-1

Here i am doing the translation for 2 languages 'en' and 'de'

 app.config(['$translateProvider', function($translateProvider) {
  $translateProvider.translations('en', {
   'name': 'Hello',
   'FOO': 'This is a paragraph'
  });
 $translateProvider.translations('de', {
  'name': 'Hallo',
  'FOO': 'Dies ist ein Absatz'
  });
 $translateProvider.preferredLanguage('de');
}])

I am hardcoding the value for the key. How can we change the hello to hallo without hardcoding if we choose 'de' language?

hmims
  • 539
  • 8
  • 28
  • 1
    "Hardcoding" as opposed to what exactly? – deceze Oct 20 '15 at 08:11
  • If i have a string "hello" in browser and if i change the language to "de" , the browser should display "hallo" and i dont want to hardcode it in my code. – hmims Oct 20 '15 at 08:19
  • Uhm, yes...!? That's exactly what angular-translate does...!? You seem to be somewhat confused about the basics of how to use it, so supply more information about what you're trying exactly. – deceze Oct 20 '15 at 08:21
  • for eg: if i want "Do we have to hardcode for localization in angular-translate for every language?" to be converted to "de" language. How can i do it using anguarjs? – hmims Oct 20 '15 at 08:24
  • 1
    Are you asking whether you can just write `Hello`, and it will automagically be translated to "Hallo", without you writing a `$translateProvider.translations('de', { .. })` anywhere?! – deceze Oct 20 '15 at 08:27
  • yes.. is there any way to do this..we just specify the language and it changes it according to that language – hmims Oct 20 '15 at 08:31
  • 1
    No. You're asking for machine translation, which is a) very bad quality compared to manual translation, and b) not what angular-translate does. – deceze Oct 20 '15 at 08:34
  • No idea about Angular but some translation toolsets provide tools to scan source code and generate or update the language files and some template engines provide syntantic sugar to make the text insertion less verbose. But you always need to clearly identify translateble strings—the computer won't figure out what your text mean. – Álvaro González Oct 20 '15 at 08:45

1 Answers1

0

You can put your translations into a separate file and load it as JSON. This way your localisation is not in your code. As an example you can configure it:

$translateProvider.useStaticFilesLoader({prefix: 'l10n/', suffix: '.json'});

Which will try to load l10n/de.json for de language from your server. Just make sure to include angular-translate-loader-static-files dependency.

FVlad
  • 307
  • 5
  • 11