Translating text in CEGUI windows into multiple languages

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Ident
CEGUI Team
Posts: 1836
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Translating text in CEGUI windows into multiple languages

Postby Ident » Wed Sep 30, 2015 19:19

"fabi" on #cegui at freenode IRC asked how to translate text in GUI dialogs to other languages.

As far as I understand it, the requested feature is multi-language support in CEGUI. Imo the best way to achieve this is to have the database with your translated strings ready and store some sort of placeholder code-word (let's call it "Text-Identifier")for each window that should contain text. The specific property can be added as user property to the list of properties in the window's PropertyList. Add the step of adding the property to all windows that need it, there is multiple ways to achieve this for example manually (if you create all windows by code) or automatically by adapting the window factory or similar. Look at WindowFactory.h to see what you need to replace. It should be pretty obvious what to insert and where and also should be easy to replace this with what you want, you may wanna do it in CEGUi directly.

After creating the property, the property value can be changed. Set all of the window's "Text-Identifier" properties to the correct value, you may wanna initialise them to the value of the "Text" property in case you are loading "layout" files. Again, the factory might come in handy here and do this for you right away so this is where I would add this step. Finally, I would also add an event handler on creation. The handler should listen to a new event you create that you may call whatever you want, for example "Text-Identifier" changed. You will have to fire the events yourself. The event handler has to look up the string from your container of translated-strings for the language you currently want and set it as text for the window. So it should be a WindowEvent that is passed to the handler which contains a pointer to the window. Again, easy to do, and should be fired at the end of the WindowFactory code that creates windows. Now everytime you change the language of your program, you should recursively fire the event. You may wanna add a function of this to Window, so the WindowEvent is created properly recursively for all windows. You will only have to fire this for all root windows.

Now this is a lot of steps but it shows one way to solve this elegantly and pretty much failproof. I might have missed something but I think this pretty much sums up the basic idea.

I have provided no code chunks, if anyone does so we can make a wiki article out of it, i can provide feedback.
CrazyEddie: "I don't like GUIs"

Return to “Help”

Who is online

Users browsing this forum: No registered users and 1 guest