Exemplo n.º 1
0
        public override string ToString()
        {
            var translation = LocalizationManager.GetTranslation(mTerm, !mRTL_IgnoreArabicFix, mRTL_MaxLineLength, !mRTL_ConvertNumbers, true);

            LocalizationManager.ApplyLocalizationParams(ref translation);
            return(translation);
        }
Exemplo n.º 2
0
        private static string GetTranslationForLanguage(string key, string code)
        {
            string language    = GetLanguageTitleByCode(code);
            string translation = LocalizationManager.GetTranslation(key, true, 0, true, false, null, language);

            Debug.Log($"Mapped code {code} to language {language}");
            Debug.Log($"Got translation for {key} and {code}: {translation}");

            return(translation);
        }
Exemplo n.º 3
0
        public void OnModifyLocalization()
        {
            if (string.IsNullOrEmpty(Localize.MainTranslation))
            {
                return;
            }

            string PlayerColor = LocalizationManager.GetTranslation("Color/Red");

            Localize.MainTranslation = Localize.MainTranslation.Replace("{PLAYER_COLOR}", PlayerColor);
        }
Exemplo n.º 4
0
        public override void OnEnter()
        {
            var termTranslation = mSource == null?LocalizationManager.GetTranslation(term.Value) : mSource.GetTranslation(term.Value);

            if (!translation.IsNone)
            {
                translation.Value = termTranslation;
            }

            Finish();
        }
        public string _StringWithTermPopup;             // Example of making a normal string that show as a popup with all the terms in the inspector

        public void Start()
        {
            // LocalizedString are strings that can be set to a Term, and when getting its value, return the Term's translation

            // Basic Example of using LocalizedString in the Inspector
            // Just change the Term in the inspector, and use this to access the term translation
            Debug.Log(_MyLocalizedString);
            Debug.Log(LocalizationManager.GetTranslation(_NormalString));         // regular strings need to manually call GetTranslation()
            Debug.Log(LocalizationManager.GetTranslation(_StringWithTermPopup));  // same here, given that this string just have a custom inspector



            // Example of setting the term in code to get its translation
            LocalizedString locString   = "Term2";
            string          translation = locString; // returns the translation of Term2 to the current language

            Debug.Log(translation);



            // Assigning a LocalizedString to another LocalizedString, copies the reference to its term
            LocalizedString locString1 = _MyLocalizedString;

            Debug.Log(locString1);



            // LocalizedString have settings to customize the result

            LocalizedString customString = "Term3";

            Debug.Log(customString);

            LocalizedString customNoRTL = "Term3";

            customNoRTL.mRTL_IgnoreArabicFix = true;
            Debug.Log(customNoRTL);


            LocalizedString customString1 = "Term3";

            customString1.mRTL_ConvertNumbers = true;
            customString1.mRTL_MaxLineLength  = 20;
            Debug.Log(customString1);



            // Copying a LocalizedString also copies its settings
            LocalizedString customStringCopy = customString1;

            Debug.Log(customStringCopy);
        }
Exemplo n.º 6
0
        public void UpdateLocalizationTMPro()
        {
            var _Dropdown = GetComponent <TMPro.TMP_Dropdown>();

            if (_Dropdown == null)
            {
                return;
            }

            _Dropdown.options.Clear();
            foreach (var term in _Terms)
            {
                var translation = LocalizationManager.GetTranslation(term);
                _Dropdown.options.Add(new TMPro.TMP_Dropdown.OptionData(translation));
            }
            _Dropdown.RefreshShownValue();
        }
