Is there a way to get the current used language in a controller (without $translateProvider
)?
Couldn't find anything in the $translate
service.
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()
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();
I think this is the better way to determine the language -
Maybe is not related but could be useful. In angular2+ the way to access to the current language is
$translate.use()
is a getter and setter.See this demo found in links of docs:
http://jsfiddle.net/PascalPrecht/eUGWJ/7/
When using angular-translate-loader-static-files I have noticed that
$translate.proposedLanguage()
returnedundefined
when using the default language while$translate.use()
always returned the proposed language.Therefore I fixed it by using:
The
$translate
service has a method calledpreferredLanguage()
that return what you want. The return of this function is the string of the language, like 'en'.Here i wrote you an example: