A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cran.r-project.org/web/packages/fda.usc/../rmarkdown/../potools/vignettes/developers.html below:

Translation for package developers

The mechanics of translating your package are quite straightforward. The bigger challenge is writing messages that are easy to translate. In part, this is an extension of writing messages that are easy to understand in English as well! And if it’s hard for a native English speaker to understand your message, it’s going to be even harder once it’s translated into another language. The following sections give some advice about how to write good messages, as inspired by the “Preparing translatable strings” section of the gettext2 manual.

Write full sentences

Generally, you should strive to make sure that each message comes from a single string (i.e. lives within a single "“). Take this simple greeting where I translate”good" and “morning” individually:

This will pose two challenges for translators:

Instead it’s better to generate the complete message in a single string using glue() or sprintf() 3 to interpolate in the parts that vary:

Then the translator sees something like this:

msgid "Good morning {name}!"
msgstr ""

This gives the translator enough context to create a good translation and the freedom to change word order to make a grammatically correct sentence in their language. We can make the problem more challenging by making our greeting more flexible:

This would generate the following sequence of translations for French:

msgid "Good"
msgstr "Bon"

msgid "morning"
msgstr "matin"

msgid "afternoon"
msgstr "après midi"

msgid "evening"
msgstr "soirée"

Unfortunately this breakdown won’t generate correct French. The three greetings should be “Bonjour” for morning and afternoon, and “Bonsoir” for evening. There are two problems: good morning and good afternoon both use bonjour (even though French has different words for morning and afternoon; bon après-midi is used as a farewell), and the two word English phrases turn into single French words.

If you were translating to Mongolian you’d face a different problem. While Mongolian uses the same times of day, it arranges the words in the opposite order to English: “Өглөөний мэнд” is morning greetings, “Өдрийн мэнд” is afternoon greetings, and “Оройн мэнд” is evening greetings.

Again, we need to resolve this problem by moving away from translating fragments and towards translating complete sentences. One way to do that here would be to restrict ourselves to a fixed set of time points and use switch() to specify the greeting:

This works for French (and Mongolian):

msgstr: "Good morning {name}!"
msgid: "Bonjour {name}!"

msgstr: "Good afternoon {name}!"
msgid: "Bonjour {name}!"

msgstr: "Good evening {name}!"
msgid: "Bonsoir {name}!"

However, it’s still not a fully general solution as it assumes that the time of day is the most important characteristic of a greeting, and that the day is broken down into at most three components. Neither is true in general:

Greetings are particularly challenging to translate because of their great cultural variation; fortunately most messages in R packages won’t require such nuance.

sprintf() vs glue()

In R, there are two common ways to interpolate variables into a string: sprintf() and glue(). There are pros and cons to each:

The difference may be more important than you realize – as mentioned above, some languages (e.g., Turkish, Korean, and Japanese) assemble phrases into sentences in a different order. “I have 7 apples” becomes “7りんごをもっています” in Japanese, i.e. “7 apples [I’m] holding” – the verb & subject switched places. The reordering of templates in your messages is going to be quite common if you want your messages available in more than a very limited set of languages.

Un-translatable content

You can use interpolation to avoid including un-translatable components like URLs or email addresses into a message. This is good practice because it saves work for the translators, makes it easier for them to see changes to the text, and avoids the chance of a translator accidentally introducing a typo. It works something like this:

Similarly, if you’re generating strings that include in HTML, avoid including the HTML in the translated string, and instead translate just the words:

Generally, you want to help the translator spend as much time as possible helping you out.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4