---++!! !CommonCtrl.Locale %TOC{title="Contents:"}% %STARTINCLUDE% ---++ 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 %T% __Sample Code__ <verbatim> -- 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" </verbatim> ---+++ Member Functions ---++++ !Locale.AutoLoadFile <verbatim> define a new control in the common control libary local Locale = { registry = {}, error = "", print_error = commonlib.warning, }</verbatim> 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__ <verbatim>function Locale.AutoLoadFile(file)</verbatim> __parameters__ | *file* | | %STOPINCLUDE%
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2008-02-29
-
LiXizhi
Home
Site map
CCWeb web
HaqiTeen web
Main web
ParaEngine web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
导航页WebTopMenu
Preferences
开发指南
Getting Started
ParacraftSDK
NPL
MCML
NPL Reference Manual
美术Mod
Account
Log In
English
简体中文
簡體中文
E
dit
A
ttach
Copyright © 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