Exemplo n.º 7
0
        public void OnLocalize(bool Force = false)
        {
            if (!Force && (!enabled || gameObject == null || !gameObject.activeInHierarchy))
            {
                return;
            }

            if (string.IsNullOrEmpty(LocalizationManager.CurrentLanguage))
            {
                return;
            }

            if (!AlwaysForceLocalize && !Force && !LocalizeCallBack.HasCallback() && LastLocalizedLanguage == LocalizationManager.CurrentLanguage)
            {
                return;
            }
            LastLocalizedLanguage = LocalizationManager.CurrentLanguage;

            if (!HasTargetCache() && !FindTarget())
            {
                return;
            }

            // These are the terms actually used (will be mTerm/mSecondaryTerm or will get them from the objects if those are missing. e.g. Labels' text and font name)
            if (string.IsNullOrEmpty(FinalTerm) || string.IsNullOrEmpty(FinalSecondaryTerm))
            {
                GetFinalTerms(out FinalTerm, out FinalSecondaryTerm);
            }


            bool hasCallback = LocalizationManager.IsPlaying() && LocalizeCallBack.HasCallback();

            if (!hasCallback && string.IsNullOrEmpty(FinalTerm) && string.IsNullOrEmpty(FinalSecondaryTerm))
            {
                return;
            }

            CallBackTerm          = FinalTerm;
            CallBackSecondaryTerm = FinalSecondaryTerm;
            MainTranslation       = string.IsNullOrEmpty(FinalTerm) || FinalTerm == "-" ? null : LocalizationManager.GetTranslation(FinalTerm, false);
            SecondaryTranslation  = string.IsNullOrEmpty(FinalSecondaryTerm) || FinalSecondaryTerm == "-" ? null : LocalizationManager.GetTranslation(FinalSecondaryTerm, false);

            if (!hasCallback && /*string.IsNullOrEmpty (MainTranslation)*/ string.IsNullOrEmpty(FinalTerm) && string.IsNullOrEmpty(SecondaryTranslation))
            {
                return;
            }

            CurrentLocalizeComponent = this;
            if (LocalizationManager.IsPlaying())
            {
                LocalizeCallBack.Execute(this);                   // This allows scripts to modify the translations :  e.g. "Player {0} wins"  ->  "Player Red wins"
                LocalizationManager.ApplyLocalizationParams(ref MainTranslation, gameObject);
            }
            bool applyRTL = LocalizationManager.IsRight2Left && !IgnoreRTL;

            if (applyRTL)
            {
                if (mLocalizeTarget.AllowMainTermToBeRTL() && !string.IsNullOrEmpty(MainTranslation))
                {
                    MainTranslation = LocalizationManager.ApplyRTLfix(MainTranslation, MaxCharactersInRTL, IgnoreNumbersInRTL);
                }
                if (mLocalizeTarget.AllowSecondTermToBeRTL() && !string.IsNullOrEmpty(SecondaryTranslation))
                {
                    SecondaryTranslation = LocalizationManager.ApplyRTLfix(SecondaryTranslation);
                }
            }

            if (PrimaryTermModifier != TermModification.DontModify)
            {
                MainTranslation = MainTranslation ?? string.Empty;
            }

            switch (PrimaryTermModifier)
            {
            case TermModification.ToUpper: MainTranslation = MainTranslation.ToUpper(); break;

            case TermModification.ToLower: MainTranslation = MainTranslation.ToLower(); break;

            case TermModification.ToUpperFirst: MainTranslation = GoogleTranslation.UppercaseFirst(MainTranslation); break;

            case TermModification.ToTitle: MainTranslation = GoogleTranslation.TitleCase(MainTranslation); break;
            }

            if (SecondaryTermModifier != TermModification.DontModify)
            {
                SecondaryTranslation = SecondaryTranslation ?? string.Empty;
            }

            switch (SecondaryTermModifier)
            {
            case TermModification.ToUpper: SecondaryTranslation = SecondaryTranslation.ToUpper();  break;

            case TermModification.ToLower: SecondaryTranslation = SecondaryTranslation.ToLower();  break;

            case TermModification.ToUpperFirst: SecondaryTranslation = GoogleTranslation.UppercaseFirst(SecondaryTranslation); break;

            case TermModification.ToTitle: SecondaryTranslation = GoogleTranslation.TitleCase(SecondaryTranslation); break;
            }
            if (!string.IsNullOrEmpty(TermPrefix))
            {
                MainTranslation = applyRTL ? MainTranslation + TermPrefix : TermPrefix + MainTranslation;
            }
            if (!string.IsNullOrEmpty(TermSuffix))
            {
                MainTranslation = applyRTL ? TermSuffix + MainTranslation : MainTranslation + TermSuffix;
            }

            if (AddSpacesToJoinedLanguages && LocalizationManager.HasJoinedWords && !string.IsNullOrEmpty(MainTranslation))
            {
                var sb = new System.Text.StringBuilder();
                sb.Append(MainTranslation[0]);
                for (int i = 1, imax = MainTranslation.Length; i < imax; ++i)
                {
                    sb.Append(' ');
                    sb.Append(MainTranslation[i]);
                }

                MainTranslation = sb.ToString();
            }
            mLocalizeTarget.DoLocalize(this, MainTranslation, SecondaryTranslation);

            CurrentLocalizeComponent = null;
        }