mirror of
https://github.com/Haui1112/minetest.git
synced 2024-10-23 01:31:50 +02:00
Replace antipattern translation example in lua_api.md (#14482)
This commit is contained in:
parent
20bfaba0b7
commit
a7908da968
|
@ -4104,25 +4104,31 @@ Two functions are provided to translate strings: `minetest.translate` and
|
||||||
avoid clashes with other mods.
|
avoid clashes with other mods.
|
||||||
This function must be given a number of arguments equal to the number of
|
This function must be given a number of arguments equal to the number of
|
||||||
arguments the translated string expects.
|
arguments the translated string expects.
|
||||||
Arguments are literal strings -- they will not be translated, so if you want
|
Arguments are literal strings -- they will not be translated.
|
||||||
them to be, they need to come as outputs of `minetest.translate` as well.
|
|
||||||
|
|
||||||
For instance, suppose we want to translate "@1 Wool" with "@1" being replaced
|
For instance, suppose we want to greet players when they join. We can do the
|
||||||
by the translation of "Red". We can do the following:
|
following:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local S = minetest.get_translator()
|
local S = minetest.get_translator("hello")
|
||||||
S("@1 Wool", S("Red"))
|
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)
|
||||||
```
|
```
|
||||||
|
|
||||||
This will be displayed as "Red Wool" on old clients and on clients that do
|
When someone called "CoolGuy" joins the game with an old client or a client
|
||||||
not have localization enabled. However, if we have for instance a translation
|
that does not have localization enabled, they will see `Hello CoolGuy, how are
|
||||||
file named `wool.fr.tr` containing the following:
|
you today?`
|
||||||
|
|
||||||
@1 Wool=Laine @1
|
However, if we have for instance a translation file named `hello.de.tr`
|
||||||
Red=Rouge
|
containing the following:
|
||||||
|
|
||||||
this will be displayed as "Laine Rouge" on clients with a French locale.
|
# textdomain: hello
|
||||||
|
Hello @1, how are you today?=Hallo @1, wie geht es dir heute?
|
||||||
|
|
||||||
|
and CoolGuy has set a German locale, they will see `Hallo CoolGuy, wie geht es
|
||||||
|
dir heute?`
|
||||||
|
|
||||||
Operations on translated strings
|
Operations on translated strings
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
Loading…
Reference in a new issue