Skip to content

Commit

Permalink
Replace antipattern translation example in lua_api.md (#14482)
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Mar 24, 2024
1 parent 20bfaba commit a7908da
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions doc/lua_api.md
Expand Up @@ -4104,25 +4104,31 @@ Two functions are provided to translate strings: `minetest.translate` and
avoid clashes with other mods.
This function must be given a number of arguments equal to the number of
arguments the translated string expects.
Arguments are literal strings -- they will not be translated, so if you want
them to be, they need to come as outputs of `minetest.translate` as well.
Arguments are literal strings -- they will not be translated.

For instance, suppose we want to translate "@1 Wool" with "@1" being replaced
by the translation of "Red". We can do the following:
For instance, suppose we want to greet players when they join. We can do the
following:

```lua
local S = minetest.get_translator()
S("@1 Wool", S("Red"))
```
```lua
local S = minetest.get_translator("hello")
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
minetest.chat_send_player(name, S("Hello @1, how are you today?", name))
end)
```

When someone called "CoolGuy" joins the game with an old client or a client
that does not have localization enabled, they will see `Hello CoolGuy, how are
you today?`

This will be displayed as "Red Wool" on old clients and on clients that do
not have localization enabled. However, if we have for instance a translation
file named `wool.fr.tr` containing the following:
However, if we have for instance a translation file named `hello.de.tr`
containing the following:

@1 Wool=Laine @1
Red=Rouge
# textdomain: hello
Hello @1, how are you today?=Hallo @1, wie geht es dir heute?

this will be displayed as "Laine Rouge" on clients with a French locale.
and CoolGuy has set a German locale, they will see `Hallo CoolGuy, wie geht es
dir heute?`

Operations on translated strings
--------------------------------
Expand Down

0 comments on commit a7908da

Please sign in to comment.