fix: language bug, store custom object

This commit is contained in:
Qwreey 2023-02-23 14:13:15 +09:00
parent 29b3f26d89
commit 049ee5b60a
8 changed files with 240 additions and 199 deletions

View file

@ -1,48 +1,48 @@
**Default** (default) **Default** (default)
**English** (en_us) **English** (en-us)
**Spanish** (es_es) **Spanish** (es-es)
**French** (fr_fr) **French** (fr-fr)
**Indonesian** (id_id) **Indonesian** (id-id)
**Italian** (it_it) **Italian** (it-it)
**Japanese** (ja_jp) **Japanese** (ja-jp)
**Korean** (ko_kr) **Korean** (ko-kr)
**Russian** (ru_ru) **Russian** (ru-ru)
**Thai** (th_th) **Thai** (th-th)
**Turkish** (tr_tr) **Turkish** (tr-tr)
**Vietnamese** (vi_vn) **Vietnamese** (vi-vn)
**Portuguese** (pt_br) **Portuguese** (pt-br)
**German** (de_de) **German** (de-de)
**ChineseSimplified** (zh_cn) **ChineseSimplified** (zh-cn)
**ChineseTraditional** (zh_tw) **ChineseTraditional** (zh-tw)
**Bulgarian** (bg_bg) **Bulgarian** (bg-bg)
**Bengali** (bn_bd) **Bengali** (bn-bd)
**Czech** (cs_cz) **Czech** (cs-cz)
**Danish** (da_dk) **Danish** (da-dk)
**Greek** (el_gr) **Greek** (el-gr)
**Estonian** (et_ee) **Estonian** (et-ee)
**Finnish** (fi_fi) **Finnish** (fi-fi)
**Hindi** (hi_in) **Hindi** (hi-in)
**Croatian** (hr_hr) **Croatian** (hr-hr)
**Hungarian** (hu_hu) **Hungarian** (hu-hu)
**Georgian** (ka_ge) **Georgian** (ka-ge)
**Kazakh** (kk_kz) **Kazakh** (kk-kz)
**Khmer** (km_kh) **Khmer** (km-kh)
**Lithuanian** (lt_lt) **Lithuanian** (lt-lt)
**Latvian** (lv_lv) **Latvian** (lv-lv)
**Malay** (ms_my) **Malay** (ms-my)
**Burmese** (my_mm) **Burmese** (my-mm)
**Bokmal** (nb_no) **Bokmal** (nb-no)
**Dutch** (nl_nl) **Dutch** (nl-nl)
**Filipino** (fil_ph) **Filipino** (fil-ph)
**Polish** (pl_pl) **Polish** (pl-pl)
**Romanian** (ro_ro) **Romanian** (ro-ro)
**Ukrainian** (uk_ua) **Ukrainian** (uk-ua)
**Sinhala** (si_lk) **Sinhala** (si-lk)
**Slovak** (sk_sk) **Slovak** (sk-sk)
**Slovenian** (sl_sl) **Slovenian** (sl-sl)
**Albanian** (sq_al) **Albanian** (sq-al)
**Bosnian** (bs_ba) **Bosnian** (bs-ba)
**Serbian** (sr_rs) **Serbian** (sr-rs)
**Swedish** (sv_se) **Swedish** (sv-se)
**Arabic** (ar_001) **Arabic** (ar-001)

View file

