CommonCtrl.Locale

A simple lib for managing localization completely in the scripting interface.

Title A simple lib for managing localization completely in the scripting interface.
Author(s) LiXizhi
Date 2006/11/24
File script/ide/Locale.lua

Description

I have referred to Locale-2.0 by ckknight

TIP Sample Code

-- in localization file KidsUI-enUS.lua, we can build strings like these
NPL.load("(gl)script/ide/Locale.lua");
local L = CommonCtrl.Locale:new("KidsUI");
L:RegisterTranslations("enUS", function() return {
   -- Bindings
   ["Hello!"] = true,
   ["Greating"] = "hi, there!",
} end);

-- in localization file KidsUI-zhCN.lua, we can build strings like these
NPL.load("(gl)script/ide/Locale.lua");
local L = CommonCtrl.Locale:new("KidsUI");
L:RegisterTranslations("zhCN", function() return {
   -- Bindings
   ["Hello!"] = "浣犲ソ锛?,
   ["Greating"] = "浣犲ソ鍟?",
} end);

-- when application starts, load all available local files, see "script/lang.lua"
NPL.load("(gl)script/ide/Locale.lua");
CommonCtrl.Locale.AutoLoadFile("KidsUI-zhCN.lua");
CommonCtrl.Locale.AutoLoadFile("KidsUI-enUS.lua");

-- in normal scripts, we can use.
local L = CommonCtrl.Locale:new("KidsUI");
local str = L("Hello!")..L"Greating"

Member Functions

Locale.AutoLoadFile

 define a new control in the common control libary
local Locale = {
   registry = {}, 
   error = "",
   print_error = commonlib.warning,  
}
CommonCtrl.Locale = Locale;

only load the file if the locale in the file matches the current locale. the file name must be in the format X[lang].lua, where [lang] is the locale string such as enUS. if [lang] is not known locale, it will be discarded.

syntax

function Locale.AutoLoadFile(file)

parameters

file  
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback