This library allows you to translate strings and should be used whenever a script has text. It loads the appropriate locale file and check automatically.
Returns the localised string of
or, if it is not found, it returns
In order for your text to be taken by the string collection tools (so the string becomes available for translation), you have to follow a few simple syntax rules:
must be entirely a literal string
- The text must be enclosed in double quotes
- You must use the exact character sequence “
” to initiate the text, no spaces in between are permitted
AddCaption(loc("Hello World")) -- Displays “Hello World” translated into your language
These are all incorrect usages of the
l = loc( "Hello World") -- Contains space
l = loc ("Hello World") -- Contains space
l = loc('Hello World') -- Not double quotes
local str = "Hello World"
l = loc(str) -- Not a literal string, only use this if you use this together with `loc_noop`
l = loc(str .. ", how are you?") -- Only partially a literal string
Note these examples do not violate Lua syntax, it is in your responsibility to follow the syntax rules listed above.
. This function has the same syntax as
. Like for
, the text will be collected to be made available for translation.
You can use this function if you want a make a string available for translation but don't want the string to be translated right now. This can come in handy if you need to store strings in variables and want do something like