Example #1
0
        private void Awake()
        {
            if (s_Instance != null)
            {
                throw new Exception("Only one LocaManager allowed");
            }
            if (m_Configs == null || m_Configs.Length == 0)
            {
                throw new Exception("No language defination");
            }
            s_Instance = this;
            DontDestroyOnLoad(gameObject);
            HashSet <SystemLanguage> hashSet = new HashSet <SystemLanguage>();

            foreach (LanguageConfig languageConfig in m_Configs)
            {
                if (!hashSet.Add(languageConfig.m_Language))
                {
                    throw new Exception("Double Language definition!");
                }
                if (languageConfig.m_LocaFiles == null || languageConfig.m_LocaFiles.Length == 0)
                {
                    throw new Exception("LocaFiles not defined in " + languageConfig.m_Language);
                }
            }
            LoadLanguage();
            LegacyLogic.Instance.EventManager.RegisterEvent(EEventType.MOD_LOADED, new EventHandler(OnModLoaded));
        }
Example #2
0
        public void Localize()
        {
            UIWidget component = GetComponent <UIWidget>();
            UILabel  uilabel   = component as UILabel;
            UISprite uisprite  = component as UISprite;

            if (mLanguage == SystemLanguage.Unknown && String.IsNullOrEmpty(loca_key) && uilabel != null)
            {
                loca_key = uilabel.text;
            }
            String text = (!String.IsNullOrEmpty(loca_key)) ? LocaManager.GetText(loca_key) : LocaManager.GetText(component.name);

            if (uilabel != null)
            {
                uilabel.text = text;
            }
            else if (uisprite != null)
            {
                uisprite.spriteName = text;
                uisprite.MakePixelPerfect();
            }
            mLanguage = LocaManager.Language;
        }