In my app i'm using angular-translate
https://github.com/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...)?
For changing application locale dynamically you need angular-dynamic-locale and you also need other locale files (english is coming 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.org/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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With