Ali Gajani
Ali Gajani

Reputation: 15091

How do I gracefully load a specific localization file dynamically in AngularJS?

Currently, I have a system which has language codes such as en, de, jp and so on. I need to provide localisation for 8 languages, so it works if I manually add in the script file here:

<script src='/js/locale/angular-locale_de.js'></script>.

But I need to be able to load it dynamically in the header. I tried using a jQuery hack using ("head").append() but on Chrome throws an error says ASYNC request deprecated.

Upvotes: 3

Views: 1361

Answers (2)

Muhammad Hasan
Muhammad Hasan

Reputation: 92

You don't have to invent the wheel, there's a module -angular dynamic localization- for that and it's pretty straight forward: https://github.com/lgalfaso/angular-dynamic-locale

and if you are looking for translation, there u go http://angular-translate.github.io/

Upvotes: 1

edhedges
edhedges

Reputation: 2718

You could use http://api.jquery.com/jQuery.getScript/ if you're already using jQuery.

Upvotes: 0

Related Questions