author Wuzzy
Wed, 02 May 2018 22:50:18 +0100
changeset 1333 60d456e83554
parent 1329 bd781e19a52d
child 1334 d8462452d5e3
permissions -rw-r--r--
LuaLibraryLocale: Edited via web interface

#summary Lua library documentation; Locale
#labels LuaLibrary

= Lua library: `Locale` =

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.

== `loc(text)` ==

Returns the localised string of `text` or, if it is not found, it returns `text`.

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:

 * `text` _must_ be entirely a literal string
 * The text _must_ be enclosed in double quotes
 * You _must_ use the exact character sequence “`loc("`” to initiate the text, no spaces in between are permitted

Valid example:
<code language="lua">
AddCaption(loc("Hello World"))  -- Displays “Hello World” translated into your language

These are all _incorrect_ usages of the `loc` function:
<code language="lua">
local l
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
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.

== `loc_noop(text)` ==
Just returns `text`. This function has the same syntax as `loc`. Like for `loc`, 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 `loc(variable_name)` later.