Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

Internationalization and translation files

To internationalize your application, you need to provide versions of string literals in all required languages. In U++, you can do this using translation files.

 

To mark string literals for translation in sources, you have to tag them with t_ macro, like

 

printf(t_("Hello world!"));

 

This macro is expanded to function that provides translation of English (more specifically en-US) text to default language set by SetLanguage function. String literal here is considered to be the key for translation lookup. U++ supports three forms of keys here:

 

plain keys are just en-US texts. Example: t_("Hello world!")

context keys consist of context and en-US text separated by \v, where both are parts of key. Example: t_("align\vTop"). This is useful in cases when context is needed to provide translation.

id keys consist of id and en-US text separated by \a, but only id is used as key in translation lookup. Example: t_("CtrlCoreReport\aReport").

 

Important: t_ tag can be used with string literals only.

 

t_ macro expands to function call that provides translation of given literal. Where this is not acceptable (like in arrays of literals), tt_ tag can be used - it is expanded to literal alone and that can be later converted using GetLngString macro.

 

Translations are stored in .t files of regular packages. Format of this file is rather simple - it is set of keys followed by translation of keys to required languages. Key is introduced by T_, translation, translations are introduced by their language codes, e.g.

 

T_("Sideways")

csCZ("Na šířku")

 

Language codes for other languages may be found in Core, within the lcid.txt file (found in the Languages section).

 

TheIDE provides means for manipulating .t files - in Workspace menu there is "Synchronize translation files" operation. This operation scans all source files of current project and builds map of t_ tagged string literals and then combines this information with any valid .t files it finds. This operation also allows adding new languages to .t files.

 

t. files are always in UTF8 encoding.  To change the encoding for your file, you can right-click on the file in TheIDE, and select 'Convert to encoding...'.  Note that if you use Windows Notepad to save the file as UTF-8, you may need to strip out the BOM that Windows may have included, or you may experience compiling errors.

 

TheIDE also maintains translation repository - it stores ALL translations that it meets into this file. Each time .t file is synchronized, TheIDE tries to supply all missing translations from repository and also adds all translation existing in .t file back to repository. This is e.g. great when some source is moved to another package.

 

U++ also supports run-time translations (as opposite to compile-time .t files). You can use --export-tr in any U++ application to force creation of runtime translation file (with .tr extension). Parameters of this flag is 4 letter language code and single letter character set encoding according this table:

 

 

_

utf-8

0

windows-1250

1

windows-1251

2

windows-1252

3

windows-1253

4

windows-1254

5

windows-1255

6

windows-1256

7

windows-1257

A

iso-8859-1

B

iso-8859-2

C

iso-8859-3

D

iso-8859-4

E

iso-8859-5

F

iso-8859-6

G

iso-8859-7

H

iso-8859-8

I

iso-8859-9

J

iso-8859-10

 

example:

 

myapp --export-tr dede2

 

will create dede2.tr file (in exe directory on Win32 and user's home folder on Posix) ready for translation to deDE in windows-1252. If translations are already present, they are supplied, otherwise .tr file contains English strings in place of translations.

 

It is also possible to output secondary already translated language to .tr file as comments (e.g. in case that translator cannot understand English, but can understand some other language):

 

 

myapp --export-tr dede2 cscz

 

Each U++ application performs search for .tr files at startup and uses them to extend internal translation tables.

 

.tr files can be also imported to .t files using TheIDE's "Import runtime translation" function of Workspace menu. Note that this function does not add new languages to .t files - just adds translations to languages added manually.

 

When --export-tr is used without parameter, it exports all compile-time languages. This is useful for maintenance purposes.

 

You will need to include the following in one of your compiled files (not a header):

 

#define TFILE <YourProject/YourTranslations.t>

#include <Core/t.h>

 

where 'YourProject/YourTranslations.t' would be a path to your translations file.

 

To set your application's language to the user's default language, add the following somewhere early in your application's execution:

 

SetLanguage( GetSystemLNG() );

 

In multithreaded applications this setting works on per-thread basis (since release 5061); threads inherit the language setting of main thread on startup.

Last edit by koldo on 12/28/2012. Do you want to contribute?. T++