Get current language with angular-translate
Is there a way to get the current used language in a controller (without $translateProvider
)?
Couldn't find anything in the $translate
service.
$translate.use()
is a getter and setter.
See this demo found in links of docs:
http://jsfiddle.net/PascalPrecht/eUGWJ/7/
$translate.use()
is the way to go. Also, when an asynchronous loader is executed, you might wanna use $translate.proposedLanguage()
which returns the language key of the language that is currently loaded but not finished loaded yet.
When using angular-translate-loader-static-files I have noticed that $translate.proposedLanguage()
returned undefined
when using the default language while $translate.use()
always returned the proposed language.
Therefore I fixed it by using:
var currentLang = $translate.proposedLanguage() || $translate.use();
$translate.use()
seems not to work on initial load of the app, to get last selected language from storage: $translate.storage().get( $translate.storageKey() )
or just
$translate.proposedLanguage();