LuaLibraryLocale.wiki
changeset 1329 bd781e19a52d
child 1333 60d456e83554
equal deleted inserted replaced
1328:7c0b4029caa1 1329:bd781e19a52d
       
     1 #summary Lua library documentation: Locale
       
     2 #labels LuaLibrary
       
     3 
       
     4 = Lua library: `Locale` =
       
     5 
       
     6 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.
       
     7 
       
     8 == `loc(text)` ==
       
     9 
       
    10 Returns the localised string of `text` or, if it is not found, it returns `text`.
       
    11 
       
    12 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:
       
    13 
       
    14  * `text` _must_ be entirely a literal string
       
    15  * The text _must_ be enclosed in double quotes
       
    16  * You _must_ use the exact character sequence “`loc("`” to initiate the text, no spaces in between are permitted
       
    17 
       
    18 Valid example:
       
    19 <code language="lua">
       
    20 AddCaption(loc("Hello World"))  -- Displays “Hello World” translated into your language
       
    21 </code>
       
    22 
       
    23 These are all _incorrect_ usages of the `loc` function:
       
    24 <code language="lua">
       
    25 local l
       
    26 l = loc( "Hello World")    -- Contains space
       
    27 l = loc ("Hello World")    -- Contains space
       
    28 l = loc('Hello World')     -- Not double quotes
       
    29 local str = "Hello World"
       
    30 l = loc(str)   -- Not a literal string
       
    31 l = loc(str .. ", how are you?")   -- Only partially a literal string
       
    32 </code>
       
    33 
       
    34 Note these examples do _not_ violate Lua syntax, it is in your responsibility to follow the syntax rules listed above.
       
    35 
       
    36 == `loc_noop(text)` ==
       
    37 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.
       
    38 
       
    39 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.