internal static void AddSource(LanguageSource Source) { if (Sources.Contains(Source)) { return; } Sources.Add(Source); #if !UNITY_EDITOR || I2LOC_AUTOSYNC_IN_EDITOR if (Source.HasGoogleSpreadsheet() && Source.GoogleUpdateFrequency != LanguageSource.eGoogleUpdateFrequency.Never) { Source.Import_Google_FromCache(); if (Source.GoogleUpdateDelay > 0) { CoroutineManager.Start(Delayed_Import_Google(Source, Source.GoogleUpdateDelay)); } else { Source.Import_Google(); } } #endif if (Source.mDictionary.Count == 0) { Source.UpdateDictionary(true); } }
public void Import_Google(bool ForceUpdate = false) { if (!ForceUpdate && GoogleUpdateFrequency == eGoogleUpdateFrequency.Never) { return; } #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) { return; } #endif string PlayerPrefName = GetSourcePlayerPrefName(); if (!ForceUpdate && GoogleUpdateFrequency != eGoogleUpdateFrequency.Always) { string sTimeOfLastUpdate = PlayerPrefs.GetString("LastGoogleUpdate_" + PlayerPrefName, ""); DateTime TimeOfLastUpdate; try { if (DateTime.TryParse(sTimeOfLastUpdate, out TimeOfLastUpdate)) { double TimeDifference = (DateTime.Now - TimeOfLastUpdate).TotalDays; switch (GoogleUpdateFrequency) { case eGoogleUpdateFrequency.Daily: if (TimeDifference < 1) { return; } break; case eGoogleUpdateFrequency.Weekly: if (TimeDifference < 8) { return; } break; case eGoogleUpdateFrequency.Monthly: if (TimeDifference < 31) { return; } break; case eGoogleUpdateFrequency.OnlyOnce: return; } } } catch (Exception) { } } PlayerPrefs.SetString("LastGoogleUpdate_" + PlayerPrefName, DateTime.Now.ToString()); //--[ Checking google for updated data ]----------------- CoroutineManager.Start(Import_Google_Coroutine()); }
public static void LocalizeAll(bool Force = false) { if (!Application.isPlaying) { DoLocalizeAll(Force); return; } mLocalizeIsScheduledWithForcedValue |= Force; if (!mLocalizeIsScheduled) { CoroutineManager.Start(Coroutine_LocalizeAll()); } }
internal static void AddSource(LanguageSourceData Source) { if (Sources.Contains(Source)) { return; } Sources.Add(Source); if (Source.HasGoogleSpreadsheet() && Source.GoogleUpdateFrequency != LanguageSourceData.eGoogleUpdateFrequency.Never && LocalizationManager.AllowSyncFromGoogle(Source)) { #if !UNITY_EDITOR Source.Import_Google_FromCache(); bool justCheck = false; #else bool justCheck = true; #endif if (Source.GoogleUpdateDelay > 0) { CoroutineManager.Start(Delayed_Import_Google(Source, Source.GoogleUpdateDelay, justCheck)); } else { Source.Import_Google(false, justCheck); } } //if (force) { for (int i = 0; i < Source.mLanguages.Count(); ++i) { Source.mLanguages[i].SetLoaded(true); } } if (Source.mDictionary.Count == 0) { Source.UpdateDictionary(true); } }
// When JustCheck is true, importing from google will not download any data, just detect if the Spreadsheet is up-to-date public void Import_Google(bool ForceUpdate, bool justCheck) { if (!ForceUpdate && GoogleUpdateFrequency == eGoogleUpdateFrequency.Never) { return; } if (!I2Utils.IsPlaying()) { return; } #if UNITY_EDITOR if (justCheck && GoogleInEditorCheckFrequency == eGoogleUpdateFrequency.Never) { return; } #endif #if UNITY_EDITOR var updateFrequency = GoogleInEditorCheckFrequency; #else var updateFrequency = GoogleUpdateFrequency; #endif string PlayerPrefName = GetSourcePlayerPrefName(); if (!ForceUpdate && updateFrequency != eGoogleUpdateFrequency.Always) { #if UNITY_EDITOR string sTimeOfLastUpdate = UnityEditor.EditorPrefs.GetString("LastGoogleUpdate_" + PlayerPrefName, ""); #else string sTimeOfLastUpdate = PersistentStorage.GetSetting_String("LastGoogleUpdate_" + PlayerPrefName, ""); #endif DateTime TimeOfLastUpdate; try { if (DateTime.TryParse(sTimeOfLastUpdate, out TimeOfLastUpdate)) { double TimeDifference = (DateTime.Now - TimeOfLastUpdate).TotalDays; switch (updateFrequency) { case eGoogleUpdateFrequency.Daily: if (TimeDifference < 1) { return; } break; case eGoogleUpdateFrequency.Weekly: if (TimeDifference < 8) { return; } break; case eGoogleUpdateFrequency.Monthly: if (TimeDifference < 31) { return; } break; case eGoogleUpdateFrequency.OnlyOnce: return; } } } catch (Exception) { } } #if UNITY_EDITOR UnityEditor.EditorPrefs.SetString("LastGoogleUpdate_" + PlayerPrefName, DateTime.Now.ToString()); #else PersistentStorage.SetSetting_String("LastGoogleUpdate_" + PlayerPrefName, DateTime.Now.ToString()); #endif //--[ Checking google for updated data ]----------------- CoroutineManager.Start(Import_Google_Coroutine(justCheck)); }