Supporting GUI Translation

From ScummVM :: Wiki
Revision as of 20:38, 23 August 2010 by Criezy (talk | contribs) (→‎Translations file format: give nice name to link.)
Jump to navigation Jump to search

This page describes what developers need to do to make some part of the ScummVM GUI translatable. Therefore it concerns in particular the porters and developers working on the GUI.

Mark translatable strings in the source code

In order to make a string translatable you have to use one of the following pseudofunctions in your code:

  • _(char *) -  Main way to mark strings. You need it in majority of cases.
  • _c(char *, char *) - Another way to mark strings. It attaches the string to a context so that we can have different translations for the same string. The second argument is the context.
  • _s(char *) - Function used to mark static string constants. For instance, when you have static arrays which need to be translated. In this case you mark these strings with _s(), and then use _() or _c() at the place where you need to perform the substitution.

<syntax type="C++"> static const char *foo = _s("Some translatable text"); StaticTextWidget *bar = new StaticTextWidget(this, "name", _(foo), _("Some other translatable text for the tooltip")); StaticTextWidget *path = new StaticTextWidget(this, "name", _("None", "path")); StaticTextWidget *soundfont = new StaticTextWidget(this, "name", _("None", "soundfont")); </syntax>

In the above example "None" can be translated differently depending if it refers to a path or a soundfont.

Update the translation template file

  1. All the files that contain translatable text should be listed in the po/POTFILES file. So if you are adding translatable text into a file, you should make sure that file is listed in POTFILES and otherwise add it to the list.
  2. You should then update the scummvm.pot template file by running "make updatepot". You need to have the gettext tool installed to run that command.

The translations are transformed into a translations.dat file (which can be done by executing "make translations-dat"), and the gettext tools are not needed for the compilation or executation of ScummVM. They are only needed to update the scummvm.pot template file and the translations when translatable strings are added, removed or modified in the source code.

Translations file format

See Translations Data File Format for a description of the format of the translations.dat file.

TO DO

  • Updating interface without restart. This will require moving much code to reflowLayout() for all dialogs and is a big piece of work.
  • Situations with strings not fitting into widgets. No code around that. Suggestions are welcome.
  • Behaviour for non-ASCII hotkeys (surrounded by tildes) is undefined and was not even tested.