Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace antipattern translation example in lua_api.md #14482

Merged
merged 2 commits into from
Mar 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 20 additions & 14 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4086,25 +4086,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