admin管理员组文章数量:1356588
In my app i'm using angular-translate
for translating my content.
And also in my view i have such date formatter:
{{article.CreatedAt | date:'dd MMM yyyy':'UTC'}}
but when i set polish, russian (or any other language, non-english) - my month names are still in english.
How can i translate them (will be great, if this is doneable without momentum and other plugins...)?
In my app i'm using angular-translate
https://github./angular-translate/angular-translate
for translating my content.
And also in my view i have such date formatter:
{{article.CreatedAt | date:'dd MMM yyyy':'UTC'}}
but when i set polish, russian (or any other language, non-english) - my month names are still in english.
How can i translate them (will be great, if this is doneable without momentum and other plugins...)?
Share Improve this question asked Dec 22, 2015 at 21:23 byCoderbyCoder 9,18427 gold badges120 silver badges259 bronze badges 12- try out this plunkr from a similar post plnkr.co/edit/AFpj79M1C6vOewSWLX8J – Jared Commented Dec 22, 2015 at 21:33
-
@Jared
will be great, if this is doneable without momentum and other plugins
. second: i haven't any ui calendar... – byCoder Commented Dec 22, 2015 at 21:36 - They are using i18n and ngLocale, I dont think you need momentum. Look at the ng-fr-ca.js file. – Jared Commented Dec 22, 2015 at 21:38
- 1 Have you loaded the locale for the languages that you are using? These contain the translations that you are seeking. github./angular/angular.js/tree/master/src/ngLocale – Jared Commented Dec 23, 2015 at 15:55
- 3 FWIW angular-translate does NOT translate any date or time settings, you must use ngLocale or angular-dynamic-locale to do that. In your case you MUST use the latter, angular-dynamic-locale, to achieve your goal. To my knowledge, there is no other way. Link: github./lgalfaso/angular-dynamic-locale – Jared Commented Dec 23, 2015 at 17:56
2 Answers
Reset to default 6 +25For changing application locale dynamically you need angular-dynamic-locale and you also need other locale files (english is ing with angular) from ngLocale.
Here is working plunker.
You need to catch translate events as we want to change locale when language is changed. So for this purpose I used $translateChangeSuccess
event to set selected language as new locale.
$rootScope.$on('$translateChangeSuccess', function (event, data) {
tmhDynamicLocale.set(data.language);
});
Here is the list of all $translate events.
You don't need an external library, in angular, date and number format are translated using angular-i18n: https://docs.angularjs/guide/i18n
For example, to get date in russian, just include the locale file after angular:
<script src="angular.js"></script>
<script src="angular-locale_ru-ru.js"></script>
Of course this will not be dynamic, you could manage it server-side, or find another trick.
to get it from bower, use
$ bower install angular-i18n
see Where are the AngularJS I18n files?
本文标签: javascriptAngulartranslate and date formatter how to translate month nameStack Overflow
版权声明:本文标题:javascript - Angular-translate and date formatter: how to translate month name? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744066918a2585170.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论