Difference between revisions of "Supporting GUI Translation"

Jump to navigation Jump to search
→‎Mark translatable strings in the source code: Use a bit more technical terminology to explain the various translation related macros.
(Removed the extra code fragments for _() and _s() and updated the text describing their usage)
(→‎Mark translatable strings in the source code: Use a bit more technical terminology to explain the various translation related macros.)
Line 2: Line 2:


== Mark translatable strings in the source code ==
== 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:
In order to make a string translatable you have to use one of the following macros in your code:
* ''_(char *)'' -  Main way to mark strings. It's a function, and is used for strings within code. For the majority of translatable strings, this is the function to be used.
* ''_(const char *)'' -  The simplest way to mark and substitute strings at the same time. It is not a constant operation, i.e. it returns a translated version of the string and might have side effects, thus it should not be used for static data tables. For the majority of translatable strings using ''_()'' is the suggested method. This can also be used on variables, which contain strings marked for translation, and simply subsitutes the string then.
* ''_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.
* ''_c(const char *, const char *)'' - Another way to mark and substitute 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. This is not a constant operation either, so it should not be used for static data tables either. This can also be used on variables, which contain strings marked for translation, and simply subsitutes the string then.
* ''_s(char *)'' - A wrapper used to mark static string constants, like for example 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.
* ''_s(const char *)'' - Only mark a string to be translated. This is a constant operation, i.e. it also evaluates to the unchanged string. This is mainly used for marking translatable strings in static data tables. In this case you mark these strings with ''_s()'', and then use ''_()'' or ''_c()'' at the place where you need to perform the substitution.
* ''_sc(char *, char *)'' - Another way to mark static string constants. It attaches the string to a context so that we can have different translations for the same string. The second argument is the context.
* ''_sc(const char *, const char *)'' - Another way to only mark strings for translations. It attaches the string to a context so that we can have different translations for the same string. The second argument is the context. Subsitution should be performed via ''_c()'' later.
* ''DECLARE_TRANSLATION_ADDITIONAL_CONTEXT(char *, char *)'' - Declare a string (first argument) to translate in a given context (second argument).
* ''DECLARE_TRANSLATION_ADDITIONAL_CONTEXT(const char *, const char *)'' - Declare a string (first argument) to translate in a given context (second argument). This macro does not evaluate to any value.


If you want to give some additional explanations to the translators, or your string could be understood in a different ways, it is recommended to precede it with a comment tagged I18N.
If you want to give some additional explanations to the translators, or your string could be understood in a different ways, it is recommended to precede it with a comment tagged I18N.
561

edits

Navigation menu