Jump to content

GUI localization


photo

Recommended Posts

Hi,

 

I want to translate the gui text to cinese, and I follow the manual and refered system.h,

I added below lines at the begin of unigine.cpp in my project:

 

--unigine.cpp

 

int init() {

engine.gui.setFont("SIMYOU.TTF");

string systemUIName = "core/unigine.ui";

string languages[] = ("English", "Russian", "Chinese");

string locales[] = ("core/locale/unigine.locale:en","core/locale/unigine.locale:ru", "chinese.xml:tr");

systemInit(SystemName, languages, locales);

 

//below are just like deflaut codes

......

}

 

I see some are translated correctly, but some are do not translate, and the button tooltip(the text appared when the mouse move on it) is not show correctly(neither english nor chinese).

 

Could anyone help me to figure out this prolem? Is there something I missed? 

thanks a lot!

Link to comment

Thanks for reply,

I only change the unigine.cpp and want to translate the text on original editor to chinese, I load "Game framework plugin", and I can change the title of main panel in game framework to chinese, and the title of setting dialog, but Others (like New Game and other) can not be changed and the tip of button is not show correctly(just a hollow box).

Link to comment

If you want to translate editor plugins, you will need to generate localization dictionaries. There are two different types of phrases:

  1. Inside *.ui files;
  2. Messages from scripts (.cpp / .h) files.

Phrases from *.ui files will be automatically exported. If you want to translate messages directly from the scripts you need to modify all the sources:

// text inside TR() will be exported into localization dictionary:
dialogMessageOk(TR("Engine"),message)

// this text will be not exported:
dialogMessageOk("Engine",message)

Game Framework plugin is not translated by default (there is no TR() functions inside the script files), so you need to modify all the sources and replace all English strings with TR("string"). After that you can export those phrases into *.locale files:

  1. In data/core/editor.cpp uncomment following line: #define EXPORT_LOCALE;
  2. Launch engine with editor and enabled game framework;
  3. You should get these lines in log file:

    Saving "editor/locale/editor.locale-new" dictionary
    Saving "editor/locale/source.locale-new" dictionary
    Saving "editor/locale/plugins.locale-new" dictionary
    Saving "editor/locale/systems.locale-new" dictionary
Phrases from *.ui files will be located in editor.locale-new file. Phrases from scrips (TR()) will be located inside plugins.locale-new. After export operation you can comment back #define EXPORT_LOCALE; string in editor.cpp.
 
Also, in editor.cpp you need to extend languages[] array inside update_language() function:
string languages[] = ( "en", "ru", "ch" );

In system.h we recommend to use following code:

string languages[] = ( "English", "Russian", "Chinese" );
string locales[] = ( "core/locale/unigine.locale:en", "core/locale/unigine.locale:ru", "core/locale/unigine.locale:ch" );

All you need to do now is to fill the locale* files with your translation, using the <ch></ch> tags. Also, UTF8 encoding without BOM is required for all text files. All *.locale-new files from editor/locale directory should be renamed to *.locale at the end of translation process.

 

Please, don't forget to run editor_reload command after you changed the language from system menu (https://developer.unigine.com/en/docs/1.0/start/system_menu#interface).

 

Sorry for the long post, but there is no easier way to get the translations to work correctly.

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
  • 2 weeks later...

Hi,

 

Thanks for your long patient explanation, I followed the steps but failed to see chinese on the eidtor.

 

I add the chinese translation in editor.locale-new and renamed it to editor.locale. But I even could not see the chinese option in interface tab.

So I undo the change in system.h and change the unigine.cpp as in my first post, I can see the chinese option, but had no effect when switch to chinese.(I had reboot the editor)

 

I wander that what is the relationship between core/locale/unigine.locale and editor/locale/*.locale? Why need add the translated text in editor/locale but not in unigine.locale?

And Where I can put the code "engine.gui.setFont()" in? I need localized font to shown my text.

 

Thanks!

Link to comment

I got it work with editor in unigine evluation folder, and I did not modified the system.h, in stead I change the Unigine.cpp in data folder as In my first post, bescause I found the systemInit() in unigine.cpp will overide the languages[] and locales[] in system.h.

The result was just like the situation in first post,  tip of button is not show correctly.

 

And in my project folder, the editor is not translated at all.

 

Please give some suggestion, Thanks!

Link to comment

I partial resolved the problem, I copy the "core" folder(only editor and gui folder) form evaluation folder to my custom project folder, and modified the editor.cpp, unigine.cpp, core/editor/locale/editor.locale, and change the font of font.ttf in gui folder. And the text shown in both caption and tooltip. But some text on caption of window (for example New Game) still in english(tool tip is shown in chinese correctly).

 

This is a little different from the step you described.

 

And I have some questions:

 

1) I noticed that every time I start program, the editor.cache will be refreshed, But when I delete the editor folder in core the GUI is retrived to english, so it seem that the editor.cache does not contained the scriptes and locale files I changed, so how can cache or packed  these folders, I dont want to include it in my shipped product.

 

2) I think it should have better solution for localize the UI, for example the tooltips only take effect when I replace the fone file in gui folder, if I want dynamic set font between english and chinese, I should use engine.gui.setFont() in unigine.cpp, and how to make it work with tooltip?

 

3) I see engine.gui.addDictionary used in two place, one in system.h -> set_language() and one in editor.cpp - >update_language() and use locale file in editor/locale folder and core/locale folder, what is popuse of these two locale files exactly used for?

 

Looking forward to your reply, thanks!

Link to comment
×
×
  • Create New...