3

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.

5
  • Why do you need to do this dynamically? According to angular's documentation, you can just have all of them in the app at the same time and it should work. Commented Apr 29, 2015 at 15:22
  • How would that happen? I need to tell the app to load the appropriate script with the specific language code. Commented Apr 29, 2015 at 15:24
  • Sorry, I misread their doc. You are right that you can only have one loaded at once. This might interest you though: sbouchard.github.io/angular-dynamic-i18n/#!/usage Commented Apr 29, 2015 at 15:25
  • See stackoverflow.com/a/29348559/1257504 Commented Apr 29, 2015 at 15:31
  • If you have different code for different languages, perhaps you should be using a dictionary that provides the translations by key/getter, and provide that as an Angular service? Commented Jun 26, 2016 at 11:49

2 Answers 2

1

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/

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Will that load it in the head, don't think so?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.