Beispiel #1
0
 public void Execute(UnityEngine.Object Sender = null)
 {
     if (HasCallback() && LocalizationManager.IsPlaying())
     {
         Target.gameObject.SendMessage(MethodName, Sender, SendMessageOptions.DontRequireReceiver);
     }
 }
        public void Import_Google_FromCache()
        {
            if (GoogleUpdateFrequency == eGoogleUpdateFrequency.Never)
            {
                return;
            }

            if (!LocalizationManager.IsPlaying())
            {
                return;
            }

            string PlayerPrefName = GetSourcePlayerPrefName();
            string I2SavedData    = PersistentStorage.Load("I2Source_" + PlayerPrefName);

            if (string.IsNullOrEmpty(I2SavedData))
            {
                return;
            }

            if (I2SavedData.StartsWith("[i2e]", StringComparison.Ordinal))
            {
                I2SavedData = StringObfucator.Decode(I2SavedData.Substring(5, I2SavedData.Length - 5));
            }

            //--[ Compare with current version ]-----
            bool   shouldUpdate            = false;
            string savedSpreadsheetVersion = Google_LastUpdatedVersion;

            if (PlayerPrefs.HasKey("I2SourceVersion_" + PlayerPrefName))
            {
                savedSpreadsheetVersion = PlayerPrefs.GetString("I2SourceVersion_" + PlayerPrefName, Google_LastUpdatedVersion);
//				Debug.Log (Google_LastUpdatedVersion + " - " + savedSpreadsheetVersion);
                shouldUpdate = IsNewerVersion(Google_LastUpdatedVersion, savedSpreadsheetVersion);
            }

            if (!shouldUpdate)
            {
                PersistentStorage.Delete("I2Source_" + PlayerPrefName);
                PlayerPrefs.DeleteKey("I2SourceVersion_" + PlayerPrefName);
                return;
            }

            if (savedSpreadsheetVersion.Length > 19)             // Check for corruption from previous versions
            {
                savedSpreadsheetVersion = string.Empty;
            }
            Google_LastUpdatedVersion = savedSpreadsheetVersion;

            //Debug.Log ("[I2Loc] Using Saved (PlayerPref) data in 'I2Source_"+PlayerPrefName+"'" );
            Import_Google_Result(I2SavedData, eSpreadsheetUpdateMode.Replace);
        }
        void FillValues()
        {
            var _Dropdown = GetComponent <Dropdown>();

            if (_Dropdown == null && LocalizationManager.IsPlaying())
            {
                #if TextMeshPro
                FillValuesTMPro();
                #endif
                return;
            }

            foreach (var term in _Dropdown.options)
            {
                _Terms.Add(term.text);
            }
        }
Beispiel #4
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;
        }