@@ -75,7 +75,8 @@ message("This", " is", " a", " message")
7575warning(" This" , " is" , " a" , " warning" )
7676# > Warning: This is a warning
7777stop(" This" , " is" , " an" , " error" )
78- # > Error: This is an error
78+ # > Error:
79+ # > ! This is an error
7980```
8081
8182However, as you’ll learn shortly, this style is unlikely to generate
@@ -148,6 +149,50 @@ translatable
148149strings] ( https://www.gnu.org/software/gettext/manual/html_node/Preparing-Strings.html#Preparing-Strings%20(Inspired%20by%20from%20) ) ”
149150section of the gettext[ ²] ( #fn2 ) manual.
150151
152+ One important point is to avoid templating out sentence fragments,
153+ especially words. Put message pieces into a template if and only if they
154+ are untranslatable (e.g., proper nouns, function names/R code).
155+
156+ For example, it is bad practice to conditionally template a word or
157+ phrase into a message:
158+
159+ ``` r
160+ # BAD
161+ in_parallel <- TRUE
162+ run_type <- if (in_parallel ) " in parallel" else " sequentially"
163+ sprintf(tr_(" Running job %s." ), run_type )
164+ # > [1] "Running job in parallel."
165+ ```
166+
167+ The translator only sees ` "Running job %s." ` , and cannot adapt the
168+ translation for the two cases. It’s much better to use two different,
169+ complete messages:
170+
171+ ``` r
172+ # GOOD
173+ in_parallel <- TRUE
174+ if (in_parallel ) {
175+ tr_(" Running job in parallel." )
176+ } else {
177+ tr_(" Running job sequentially." )
178+ }
179+ # > [1] "Running job in parallel."
180+ ```
181+
182+ This gives the translator full context. Why is this important? Because
183+ different words can require entirely different sentence structures in
184+ other languages. For example, in Polish, “to run \[ a job\] sequentially”
185+ can be expressed with a specific verb, ` szeregować ` . A natural
186+ translation of “Running job sequentially.” might be “Szeregowanie
187+ zadania.”. For “Running job in parallel.”, one would likely use a
188+ different verb and structure, like “Uruchamianie zadania równolegle.”.
189+
190+ The template in the “BAD” example is too rigid. It forces the translator
191+ to find a single translation for “Running job %s.” that works with both
192+ “sequentially” and “in parallel”, which is unnatural and may not even be
193+ possible. The “GOOD” example, by providing two distinct sentences,
194+ allows the translator to pick the most idiomatic phrasing for each case.
195+
151196### Write full sentences
152197
153198Generally, you should strive to make sure that each message comes from a
0 commit comments