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.

Khalid
  • 4,730
  • 5
  • 27
  • 50
Ali Gajani
  • 14,762
  • 12
  • 59
  • 100
  • 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. – Etienne Maheu Apr 29 '15 at 15:22
  • How would that happen? I need to tell the app to load the appropriate script with the specific language code. – Ali Gajani Apr 29 '15 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: http://sbouchard.github.io/angular-dynamic-i18n/#!/usage – Etienne Maheu Apr 29 '15 at 15:25
  • See http://stackoverflow.com/a/29348559/1257504 – Tony Barnes Apr 29 '15 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? – Lee Goddard Jun 26 '16 at 11:49

2 Answers2

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/

0

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

edhedges
  • 2,722
  • 2
  • 28
  • 61