3,146
edits
Changes
From Gramps
no edit summary
_(George Smith and Annie Jones have %(num)d child, George Smith and Annie Jones have %(num)d children, n) % {num : n}
In other cases, it's necessary to provide a hint to translators, <abbr title="exempli gratia - Latin phrase meaning 'for example'">e.g.</abbr>,
_(Remaining names | rest)
====For portable string handling on all platforms and for all locales====
* Localized strings returned from gettext, ngettext, <abbr title="et cetera - Latin phrase meaning 'and so on'">etc. </abbr> are always unicode
* Text files should always be encoded in UTF8. The easy and portable way to do this is to:
*: <pre>import io</pre>
translatable strings and for retrieving the translated values are the same as for internal modules.
See [[Addons_DevelopmentAddons_development#Localization|Addons development]] for more details.
==How it works==
* [[Translation_environment20|2.0.x]]
* [[Translation_environment22|2.2.x to Gramps 3.4.x]]
* [[Translation_environment4|Gramps 4.0.x to master (trunk)5.1.x]]
There are two stages to getting a translation to work.
==Tips for writing a translatable Python module==
===Use complete sentences===
Don't build up a sentence from phrases. Because a sentence is ordered in a particular way in your language does not mean that it is ordered the same way in another. Providing the entire sentence as a single unit allows the translator to make a meaningful translation. Do not concatenate phrases or terms as they will then show up as separate phrases or terms to be translated and the complete sentence may then show up incorrectly, especially in right-to-left languages (Arabic, Hebrew, <abbr title="et cetera - Latin phrase meaning 'and so on'">etc.</abbr>).===Use named %s/%d parameter values===Python provides a powerful mechanism that allows the reordering of %s parameter values in a string. A This has two advantages:# it allows the translator may need an option to rearrange the structure of a sentenceto fit more naturally into the language structure.# it can provide the translator more detail about what the variable refers to. There are two main options allowing you to name the variable being replaced.* The older style applies [https://docs.python.org/3.11/library/stdtypes.html#printf-style-string-formatting the '%' operator]* Python3 introduced a new style with the [https://docs.python.org/3.11/library/stdtypes.html#str.format| string formatting method] Either technique can be used with Gramps for translations, although the ''str.format()'' method is preferred for new code.Whichever you choose, and it may not match is important to ''use named arguments'' when there is more than one %s/%d value into a translation string. Also remember, some languages are using right-to-left text direction. Most examples on this page use the order you choseolder style - this includes use of the ''print'' statement, which must be replaced by the ''print()'' function in python3. For ==== Using '%' style formatting ====A simple example:
print "%s was born in %s" % ('Joe','Toronto')
city = 'Toronto', male_name = 'Joe')
===Provide separate strings for masculine and feminine.===
===Provide support for plural forms.===
Plurals are handled differently in various languages. Whilst English or German have a singular and a plural form, other languages like Turkish don't distinguish between plural or singular and there are languages which use different plurals for different numbers, <abbr title="exempli gratia - Latin phrase meaning 'for example'">e.g. </abbr>, Polish.
Gramps provides a [[Translating_Gramps#Plural_forms|plural forms]] support, useful for locales with multiples plurals according to a number (''often slavic based languages'') or for Asian family languages (''singular = plural'').
===Object classes===
Gramps often displays names of primary objects (''Person, Family, Event, <abbr title="et cetera - Latin phrase meaning 'and so on'">etc .</abbr> ...''), for being consistent on displayed strings (also in english!), there is a ''trans_objclass(objclass_str)'' function on TransUtils module.
So, when we need to display the primary object name in lower case into a sentence, we can use this function.
will display:
See ''the person'' details # or See ''the family, the event, <abbr title="et cetera - Latin phrase meaning 'and so on'">etc.</abbr> ...'' details
Make ''the person'' active
Instead of "free form" text that talks about
<abbr title="exempli gratia - Latin phrase meaning 'for example'">e.g. </abbr>,
son '''of %s'''
better would be for example some tabulated format like this:
* GtkBuilder (editors, configuration dialogs) can provide a default colon after the string without spacing,
so need some extra-testing and customization for some translators. <abbr title="exempli gratia - Latin phrase meaning 'for example'">e.g.</abbr>, in french
<pre>
print(_(a))
</pre>
This works because the dummy definition of _() simply returns the string unchanged. And this dummy definition will temporarily override any definition of _() in the built-in builtin namespace (until the del command). Take care, though if you have a previous definition of _() in the local namespace.
Note that the second use of _() will not identify “a” as being translatable to the gettext program, because the parameter is not a string literal.
self.__get_date(event.get_date_object())
self.__get_type(event.get_type())
==See also==
* [[Coding_for_translation|Coding for Translation]]
* [[Coding_for_translation_using_weblate|Coding for Translation using Weblate]]
* [[Translating_Gramps_using_Weblate|Translating Gramps using Weblate]]
* [https://www.gramps-project.org/docs/gen/gen_utils.html#gramps.gen.utils.grampslocale.Lexeme Lexeme] class in the General Utilities documentation
* [[Date_Handler#Localizing_the_date_strings|Localizing the date strings]]
* [[Translating_the_Gramps_User_manual|Translating the Gramps User manual]]
* [[Portal:Translators|Portal:Translators]]
* [[Committing_policies|Committing policies]]
* [[What_to_do_for_a_release|What to do for a release]]
[[Category:Translators/Categories]]
[[Category:Developers/Tutorials]]
[[Category:Developers/General]]