2

I have an Angularjs app and it uses a Angularjs Translation provider which has the following configuration -

app.config(['$translateProvider', function($translateProvider){
    // Register a loader for the static files
    // So, the module will search missing translation tables under the specified urls.
    // Those urls are [prefix][langKey][suffix].
    $translateProvider.useStaticFilesLoader({
      prefix: '/src/l10n/',
      suffix: '.js'
    });
    // Tell the module what language to use by default
    $translateProvider.preferredLanguage('en');
    // Tell the module to store the language in the local storage
    $translateProvider.useLocalStorage();
  }]);

Now i have files like en.js inside directory src/l10n which has the following sample content -

{

"header" : {
  "navbar" : {
    "UPLOAD" : "Upload",
    "new" : {
      "NEW" : "New",
      "PROJECT" : "Projects",
      "TASK" : "Task",
      "USER" : "User",
      "EMAIL" : "Email"
    },
    "NOTIFICATIONS" : "Notifications"
  }
}

and I am using this in HTML as -

<div translate="header.navbar.UPLOAD"> </div>

Which puts the content inside the div according to the language selected so basically I want to understand how to create such a translation file like en.js which can translate and display hindi on screen

Since, I only have to create a translation file and don't need to translate english to hindi in realtime, I don't think the results/libraries I found on internet that convert english to hindi using google apis or other are suitable for my use case.

So, is it possible to display the text in hindi on my browser using a translation file that I could create. If yes then how can I do it ?

Harshit Laddha
  • 2,044
  • 8
  • 34
  • 64

1 Answers1

2

You can create a file named hi.js in your src/l10n folder, containing the structure exactly similar to en.js, but with your Hindi translations.

To switch languages on runtime, use

$translateProvider.use('hi');

kensplanet
  • 493
  • 8
  • 15
  • But how to put the content in Hindi in hi.js that's my question – Harshit Laddha Oct 25 '15 at 14:40
  • Why are you not able to put the contents in hi.js. Are you trying to indicate there is a content encoding issue due to Hindi characters. Ideally, you should add your translations in a JSON file, not a JS file. Your files should be named en.json, fr.json, hi.json, etc. – kensplanet Oct 26 '15 at 00:21
  • Okay, so for translating to hindi I should add the unicode values of hindi characters in my hi.js or hi.json file ? am I understanding this correctly – Harshit Laddha Oct 26 '15 at 05:08
  • Yes. I have successfully worked with Chinese and Japanese characters. – kensplanet Oct 26 '15 at 05:10