Problem with Angular translation and nya-bs-select

60 views
Skip to first unread message

Florian Scheffer

unread,
Apr 25, 2017, 6:31:47 AM4/25/17
to Angular and AngularJS discussion
Hello dudes,

I'm new to Angular and normally a php developer. So dont hate me :).

I've a problem.
  • Created a Language dropdown switcher with nya-bs-select and tried to translate the text of that Dropdown. But it fails :/

Thats my template (index.php)

<ol class="nya-bs-select" ng-model="selectedlanguage">
   
<li data-value="de_DE" class="nya-bs-option">
       
<a ng-click="setLang('de_DE')">
           
<span><span class="flag-icon flag-icon-de"></span> {{ 'load.partial.root.german' | translate }}</span>
       
</a>
   
</li>
   
<li data-value="en_US" class="nya-bs-option">
       
<a ng-click="setLang('en_US')">
           
<span><span class="flag-icon flag-icon-gb"></span> {{ 'load.partial.root.english' | translate }}</span>
       
</a>
   
</li>
</ol>

I'm loading the translations over partials


$translateProvider.useLoader('$translatePartialLoader', {
   
urlTemplate: 'l10n/partial/{lang}.json'
});

// Tell the module what language to use by default
$translateProvider.preferredLanguage('de_DE');
// Tell the module to store the language in the cookies
$translateProvider.useCookieStorage();
$translatePartialLoaderProvider
.addPart('root');
// Enable escaping of HTML
$translateProvider.useSanitizeValueStrategy('escape');


And my controller tells

$scope.selectedlanguage = $translate.proposedLanguage();

$scope
.setLang = function(langKey) {
    $translate
.use(langKey);
};

And now you see my Problem:

Any idea?


Thank you


Sander Elias

unread,
Apr 26, 2017, 6:26:33 AM4/26/17
to Angular and AngularJS discussion
Hi Florian,

Pull the texts into your controller, and iterate over an array of the options. That way the ui will only be filled after the translations are done.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages