Skip to content

Commit e51b0e8

Browse files
Exemplify fragmented sentences (#332)
1 parent 4f3ce50 commit e51b0e8

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

vignettes/developers.Rmd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,33 @@ In part, this is an extension of writing messages that are easy to understand in
117117
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.
118118
The following sections give some advice about how to write good messages, as inspired by the "[Preparing translatable strings](https://www.gnu.org/software/gettext/manual/html_node/Preparing-Strings.html#Preparing-Strings%20(Inspired%20by%20from%20))" section of the gettext[^2] manual.
119119

120+
One important point is to avoid templating out sentence fragments, especially words. Put message pieces into a template if and only if they are untranslatable (e.g., proper nouns, function names/R code).
121+
122+
For example, it is bad practice to conditionally template a word or phrase into a message:
123+
124+
```{r}
125+
# BAD
126+
in_parallel <- TRUE
127+
run_type <- if (in_parallel) "in parallel" else "sequentially"
128+
sprintf(tr_("Running job %s."), run_type)
129+
```
130+
131+
The translator only sees `"Running job %s."`, and cannot adapt the translation for the two cases. It's much better to use two different, complete messages:
132+
133+
```{r}
134+
# GOOD
135+
in_parallel <- TRUE
136+
if (in_parallel) {
137+
tr_("Running job in parallel.")
138+
} else {
139+
tr_("Running job sequentially.")
140+
}
141+
```
142+
143+
This gives the translator full context. Why is this important? Because different words can require entirely different sentence structures in other languages. For example, in Polish, "to run [a job] sequentially" can be expressed with a specific verb, `szeregować`. A natural translation of "Running job sequentially." might be "Szeregowanie zadania.". For "Running job in parallel.", one would likely use a different verb and structure, like "Uruchamianie zadania równolegle.".
144+
145+
The template in the "BAD" example is too rigid. It forces the translator to find a single translation for "Running job %s." that works with both "sequentially" and "in parallel", which is unnatural and may not even be possible. The "GOOD" example, by providing two distinct sentences, allows the translator to pick the most idiomatic phrasing for each case.
146+
120147
[^2]: gettext is the underlying library that powers R's translation system.
121148

122149
### Write full sentences

0 commit comments

Comments
 (0)