Esempio n. 1
0
        protected bool TryGetLocalizedText(out string p_localizedValue)
        {
            bool v_sucess = false;

            if ((!string.IsNullOrEmpty(m_key) || m_autoTrackKey) && LocaleManager.InstanceExists())
            {
                // If no localization key has been specified, use the label's/Input's text as the key
                if (m_autoTrackKey && string.IsNullOrEmpty(_language) && string.IsNullOrEmpty(m_key))
                {
                    m_key = Text;
                }

                // If we still don't have a key, leave the value as blank
                if (string.IsNullOrEmpty(m_key))
                {
                    p_localizedValue = "";
                }
                else
                {
                    v_sucess = LocaleManager.TryGetLocalizedText(m_key, out p_localizedValue, m_supportLocaleRichTextTags);
                }

                //Return Key value if localization is empty
                if (!v_sucess)
                {
                    p_localizedValue = m_key;
                }
            }
            else
            {
                p_localizedValue = m_key != null? m_key : "";
            }

            return(v_sucess);
        }
Esempio n. 2
0
        protected override void Apply()
        {
            if (!Application.isPlaying)
            {
                return;
            }

            if (LocaleManager.InstanceExists())
            {
                UnregisterEvents();

                string v_localizedValue;
                if (TryGetLocalizedText(out v_localizedValue))
                {
                    Text = v_localizedValue;
                }

                _language = LocaleManager.Instance.CurrentLanguage;

                if (enabled && gameObject.activeInHierarchy)
                {
                    RegisterEvents();
                }
            }

            _lastLocalizedValue = Text;
        }
 protected virtual void HandleOnLocalize(bool p_forceReapply)
 {
     if (LocaleManager.InstanceExists() && m_isLocalized && (p_forceReapply || !string.Equals(_lastLocalizedLanguage, LocaleManager.Instance.CurrentLanguage)))
     {
         //Invalidate Text
         SetText(m_text);
     }
 }
        protected virtual bool ParseInputTextAndLocalizeTags()
        {
            _localeParsingRequired = false;

            //Only parse when richtext active (we need the <sprite=index> tag)
            if (LocaleManager.InstanceExists() || !Application.isPlaying || (m_supportLocaleRichTextTags && m_isRichText && !m_isLocalized))
            {
                var v_parsedLocale = false;
                var v_oldText      = m_text;

                if (IsInputParsingRequired_Internal)
                {
                    m_text = m_text != null?m_text.Replace("\n", "\\n").Replace("\r", "") : null;
                }

                v_parsedLocale = !Application.isPlaying || (m_supportLocaleRichTextTags && m_isRichText && !m_isLocalized) ?
                                 TryClearLocaleTags(m_text, out m_text) :
                                 TryGetLocalizedText(m_text, out m_text);


                _localeParsingRequired          = false;
                IsInputParsingRequired_Internal = false;
                InputSource_Internal            = TextInputSources.Text;

                ParseInputText();

                _localeParsingRequired          = false;
                IsInputParsingRequired_Internal = false;

                //Debug.Log("ParseInputTextAndEmojiCharSequence");
                //We must revert the original text because we dont want to permanently change the text
                m_text = v_oldText;

#if !TMP_2_1_0_PREVIEW_10_OR_NEWER
                m_isCalculateSizeRequired = true;
#endif

                return(v_parsedLocale);
            }

            return(false);
        }
Esempio n. 5
0
        protected override void OnEnable()
        {
            RegisterEvents();

            if (!Application.isPlaying)
            {
                return;
            }

            if (_started)
            {
                //Update AutoTrack Key Value
                HandleOnVerticesDirty();
                //_lastLocalizedValue = Text;
                if (LocaleManager.InstanceExists() && !string.Equals(Language, LocaleManager.Instance.CurrentLanguage, StringComparison.InvariantCultureIgnoreCase))
                {
                    SetDirty(); //prevent localize bugs when changing scene
                }
            }
        }
        protected bool TryGetLocalizedText(string p_text, out string p_localizedValue)
        {
            bool v_sucess = false;

            if (m_isLocalized && !string.IsNullOrEmpty(p_text) && LocaleManager.InstanceExists())
            {
                v_sucess = LocaleManager.TryGetLocalizedText(p_text, out p_localizedValue, m_supportLocaleRichTextTags && m_isRichText);

                //Return Key value if localization is empty
                if (!v_sucess)
                {
                    p_localizedValue = p_text;
                }

                _lastLocalizedLanguage = LocaleManager.Instance.CurrentLanguage;
            }
            else
            {
                p_localizedValue = p_text != null ? p_text : "";
            }

            return(v_sucess);
        }