语言

Menu
Sites
Language
How to localize a gear widget?

I don't understand the help document about localizing gear widget- Where and How is LANG_JSON_DATA defined?

I have not coded javascript for a while .. the help document says

"Define a global JS object in the resource file. In the following example, the JS object is LANG_JSON_DATA. This object defines the key-value pairs for localized strings"

then make folder for each locale and create langugae.js file (JSON data) and the runtime will load the correct locale!!

 

查看选择的答案

响应

7 回复
AVSukhov

Hello,

LANG_JSON_DATA - it`s global object defined in language.js for each local (ru, en, fr,....).

When the application is launched Web Runtime determines the current local and load appropriate LANG_JSON_DATA object.

Yeah, but how to do it. Can you show me a code?

Mark as answer

problem solved. There is language.js generated automatically by the widget that does the job. I was coding my own

LOL.. I have a problem....there is no default language .. I must create folders for all?!

dammmm

Fujikawa

I found the solution.

     <script src="locales/en-us/language.js"></script>
     <script src="language.js"></script>

For this code, if "language.js" of specified language doesn't exist, "language.js" of en-us is used and works.

I defined global LANG_JSON_DATA in AppPref.js  and then if locale of the phone is not english and not supported by app - then default LANG_JSON_DATA  AppPref.js will be loaded -

 

<script type="text/javascript" src="js/AppPref.js"></script>
<script type="text/javascript" src="language.js"></script>
<script type="text/javascript" src="js/main.js"></script>

AVSukhov

Hello,

You need to create "locales" folder in your project.

In this folder create subfolders for each language (f.e. "en", "ru", "fr".......) 

In each folder create "language.js":

f.e. language.js in "en" folder:

LANG_JSON_DATA=
{
   "hello": "hello"
}

language.js in "ru" folder:

LANG_JSON_DATA=
{
   "hello": "привет"
}

 

After this load language resources to your index.html:

<script src="language.js"></script>

and use in your code, f.e.:

console.log(LANG_JSON_DATA["hello"]);

That`s all.