void OnEnable(){ string[] moduels; EditorLocalize.GetModuelNames(out moduels); _moduelName = moduels[0]; _moduel = EditorLocalize.LoadModuel(_moduelName); stringSet = _moduel.GetAllKeys().ToList(); filter = ""; }
private Localize(TextAsset current,TextAsset fallback){ try{ _current = JsonMapper.ToObject<Collection>(current.text); if(fallback != null){ _fallback = JsonMapper.ToObject<Collection>(fallback.text); } }catch(System.Exception e){ Debug.LogException(e); Debug.LogError("Json format is wrong!"); return; } Localize.active = this; _localizeMap.Add(_current.moduelName,this); }
private Localize(Collection current,Collection fallback){ _current = current; _fallback = fallback; Localize.active = this; _localizeMap.Add(_current.moduelName,this); }
public static void UnloadAll(){ _localizeMap.Clear(); Localize.active = null; }
/// <summary> /// Load localization json files. /// </summary> public static void Load(string moduelName,System.Action<Localize> onComplete,SystemLanguage? fallbackLan = null, ILoader loader = null){ if(ExistModuel(moduelName)){ Debug.LogWarning("Already existed moduel : "+moduelName); onComplete(GetModuel(moduelName)); return; } SystemLanguage currentLan = Localize.preferLanguage; LoadCollection(moduelName,currentLan,delegate(Collection current) { if(fallbackLan !=null && fallbackLan != currentLan){ LoadCollection(moduelName,(SystemLanguage)fallbackLan,delegate(Collection fallback) { Localize loc = null; if(current != null){ loc = new Localize(current,fallback); } onComplete(loc); },loader); }else{ Localize loc = null; if(current != null){ loc = new Localize(current,null); } onComplete(loc); } },loader); }
public static Localize Load(string modulename, string format, TextAsset main, TextAsset fallback = null){ if(!_decoderMap.ContainsKey(format)){ throw new System.Exception("thers is no decoder for foramt : "+format); } var decoder = _decoderMap[format]; Collection mainCol = null; Collection fallbackCol = null; try{ mainCol = decoder.Invoke(main.text); if(fallback != null){ fallbackCol = decoder.Invoke(fallback.text); } }catch(System.Exception e){ Debug.LogException(e); Debug.LogFormat("file content is wrong! {0}.{1}",main.name,format); return null; } var loc = new Localize(modulename, mainCol,fallbackCol); _localizeMap.Add(modulename,loc); return loc; }
/// <summary> /// Load localization json files. /// </summary> public static void Load(string filename, System.Action<Localize> onComplete, SystemLanguage? fallbackLan = null, ILoader loader = null){ string format = System.IO.Path.GetExtension(filename).Substring(1); string moduleName = System.IO.Path.GetFileNameWithoutExtension(filename); if(!_decoderMap.ContainsKey(format)){ throw new System.Exception("no decoder for format : "+format); } if(ExistModule(moduleName)){ Debug.LogWarning("Already existed module : "+moduleName); onComplete(GetModule(moduleName)); return; } SystemLanguage mainLan = Localize.preferLanguage; LoadCollection(moduleName,format,mainLan,delegate(Collection main) { if(fallbackLan !=null && fallbackLan != mainLan){ LoadCollection(moduleName,format,(SystemLanguage)fallbackLan,delegate(Collection fallback) { Localize loc = null; loc = new Localize(moduleName,main,fallback); _localizeMap.Add(moduleName,loc); onComplete(loc); },loader); }else{ Localize loc = null; loc = new Localize(moduleName, main,null); _localizeMap.Add(moduleName,loc); onComplete(loc); } },loader); }
private void SelectModule(int index){ _focusedModuleIndex = index; _module = EditorLocalize.LoadModule(filenames[index]); stringSet = _module.GetAllKeys().ToList(); filter = ""; }