@ -53,6 +53,8 @@ local myClass = Class.Extend()
-- 일반 오브젝트와 똑같이 id 를 넣고 GetObject 로 -- 일반 오브젝트와 똑같이 id 를 넣고 GetObject 로
-- 가져올 수도 있습니다 -- 가져올 수도 있습니다
local main = myClass "main" { local main = myClass "main" {
-- 이 테이블은 모듈의 :Init(props) 에 제공됩니다.
-- :Render(props) 에도 이 테이블이 제공됩니다.
Testing = 1; Testing = 1;
Text = "Test"; Text = "Test";
-- 레지스터 값을 넘겨줄 수도 있습니다. -- 레지스터 값을 넘겨줄 수도 있습니다.

View file

@ -31,12 +31,21 @@ myStore.color = Color3.fromRGB(0,0,0)
???+ Warning "주의" ???+ Warning "주의"
구현의 복잡성의 이유로 레지스터는 오브젝트 생성시에만 등록할 수 있습니다. 구현의 복잡성의 이유로 레지스터는 오브젝트 생성시에만 등록할 수 있습니다.
```lua ```lua
local myFrame = Frame{} local myFrame = Frame{}
Frame.BackgroundColor3 = myStore "color" Frame.BackgroundColor3 = myStore "color"
``` ```
위처럼 사용할 수 없습니다. 위처럼 사용할 수 없습니다.
```lua
local myFrame = Frame{}
Apply (myFrame) {
BackgroundColor3 = myStore "color";
}
```
> 1. 스토어를 생성함. > 1. 스토어를 생성함.
> 2. 기본 값을 설정함. > 2. 기본 값을 설정함.
> 3. 스토어를 호출해 레지스터를 얻어 등록함. > 3. 스토어를 호출해 레지스터를 얻어 등록함.

View file

@ -12,7 +12,7 @@
Quad 에는 귀찮은 언어관리를 자동으로 해주는 기능이 내장되어 있습니다. 이 기능은 register 와 연동해 적은 줄의 코드로 변하는 텍스트도 언어에 맞게 출력되도록 만들 수 있습니다. Quad 에는 귀찮은 언어관리를 자동으로 해주는 기능이 내장되어 있습니다. 이 기능은 register 와 연동해 적은 줄의 코드로 변하는 텍스트도 언어에 맞게 출력되도록 만들 수 있습니다.
번역 테이블은 `#!ts Lang.New(LangName:string,{ [Locale]: string|(options)->string })` 다음을 이용해 만들 수 있으며. 번역 테이블은 `#!ts Lang.New(LangName:string,{ [Locale]: string|(options)->string })` 다음을 이용해 만들 수 있으며.
`Lang(LangName:string)(options)` 로 UI 에 적용시킬 수 있습니다. `#!ts Lang(LangName:string)(options)->register` 로 UI 에 적용시킬 수 있습니다.
=== "용법" === "용법"
@ -78,6 +78,27 @@ Quad 에는 귀찮은 언어관리를 자동으로 해주는 기능이 내장되
end end
``` ```
???+ Warning "주의"
구현의 복잡성의 이유로 Lang 은 레지스터와 같은 제약을 가집니다 (오브젝트 생성시에만 등록할 수 있습니다)
```lua
local myLabel = TextLabel{}
Lang.new("Test",{ [Lang.Locales.Default] = "{lang}" })
myLabel.Text = Lang "Test" { lang = 1 }
```
위처럼 사용할 수 없습니다.
대신에 `#!ts :Register` 문법을 사용하여 등록할 수 있습니다.
```lua
local myLabel = TextLabel{}
Lang.new("Test",{ [Lang.Locales.Default] = "{lang}" })
Apply (myLabel) {
Text = Lang "Test" { lang = 1 };
}
```
--- ---
## Locale 목록 ## Locale 목록

View file

@ -27,6 +27,7 @@ function module.init(shared)
local round = shared.Round ---@type quad_module_round local round = shared.Round ---@type quad_module_round
local signal = shared.Signal ---@type quad_module_signal local signal = shared.Signal ---@type quad_module_signal
local bindable = signal.Bindable local bindable = signal.Bindable
local PcallGetProperty = store.PcallGetProperty
local function InstanceNewWithName(classname,parent,name) local function InstanceNewWithName(classname,parent,name)
local item = InstanceNew(classname,parent) local item = InstanceNew(classname,parent)
@ -108,16 +109,6 @@ function module.init(shared)
end end
new.SetProperty = SetProperty new.SetProperty = SetProperty
local function RawGetProperty(item,index)
return item[index]
end
local function PcallGetProperty(item,index)
local ok,err = pcall(RawGetProperty,item,index)
if ok then return err end
return nil
end
new.PcallGetProperty = PcallGetProperty
local function Link(linker,item,index,indexType) local function Link(linker,item,index,indexType)
local target = linker.target local target = linker.target
local name = linker.name local name = linker.name
@ -550,6 +541,11 @@ function module.init(shared)
return this return this
end end
local function Apply()
end
new.Apply = Apply
return new return new
end end

View file

@ -13,52 +13,52 @@ function module.init(shared)
new.Locales = { new.Locales = {
["Default"] = "default"; ["Default"] = "default";
["English"] = "en_us"; ["English"] = "en-us";
["Spanish"] = "es_es"; ["Spanish"] = "es-es";
["French"] = "fr_fr"; ["French"] = "fr-fr";
["Indonesian"] = "id_id"; ["Indonesian"] = "id-id";
["Italian"] = "it_it"; ["Italian"] = "it-it";
["Japanese"] = "ja_jp"; ["Japanese"] = "ja-jp";
["Korean"] = "ko_kr"; ["Korean"] = "ko-kr";
["Russian"] = "ru_ru"; ["Russian"] = "ru-ru";
["Thai"] = "th_th"; ["Thai"] = "th-th";
["Turkish"] = "tr_tr"; ["Turkish"] = "tr-tr";
["Vietnamese"] = "vi_vn"; ["Vietnamese"] = "vi-vn";
["Portuguese"] = "pt_br"; ["Portuguese"] = "pt-br";
["German"] = "de_de"; ["German"] = "de-de";
["ChineseSimplified"] = "zh_cn"; ["ChineseSimplified"] = "zh-cn";
["ChineseTraditional"] = "zh_tw"; ["ChineseTraditional"] = "zh-tw";
["Bulgarian"] = "bg_bg"; ["Bulgarian"] = "bg-bg";
["Bengali"] = "bn_bd"; ["Bengali"] = "bn-bd";
["Czech"] = "cs_cz"; ["Czech"] = "cs-cz";
["Danish"] = "da_dk"; ["Danish"] = "da-dk";
["Greek"] = "el_gr"; ["Greek"] = "el-gr";
["Estonian"] = "et_ee"; ["Estonian"] = "et-ee";
["Finnish"] = "fi_fi"; ["Finnish"] = "fi-fi";
["Hindi"] = "hi_in"; ["Hindi"] = "hi-in";
["Croatian"] = "hr_hr"; ["Croatian"] = "hr-hr";
["Hungarian"] = "hu_hu"; ["Hungarian"] = "hu-hu";
["Georgian"] = "ka_ge"; ["Georgian"] = "ka-ge";
["Kazakh"] = "kk_kz"; ["Kazakh"] = "kk-kz";
["Khmer"] = "km_kh"; ["Khmer"] = "km-kh";
["Lithuanian"] = "lt_lt"; ["Lithuanian"] = "lt-lt";
["Latvian"] = "lv_lv"; ["Latvian"] = "lv-lv";
["Malay"] = "ms_my"; ["Malay"] = "ms-my";
["Burmese"] = "my_mm"; ["Burmese"] = "my-mm";
["Bokmal"] = "nb_no"; ["Bokmal"] = "nb-no";
["Dutch"] = "nl_nl"; ["Dutch"] = "nl-nl";
["Filipino"] = "fil_ph"; ["Filipino"] = "fil-ph";
["Polish"] = "pl_pl"; ["Polish"] = "pl-pl";
["Romanian"] = "ro_ro"; ["Romanian"] = "ro-ro";
["Ukrainian"] = "uk_ua"; ["Ukrainian"] = "uk-ua";
["Sinhala"] = "si_lk"; ["Sinhala"] = "si-lk";
["Slovak"] = "sk_sk"; ["Slovak"] = "sk-sk";
["Slovenian"] = "sl_sl"; ["Slovenian"] = "sl-sl";
["Albanian"] = "sq_al"; ["Albanian"] = "sq-al";
["Bosnian"] = "bs_ba"; ["Bosnian"] = "bs-ba";
["Serbian"] = "sr_rs"; ["Serbian"] = "sr-rs";
["Swedish"] = "sv_se"; ["Swedish"] = "sv-se";
["Arabic"] = "ar_001"; ["Arabic"] = "ar-001";
} }
local function GetLocale() local function GetLocale()
@ -75,6 +75,7 @@ function module.init(shared)
local weak = {__mode = "v"} local weak = {__mode = "v"}
local lang = {} local lang = {}
local langList = {}
lang.__index = lang lang.__index = lang
function lang.New(id,handlers) function lang.New(id,handlers)
local this = { local this = {
@ -84,7 +85,7 @@ function module.init(shared)
index=1; index=1;
registers = setmetatable({},weak); registers = setmetatable({},weak);
} }
lang[id] = this langList[id] = this
if not handlers[new.Locales.Default] then if not handlers[new.Locales.Default] then
warn(("Localization %s have no Default value, Did you missed '[Lang.Locales.Default] = ...' ? It may make Localization fail on other languages")) warn(("Localization %s have no Default value, Did you missed '[Lang.Locales.Default] = ...' ? It may make Localization fail on other languages"))
end end
@ -205,7 +206,7 @@ function module.init(shared)
end end
function new.Update() function new.Update()
for _,this in pairs(lang) do for _,this in pairs(langList) do
this:UpdateAll() this:UpdateAll()
end end
end end
@ -213,7 +214,7 @@ function module.init(shared)
setmetatable(new,{ setmetatable(new,{
__call = function(_,id) __call = function(_,id)
return function (options) return function (options)
local data = lang[id] local data = langList[id]
if not data then if not data then
error(("Localization %s is not definded"):format(id)) error(("Localization %s is not definded"):format(id))
end end

View file

@ -40,6 +40,16 @@ function module.init(shared)
local items = {} local items = {}
new.Items = items new.Items = items
local function RawGetProperty(item,index)
return item[index]
end
local function PcallGetProperty(item,index)
local ok,err = pcall(RawGetProperty,item,index)
if ok then return err end
return nil
end
new.PcallGetProperty = PcallGetProperty
-- id space (array of object) -- id space (array of object)
local objectListClass = {__type = "quad_objectlist"} local objectListClass = {__type = "quad_objectlist"}
function objectListClass:EachAsync(func) function objectListClass:EachAsync(func)
@ -290,7 +300,7 @@ function module.init(shared)
end end
function store:__newindex(key,value) function store:__newindex(key,value)
-- if got register, just copy data to self and connect -- if got register, just copy data to self and connect
if type(value) == "table" and value.__type == "quad_register" then if PcallGetProperty(value,"__type") == "quad_register" then
-- warn "[Quad] adding register value on store is only allowed when init store. set value request was ignored" -- warn "[Quad] adding register value on store is only allowed when init store. set value request was ignored"
local selfValues = self.__self local selfValues = self.__self

View file

@ -218,100 +218,102 @@ export type langHandler = {
export type Locale = string export type Locale = string
export type module_lang = { export type module_lang = {
New: (id:string,handlers:{ New: (id:string,handlers:{
en_us: langHandler; ["default"]: langHandler;
es_es: langHandler; ["en-us"]: langHandler;
fr_fr: langHandler; ["es-es"]: langHandler;
id_id: langHandler; ["fr-fr"]: langHandler;
it_it: langHandler; ["id-id"]: langHandler;
ja_jp: langHandler; ["it-it"]: langHandler;
ko_kr: langHandler; ["ja-jp"]: langHandler;
ru_ru: langHandler; ["ko-kr"]: langHandler;
th_th: langHandler; ["ru-ru"]: langHandler;
tr_tr: langHandler; ["th-th"]: langHandler;
vi_vn: langHandler; ["tr-tr"]: langHandler;
pt_br: langHandler; ["vi-vn"]: langHandler;
de_de: langHandler; ["pt-br"]: langHandler;
zh_cn: langHandler; ["de-de"]: langHandler;
zh_tw: langHandler; ["zh-cn"]: langHandler;
bg_bg: langHandler; ["zh-tw"]: langHandler;
bn_bd: langHandler; ["bg-bg"]: langHandler;
cs_cz: langHandler; ["bn-bd"]: langHandler;
da_dk: langHandler; ["cs-cz"]: langHandler;
el_gr: langHandler; ["da-dk"]: langHandler;
et_ee: langHandler; ["el-gr"]: langHandler;
fi_fi: langHandler; ["et-ee"]: langHandler;
hi_in: langHandler; ["fi-fi"]: langHandler;
hr_hr: langHandler; ["hi-in"]: langHandler;
hu_hu: langHandler; ["hr-hr"]: langHandler;
ka_ge: langHandler; ["hu-hu"]: langHandler;
kk_kz: langHandler; ["ka-ge"]: langHandler;
km_kh: langHandler; ["kk-kz"]: langHandler;
lt_lt: langHandler; ["km-kh"]: langHandler;
lv_lv: langHandler; ["lt-lt"]: langHandler;
ms_my: langHandler; ["lv-lv"]: langHandler;
my_mm: langHandler; ["ms-my"]: langHandler;
nb_no: langHandler; ["my-mm"]: langHandler;
nl_nl: langHandler; ["nb-no"]: langHandler;
fil_ph: langHandler; ["nl-nl"]: langHandler;
pl_pl: langHandler; ["fil-ph"]: langHandler;
ro_ro: langHandler; ["pl-pl"]: langHandler;
uk_ua: langHandler; ["ro-ro"]: langHandler;
si_lk: langHandler; ["uk-ua"]: langHandler;
sk_sk: langHandler; ["si-lk"]: langHandler;
sl_sl: langHandler; ["sk-sk"]: langHandler;
sq_al: langHandler; ["sl-sl"]: langHandler;
bs_ba: langHandler; ["sq-al"]: langHandler;
sr_rs: langHandler; ["bs-ba"]: langHandler;
sv_se: langHandler; ["sr-rs"]: langHandler;
ar_001: langHandler; ["sv-se"]: langHandler;
["ar-001"]: langHandler;
})->(); })->();
Locales: { Locales: {
English: Locale & "en_us"; Default: "default";
Spanish: Locale & "es_es"; English: Locale & "en-us";
French: Locale & "fr_fr"; Spanish: Locale & "es-es";
Indonesian: Locale & "id_id"; French: Locale & "fr-fr";
Italian: Locale & "it_it"; Indonesian: Locale & "id-id";
Japanese: Locale & "ja_jp"; Italian: Locale & "it-it";
Korean: Locale & "ko_kr"; Japanese: Locale & "ja-jp";
Russian: Locale & "ru_ru"; Korean: Locale & "ko-kr";
Thai: Locale & "th_th"; Russian: Locale & "ru-ru";
Turkish: Locale & "tr_tr"; Thai: Locale & "th-th";
Vietnamese: Locale & "vi_vn"; Turkish: Locale & "tr-tr";
Portuguese: Locale & "pt_br"; Vietnamese: Locale & "vi-vn";
German: Locale & "de_de"; Portuguese: Locale & "pt-br";
ChineseSimplified: Locale & "zh_cn"; German: Locale & "de-de";
ChineseTraditional: Locale & "zh_tw"; ChineseSimplified: Locale & "zh-cn";
Bulgarian: Locale & "bg_bg"; ChineseTraditional: Locale & "zh-tw";
Bengali: Locale & "bn_bd"; Bulgarian: Locale & "bg-bg";
Czech: Locale & "cs_cz"; Bengali: Locale & "bn-bd";
Danish: Locale & "da_dk"; Czech: Locale & "cs-cz";
Greek: Locale & "el_gr"; Danish: Locale & "da-dk";
Estonian: Locale & "et_ee"; Greek: Locale & "el-gr";
Finnish: Locale & "fi_fi"; Estonian: Locale & "et-ee";
Hindi: Locale & "hi_in"; Finnish: Locale & "fi-fi";
Croatian: Locale & "hr_hr"; Hindi: Locale & "hi-in";
Hungarian: Locale & "hu_hu"; Croatian: Locale & "hr-hr";
Georgian: Locale & "ka_ge"; Hungarian: Locale & "hu-hu";
Kazakh: Locale & "kk_kz"; Georgian: Locale & "ka-ge";
Khmer: Locale & "km_kh"; Kazakh: Locale & "kk-kz";
Lithuanian: Locale & "lt_lt"; Khmer: Locale & "km-kh";
Latvian: Locale & "lv_lv"; Lithuanian: Locale & "lt-lt";
Malay: Locale & "ms_my"; Latvian: Locale & "lv-lv";
Burmese: Locale & "my_mm"; Malay: Locale & "ms-my";
Bokmal: Locale & "nb_no"; Burmese: Locale & "my-mm";
Dutch: Locale & "nl_nl"; Bokmal: Locale & "nb-no";
Filipino: Locale & "fil_ph"; Dutch: Locale & "nl-nl";
Polish: Locale & "pl_pl"; Filipino: Locale & "fil-ph";
Romanian: Locale & "ro_ro"; Polish: Locale & "pl-pl";
Ukrainian: Locale & "uk_ua"; Romanian: Locale & "ro-ro";
Sinhala: Locale & "si_lk"; Ukrainian: Locale & "uk-ua";
Slovak: Locale & "sk_sk"; Sinhala: Locale & "si-lk";
Slovenian: Locale & "sl_sl"; Slovak: Locale & "sk-sk";
Albanian: Locale & "sq_al"; Slovenian: Locale & "sl-sl";
Bosnian: Locale & "bs_ba"; Albanian: Locale & "sq-al";
Serbian: Locale & "sr_rs"; Bosnian: Locale & "bs-ba";
Swedish: Locale & "sv_se"; Serbian: Locale & "sr-rs";
Arabic: Locale & "ar_001"; Swedish: Locale & "sv-se";
Arabic: Locale & "ar-001";
}; };
CurrentLocale: Locale; CurrentLocale: Locale;
FailedMessage: string; FailedMessage: string;