Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Update Languages registered in angular-translate #1842

Open
noelyriosquantion opened this issue Apr 17, 2018 · 2 comments
Open

Update Languages registered in angular-translate #1842

noelyriosquantion opened this issue Apr 17, 2018 · 2 comments

Comments

@noelyriosquantion
Copy link

I am using the angular-translate and in the configuration of my application I have the following:

`corporativas.config(['$translateProvider',
function ($translateProvider) {
//TRANSLATION SYSTEM
$translateProvider.useStaticFilesLoader({
prefix: 'locales/locale-',
suffix: '.json'
});

$translateProvider.registerAvailableLanguageKeys(['en', 'es']);
$translateProvider.preferredLanguage('en'); //manual decision of translation provider
$translateProvider.fallbackLanguage('en');
$translateProvider.useSanitizeValueStrategy('sanitize');
$translateProvider.useCookieStorage(); //use cookie storage to save the language of the user, updated everytime it changes

}]);`

But the languages that are defined in the function registerAvailableLanguageKeys () are static, but for my application these values must be obtained from the database.

I understand that in the angle config I can not make asynchronous calls because the angular life cycle executes the config first and may not return anything at run time.

So I was wondering if anyone knows how to update the values of the registerAvailableLanguageKeys () from a controller or from the run.

version:

Angularjs: 1.6.4
Angular-translate: 2.15.1

@knalli
Copy link
Member

knalli commented Apr 17, 2018

Well. Hardly. As you said already: The config is a life cycle phase which is done prior before anything else.

You can solve this issue with adding such values either within your page template processor (i.e. as HTML meta tags and re-parsing them again), a custom (blocking?) script injected with dynamic values and adding data to your DOM or with a custom AngularJS bootstrapper which loads (without AngularJS) some configurations before.

Personally, I'm fine with the first one (depends whether page modifications are possible).

@gpgpublickey
Copy link

gpgpublickey commented Jun 13, 2018

I need to do something similar, how can I inject new texts on runtime to translate new texts after the angular config phase was procesed? I don't understand the explanations of @knalli

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants