我卻高興不起來使用給定的辦法,所以我想通了這一個使用angular-translate和可能性,覆蓋角-ui-自舉的模板這樣的(來源自ui-bootstrap-tpls.js
):
對於uib/template/datepicker/day.html
:
angular.module("uib/template/datepicker/day.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("uib/template/datepicker/day.html",
"<table class=\"uib-daypicker\" role=\"grid\" aria-labelledby=\"{{::uniqueId}}-title\" aria-activedescendant=\"{{activeDateId}}\">\n" +
" <thead>\n" +
" <tr>\n" +
" <th><button type=\"button\" class=\"btn btn-default btn-sm pull-left uib-left\" ng-click=\"move(-1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-left\"></i></button></th>\n" +
" <th colspan=\"{{::5 + showWeeks}}\"><button id=\"{{::uniqueId}}-title\" role=\"heading\" aria-live=\"assertive\" aria-atomic=\"true\" type=\"button\" class=\"btn btn-default btn-sm uib-title\" ng-click=\"toggleMode()\" ng-disabled=\"datepickerMode === maxMode\" tabindex=\"-1\"><strong>{{ title | uppercase | localizeMonth }}</strong></button></th>\n" +
" <th><button type=\"button\" class=\"btn btn-default btn-sm pull-right uib-right\" ng-click=\"move(1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-right\"></i></button></th>\n" +
" </tr>\n" +
" <tr>\n" +
" <th ng-if=\"showWeeks\" class=\"text-center\"></th>\n" +
" <th ng-repeat=\"label in ::labels track by $index\" class=\"text-center\"><small aria-label=\"{{::label.full}}\">{{ ('DAY_' + label.abbr | uppercase) | translate}}</small></th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" +
" <tr class=\"uib-weeks\" ng-repeat=\"row in rows track by $index\">\n" +
" <td ng-if=\"showWeeks\" class=\"text-center h6\"><em>{{ weekNumbers[$index] }}</em></td>\n" +
" <td ng-repeat=\"dt in row\" class=\"uib-day text-center\" role=\"gridcell\"\n" +
" id=\"{{::dt.uid}}\"\n" +
" ng-class=\"::dt.customClass\">\n" +
" <button type=\"button\" class=\"btn btn-default btn-sm\"\n" +
" uib-is-class=\"\n" +
" 'btn-info' for selectedDt,\n" +
" 'active' for activeDt\n" +
" on dt\"\n" +
" ng-click=\"select(dt.date)\"\n" +
" ng-disabled=\"::dt.disabled\"\n" +
" tabindex=\"-1\"><span ng-class=\"::{'text-muted': dt.secondary, 'text-info': dt.current}\">{{::dt.label}}</span></button>\n" +
" </td>\n" +
" </tr>\n" +
" </tbody>\n" +
"</table>\n" +
"");
}]);
對於uib/template/datepicker/month.html
:
angular.module("uib/template/datepicker/month.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("uib/template/datepicker/month.html",
"<table class=\"uib-monthpicker\" role=\"grid\" aria-labelledby=\"{{::uniqueId}}-title\" aria-activedescendant=\"{{activeDateId}}\">\n" +
" <thead>\n" +
" <tr>\n" +
" <th><button type=\"button\" class=\"btn btn-default btn-sm pull-left uib-left\" ng-click=\"move(-1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-left\"></i></button></th>\n" +
" <th><button id=\"{{::uniqueId}}-title\" role=\"heading\" aria-live=\"assertive\" aria-atomic=\"true\" type=\"button\" class=\"btn btn-default btn-sm uib-title\" ng-click=\"toggleMode()\" ng-disabled=\"datepickerMode === maxMode\" tabindex=\"-1\"><strong>{{title}}</strong></button></th>\n" +
" <th><button type=\"button\" class=\"btn btn-default btn-sm pull-right uib-right\" ng-click=\"move(1)\" tabindex=\"-1\"><i class=\"glyphicon glyphicon-chevron-right\"></i></button></th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" +
" <tr class=\"uib-months\" ng-repeat=\"row in rows track by $index\">\n" +
" <td ng-repeat=\"dt in row\" class=\"uib-month text-center\" role=\"gridcell\"\n" +
" id=\"{{::dt.uid}}\"\n" +
" ng-class=\"::dt.customClass\">\n" +
" <button type=\"button\" class=\"btn btn-default\"\n" +
" uib-is-class=\"\n" +
" 'btn-info' for selectedDt,\n" +
" 'active' for activeDt\n" +
" on dt\"\n" +
" ng-click=\"select(dt.date)\"\n" +
" ng-disabled=\"::dt.disabled\"\n" +
" tabindex=\"-1\"><span ng-class=\"::{'text-info': dt.current}\">{{ ('MONTH_' + dt.label | uppercase) | translate }}</span></button>\n" +
" </td>\n" +
" </tr>\n" +
" </tbody>\n" +
"</table>\n" +
"");
}]);
您還需要通過延長您的語言文件(這是德語):
, 'MONTH_JANUARY': 'Januar'
, 'MONTH_FEBRUARY': 'Februar'
, 'MONTH_MARCH': 'März'
, 'MONTH_APRIL': 'April'
, 'MONTH_MAY': 'May'
, 'MONTH_JUNE': 'June'
, 'MONTH_JULY': 'July'
, 'MONTH_AUGUST': 'August'
, 'MONTH_SEPTEMBER': 'September'
, 'MONTH_OCTOBER': 'October'
, 'MONTH_NOVEMBER': 'November'
, 'MONTH_DECEMBER': 'December'
而且,由於日期選擇器的當前月份orignally呈現爲{{title}}
provied通過scope.title = dateFilter(this.activeDate, this.formatDayTitle);
(線2216 ui-bootstrap-tpls.js
),你必須加載過濾當月本地化(感謝this post):
/* global app */
app.filter('localizeMonth', function($interpolate)
{
return function (input)
{
return input
.replace(/JANUARY/g, $interpolate('{{ \'MONTH_JANUARY\' | translate}}'))
.replace(/FEBRUARY/g, $interpolate('{{ \'MONTH_FEBRUARY\' | translate}}'))
.replace(/MARCH/g, $interpolate('{{ \'MONTH_MARCH\' | translate}}'))
.replace(/APRIL/g, $interpolate('{{ \'MONTH_APRIL\' | translate}}'))
.replace(/MAY/g, $interpolate('{{ \'MONTH_MAY\' | translate}}'))
.replace(/JUNE/g, $interpolate('{{ \'MONTH_JUNE\' | translate}}'))
.replace(/JULY/g, $interpolate('{{ \'MONTH_JULY\' | translate}}'))
.replace(/AUGUST/g, $interpolate('{{ \'MONTH_AUGUST\' | translate}}'))
.replace(/SEPTEMBER/g, $interpolate('{{ \'MONTH_SEPTEMBER\' | translate}}'))
.replace(/OCTOBER/g, $interpolate('{{ \'MONTH_OCTOBER\' | translate}}'))
.replace(/NOVEMBER/g, $interpolate('{{ \'MONTH_NOVEMBER\' | translate}}'))
.replace(/DECEMBER/g, $interpolate('{{ \'MONTH_DECEMBER\' | translate}}'))
;
};
});
我認爲這個解決方案至少與這裏發明的其他黑客一樣醜陋,但你不必自己觸發重繪或類似的事情。
[AngularJS/Angular-ui-bootstrap更改datePicker使用的語言]的可能重複(http://stackoverflow.com/questions/19671887/angularjs-angular-ui-bootstrap-changing-language-used-by- datepicker) – redben
@redben問題可能是一樣的,但導致問題形成的上下文是不同的。 – ThCC
你好。有沒有辦法在不添加特定語言腳本的情況下更改語言? –