mirror of
https://github.com/minetest-mods/intllib.git
synced 2025-01-24 00:40:18 +01:00
Updated readme, in an attempt to make it more readable
This commit is contained in:
parent
475711f7f7
commit
e8e8a532c8
@ -1,20 +1,21 @@
|
|||||||
|
|
||||||
Internationalization Lib for Minetest
|
#Internationalization Lib for Minetest
|
||||||
By Diego Martínez (a.k.a. "Kaeza").
|
By Diego Martínez (a.k.a. "Kaeza").
|
||||||
Released as WTFPL.
|
Released as WTFPL.
|
||||||
|
|
||||||
This mod is an attempt at providing internationalization support for mods
|
This mod is an attempt at providing internationalization support for mods
|
||||||
(something Minetest currently lacks).
|
(something Minetest currently lacks).
|
||||||
|
|
||||||
How do I use it?
|
##How do I use it?
|
||||||
In order to enable it for your mod, copy the following code snippet and paste
|
In order to enable it for your mod, copy the following code snippet and paste
|
||||||
it at the beginning of your source file(s):
|
it at the beginning of your source file(s):
|
||||||
|
|
||||||
-- Boilerplate to support localized strings if intllib mod is installed.
|
```lua
|
||||||
local S
|
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||||
if minetest.get_modpath("intllib") then
|
local S
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
S = intllib.Getter()
|
S = intllib.Getter()
|
||||||
else
|
else
|
||||||
-- If you don't use insertions (@1, @2, etc) you can use this:
|
-- If you don't use insertions (@1, @2, etc) you can use this:
|
||||||
S = function(s) return s end
|
S = function(s) return s end
|
||||||
|
|
||||||
@ -23,8 +24,8 @@ it at the beginning of your source file(s):
|
|||||||
|
|
||||||
-- Use this if you require full functionality
|
-- Use this if you require full functionality
|
||||||
S = function(s,a,...)if a==nil then return s end a={a,...}return s:gsub("(@?)@(%(?)(%d+)(%)?)",function(e,o,n,c)if e==""then return a[tonumber(n)]..(o==""and c or"")else return"@"..o..n..c end end) end
|
S = function(s,a,...)if a==nil then return s end a={a,...}return s:gsub("(@?)@(%(?)(%d+)(%)?)",function(e,o,n,c)if e==""then return a[tonumber(n)]..(o==""and c or"")else return"@"..o..n..c end end) end
|
||||||
end
|
end
|
||||||
|
```
|
||||||
You will also need to optionally depend on intllib, to do so add "intllib?" to
|
You will also need to optionally depend on intllib, to do so add "intllib?" to
|
||||||
a empty line in your depends.txt. Also note that if intllib is not installed,
|
a empty line in your depends.txt. Also note that if intllib is not installed,
|
||||||
the S() function is defined so it returns the string unchanged. This is done
|
the S() function is defined so it returns the string unchanged. This is done
|
||||||
@ -34,30 +35,34 @@ if the lib is actually installed.
|
|||||||
Next, for each "translatable" string in your sources, use the S() function
|
Next, for each "translatable" string in your sources, use the S() function
|
||||||
(defined in the snippet) to return the translated string. For example:
|
(defined in the snippet) to return the translated string. For example:
|
||||||
|
|
||||||
minetest.register_node("mymod:mynode", {
|
```lua
|
||||||
|
minetest.register_node("mymod:mynode", {
|
||||||
description = S("My Fabulous Node"),
|
description = S("My Fabulous Node"),
|
||||||
<...>
|
<...>
|
||||||
})
|
})
|
||||||
|
```
|
||||||
|
|
||||||
Then, you create a `locale' directory inside your mod directory, with files
|
Then, you create a 'locale' directory inside your mod directory, with files
|
||||||
named after the two-letter ISO Language Code of the languages you want to
|
named after the two-letter ISO Language Code of the languages you want to
|
||||||
support. Here's an example for a Spanish locale file (`es.txt'):
|
support. Here's an example for a Spanish locale file (`es.txt'):
|
||||||
|
|
||||||
# Lines beginning with a pound sign are comments and are effectively ignored
|
```text
|
||||||
# by the reader. Note that comments only span until the end of the line;
|
# Lines beginning with a pound sign are comments and are effectively ignored
|
||||||
# there's no support for multiline comments.
|
# by the reader. Note that comments only span until the end of the line;
|
||||||
Hello, World! = Hola, Mundo!
|
# there's no support for multiline comments.
|
||||||
String with\nnewlines = Cadena con\nsaltos de linea
|
Hello, World! = Hola, Mundo!
|
||||||
String with an \= equals sign = Cadena con un signo de \= igualdad
|
String with\nnewlines = Cadena con\nsaltos de linea
|
||||||
|
String with an \= equals sign = Cadena con un signo de \= igualdad
|
||||||
|
```
|
||||||
|
|
||||||
Since there's currently no portable way to detect the language, this library
|
Since there's currently no portable way to detect the language, this library
|
||||||
tries several alternatives, and uses the first one found:
|
tries several alternatives, and uses the first one found:
|
||||||
- `language' setting in `minetest.conf'
|
- `language` setting in `minetest.conf`
|
||||||
- `LANG' environment variable (this is always set on Unix-like OSes).
|
- `LANG` environment variable (this is always set on Unix-like OSes).
|
||||||
- Default of "en".
|
- Default of `"en"`.
|
||||||
Note that in any case only up to the first two characters are used, so for
|
Note that in any case only up to the first two characters are used, so for
|
||||||
example, the settings "de_DE.UTF-8", "de_DE", and "de" are all equal.
|
example, the settings `"de_DE.UTF-8"`, `"de_DE"`, and `"de"` are all equal.
|
||||||
Windows users have no `LANG' environment variable by default. To add it, do
|
Windows users have no `LANG` environment variable by default. To add it, do
|
||||||
the following:
|
the following:
|
||||||
- Click Start->Settings->Control Panel.
|
- Click Start->Settings->Control Panel.
|
||||||
- Start the "System" applet.
|
- Start the "System" applet.
|
||||||
@ -78,6 +83,8 @@ Thanks for reading up to this point.
|
|||||||
Should you have any comments/suggestions, please post them in the forum topic.
|
Should you have any comments/suggestions, please post them in the forum topic.
|
||||||
|
|
||||||
Let there be translated texts! :P
|
Let there be translated texts! :P
|
||||||
--
|
|
||||||
|
\--
|
||||||
|
|
||||||
Yours Truly,
|
Yours Truly,
|
||||||
Kaeza
|
Kaeza
|
Loading…
Reference in New Issue
Block a user