我正在尝试使用包中包含的语言文件翻译 FullCalendar。为了使 Angular 变得更简单,我使用插件 ui-calendar。
为此,我导入了语言脚本,如 doc 中所述。 :
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
... //other includes generated by bower
<script src="bower_components/moment/moment.js"></script>
<script src="bower_components/fullcalendar/dist/fullcalendar.js"></script>
<script src="bower_components/jquery-ui/ui/jquery-ui.js"></script>
<script src="bower_components/angular-ui-calendar/src/calendar.js"></script>
<!-- endbower -->
<!-- endbuild -->
<!-- FullCalendar language pack -->
<script src="bower_components/fullcalendar/dist/lang/fr-ca.js"></script>
但是,月份和日期并未被翻译。我确实设法使用 "monthNames" 手动翻译标签、“dayNames”等配置,但在我看来,这很丑陋,而且它不会翻译 ui.bootstrap.datepicker。
据我了解,问题是 momentjs 不会接受我给他的任何东西。我尝试做一个 'moment.lang('fr-ca')' 但它没有做太多。有人知道可以帮助解决此问题的“米老鼠技巧”吗?
Note: ui-calendar uses the v 1.6 of fullcalendar which doesn't include the languages utilities. So I added [email protected] to my bower.json. Everything seams to be working properly, I don't see where this could mess up the language since I'm calling fullcalendar directly.
最佳答案
这是一个工作plunkr:http://plnkr.co/edit/AFpj79M1C6vOewSWLX8J
您还需要本地化 Angular ,您可以在此处阅读文档:https://docs.angularjs.org/guide/i18n
为了使其工作,我在 plunkr 文件 ng-fr-ca.js
中添加了 i18n/angular-locale_fr-ca.js
代码。
查看 ui-calendar 的源代码(第 179 行),您会看到它使用 Angular $locale
服务来翻译天、月等。我添加了一个 console.log
到源代码,这样你就可以看到之间的区别
var dtf = $locale.DATETIME_FORMATS;
console.log(dtf);
$locale
默认使用英语。如果您加载 i18n
语言环境文件之一,您将对其进行翻译。
关于angularjs - 月份和日期尚未翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25514124/