diff --git a/Zframework/languages.lua b/Zframework/languages.lua index 715c3110..158d0ff9 100644 --- a/Zframework/languages.lua +++ b/Zframework/languages.lua @@ -12,23 +12,30 @@ 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 LANG={} ---Must call before LANG.init +--Call these before call LANG.init() function LANG.setLangList(list)langList=list end function LANG.setPublicText(L)publicText=L end function LANG.setPublicWidgetText(L)publicWidgetText=L end -function LANG.init() +function LANG.init()--Attention, calling this will DESTORY ALL METHODS, only left LANG.set()! for i=1,#langList do local L=langList[i] - + --Set public text for key,list in next,publicText do L[key]=list end - + --Set public widget text for key,list in next,publicWidgetText do local WT=L.WidgetText @@ -37,31 +44,24 @@ function LANG.init() WT[key][k]=v end end - + --Fallback to other language, default zh if i>1 then langFallback(langList[L.fallback or 1],L) end - + --Metatable:__call for table:getTip if type(rawget(L,"getTip"))=="table"then setmetatable(L.getTip,tipMeta) end - + --set global name for all back button for _,v in next,L.WidgetText do v.back=L.back end end - LANG.init=nil -end - -function LANG.set(l) - text=langList[l] - WIDGET.setLang(text.WidgetText) - for _,s in next,drawableTextLoad do - drawableText[s]:set(text[s]) - end + LANG.init,LANG.setLangList,LANG.setPublicText,LANG.setPublicWidgetText=nil + LANG.set=lang_set end return LANG \ No newline at end of file diff --git a/Zframework/widget.lua b/Zframework/widget.lua index 69ee305c..f6bbb49e 100644 --- a/Zframework/widget.lua +++ b/Zframework/widget.lua @@ -3,12 +3,10 @@ local kb=love.keyboard local int,abs=math.floor,math.abs local max,min=math.max,math.min local sub,format=string.sub,string.format -local ins=table.insert local Timer=love.timer.getTime local setFont,mStr=setFont,mStr -local widgetList={} local WIDGET={} local widgetMetatable={ __tostring=function(self)