1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-07 18:55:18 +01:00

Use codeblocks in README_mod_translation_updater.md

This commit is contained in:
Bradley Pierce
2024-01-27 10:40:21 -05:00
parent 2fc7976a07
commit 95551f9781

View File

@@ -40,10 +40,12 @@ Here is the list of all recognized function names. All functions return a string
Here is the boilerplate code you have to add at the top of your source code file: Here is the boilerplate code you have to add at the top of your source code file:
local S = minetest.get_translator("<textdomain>") ```lua
local NS = function(s) return s end local S = minetest.get_translator("<textdomain>")
local FS = function(...) return minetest.formspec_escape(S(...)) end local NS = function(s) return s end
local NFS = function(s) return minetest.formspec_escape(s) end local FS = function(...) return minetest.formspec_escape(S(...)) end
local NFS = function(s) return minetest.formspec_escape(s) end
```
Replace `<textdomain>` above and optionally delete `NS`, `FS` and/or `NFS` if you don't need Replace `<textdomain>` above and optionally delete `NS`, `FS` and/or `NFS` if you don't need
them. them.
@@ -73,28 +75,34 @@ Undetectable notations:
This minimal code example sends "Hello world!" to all players, but translated according to This minimal code example sends "Hello world!" to all players, but translated according to
each player's language: each player's language:
local S = minetest.get_translator("example") ```lua
minetest.chat_send_all(S("Hello world!")) local S = minetest.get_translator("example")
minetest.chat_send_all(S("Hello world!"))
```
### How to Use `NS` ### How to Use `NS`
The reason why `NS` exists is for cases like this: Sometimes, you want to define a list of The reason why `NS` exists is for cases like this: Sometimes, you want to define a list of
strings to they can be later output in a function. Like so: strings to they can be later output in a function. Like so:
local fruit = {"Apple", "Orange", "Pear"} ```lua
local function return_fruit(fruit_id) local fruit = {"Apple", "Orange", "Pear"}
return fruit[fruit_id] local function return_fruit(fruit_id)
end return fruit[fruit_id]
end
```
If you want to translate the fruit names when `return_fruit` is run, but have the If you want to translate the fruit names when `return_fruit` is run, but have the
*untranslated* fruit names in the `fruit` table stored, this is where `NS` will help. *untranslated* fruit names in the `fruit` table stored, this is where `NS` will help.
It will show the script the string without Minetest translating it. The script could be made It will show the script the string without Minetest translating it. The script could be made
translatable like this: translatable like this:
local fruit = {NS("Apple"), NS("Orange"), NS("Pear")} ```lua
local function return_fruit(fruit_id) local fruit = {NS("Apple"), NS("Orange"), NS("Pear")}
return S(fruit[fruit_id]) local function return_fruit(fruit_id)
end return S(fruit[fruit_id])
end
```
## How to Run the Script ## How to Run the Script