Skip to content

Commit 5a6618c

Browse files
authoredAug 26, 2017
Add '@n' escape sequences and some documentation on translated strings.
1 parent fc13c00 commit 5a6618c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed
 

Diff for: ‎builtin/common/misc_helpers.lua

+2
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ function core.translate(textdomain, str, ...)
704704
end
705705
arg_index = arg_index + 1
706706
return ESCAPE_CHAR .. "F" .. arg[a] .. ESCAPE_CHAR .. "E"
707+
elseif matched == "n" then
708+
return "\n"
707709
else
708710
return matched
709711
end

Diff for: ‎doc/lua_api.txt

+10
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,15 @@ Two functions are provided to translate strings: `minetest.translate` and `minet
21992199

22002200
this will be displayed as "Laine Rouge" on clients with a French locale.
22012201

2202+
### Operations on translated strings
2203+
2204+
The output of `minetest.translate` is a string, with escape sequences adding additional information to that string
2205+
so that it can be translated on the different clients. In particular, you can't expect operations like string.length
2206+
to work on them like you would expect them to, or string.gsub to work in the expected manner. However, string
2207+
concatenation will still work as expected (note that you should only use this for things like formspecs; do not
2208+
translate sentences by breaking them into parts; arguments should be used instead), and operations such as
2209+
`minetest.colorize` which are only concatenation under the hood as well.
2210+
22022211
### Translation file format
22032212
A translation file has the suffix `.[lang].tr`, where `[lang]` is the language it corresponds to.
22042213
The file should be a text file, with the following format:
@@ -2221,6 +2230,7 @@ Strings that need to be translated can contain several escapes, preceded by `@`.
22212230
files to avoid begin confused with the `=` separating the original from the translation.
22222231
* `@\n` (where the `\n` is a literal newline) acts as a literal newline. As with `@=`, this escape is not required
22232232
in strings given to `minetest.translate`, but is in translation files.
2233+
* `@n` acts as a literal newline as well.
22242234

22252235
`minetest` namespace reference
22262236
------------------------------

Diff for: ‎src/translation.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ void Translations::loadTranslation(const std::string &data)
8080
if (i + 1 < wline.length()) {
8181
if (wline[i + 1] == L'=') {
8282
word1.put(L'=');
83+
} else if (wline[i + 1] == L'n') {
84+
word1.put(L'\n');
8385
} else {
8486
word1.put(L'@');
8587
word1.put(wline[i + 1]);
@@ -113,6 +115,8 @@ void Translations::loadTranslation(const std::string &data)
113115
if (i + 1 < wline.length()) {
114116
if (wline[i + 1] == L'=') {
115117
word2.put(L'=');
118+
} else if (wline[i + 1] == L'n') {
119+
word2.put(L'\n');
116120
} else {
117121
word2.put(L'@');
118122
word2.put(wline[i + 1]);

0 commit comments

Comments
 (0)
Please sign in to comment.