From b0f885ab2c682fb18420428ab2e12eceec9c9909 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Tue, 15 Dec 2020 14:46:52 +0800 Subject: [PATCH] =?UTF-8?q?LANG=E6=A8=A1=E5=9D=97=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=95=B4=E7=90=86=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E7=9A=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/languages.lua | 47 ++++++++++++++++++++-------------------- main.lua | 5 ++++- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Zframework/languages.lua b/Zframework/languages.lua index 158d0ff9..f346d5af 100644 --- a/Zframework/languages.lua +++ b/Zframework/languages.lua @@ -1,25 +1,4 @@ -local function langFallback(T0,T) - for k,v in next,T0 do - if type(v)=="table"and not v.refuseCopy then--refuseCopy: just copy pointer, not contents - if not T[k]then T[k]={}end - if type(T[k])=="table"then langFallback(v,T[k])end - elseif not T[k]then - T[k]=v - end - end -end -local tipMeta={__call=function(L)return L[math.random(#L)]end} - -local langList={} -local publicText,publicWidgetText={},{} -local function lang_set(l) - text=langList[l] - WIDGET.setLang(text.WidgetText) - for _,s in next,drawableTextLoad do - drawableText[s]:set(text[s]) - end -end - +local langList,publicText,publicWidgetText={},{},{} local LANG={} --Call these before call LANG.init() @@ -27,7 +6,19 @@ function LANG.setLangList(list)langList=list end function LANG.setPublicText(L)publicText=L end function LANG.setPublicWidgetText(L)publicWidgetText=L end -function LANG.init()--Attention, calling this will DESTORY ALL METHODS, only left LANG.set()! +function LANG.init()--Attention, calling this will destory all initializing methods, create a LANG.set()! + local function langFallback(T0,T) + for k,v in next,T0 do + if type(v)=="table"and not v.refuseCopy then--refuseCopy: just copy pointer, not contents + if not T[k]then T[k]={}end + if type(T[k])=="table"then langFallback(v,T[k])end + elseif not T[k]then + T[k]=v + end + end + end + local tipMeta={__call=function(L)return L[math.random(#L)]end} + for i=1,#langList do local L=langList[i] @@ -60,8 +51,16 @@ function LANG.init()--Attention, calling this will DESTORY ALL METHODS, only lef v.back=L.back end end + LANG.init,LANG.setLangList,LANG.setPublicText,LANG.setPublicWidgetText=nil - LANG.set=lang_set + + function LANG.set(l) + text=langList[l] + WIDGET.setLang(text.WidgetText) + for _,s in next,drawableTextLoad do + drawableText[s]:set(text[s]) + end + end end return LANG \ No newline at end of file diff --git a/main.lua b/main.lua index eafe8e4d..b28a1cf6 100644 --- a/main.lua +++ b/main.lua @@ -166,7 +166,10 @@ LANG.setLangList{ require"parts/language/lang_sp", require"parts/language/lang_symbol", require"parts/language/lang_yygq", - --Add new language file to LANG folder. Attention, new language won't show in-game when you add language + --1. Add language file to LANG folder; + --2. Require it; + --3. Add a button in parts/scenes/setting_lang.lua; + --4. Set button name at LANG.setPublicWidgetText.lang beneath. } LANG.setPublicText{ block={