public void SetThreadLanguageAutomatic() { var context = HttpManager.CurrentContext; // No cookies, no accept languages, with default language context.RemoveCookie(LocaleUtils.LanguageKey); Assert.IsTrue(LocaleUtils.SetThreadLanguageAutomatic(false, "zh-CN")); Assert.Equals(CultureInfo.CurrentCulture.Name, "zh-CN"); Assert.Equals(CultureInfo.CurrentUICulture.Name, "zh-CN"); Assert.IsTrue(LocaleUtils.SetThreadLanguageAutomatic(false, "en-US")); Assert.Equals(CultureInfo.CurrentCulture.Name, "en-US"); Assert.Equals(CultureInfo.CurrentUICulture.Name, "en-US"); // No cookies, have accept languages but not using, no default language using (HttpManager.OverrideContext("", "GET")) { var request = (HttpRequestMock)HttpManager.CurrentContext.Request; request.headers["Accept-Language"] = "NotExist,zh-CN;q=0.7"; Assert.IsTrue(!LocaleUtils.SetThreadLanguageAutomatic(false, null)); Assert.Equals(CultureInfo.CurrentCulture.Name, "en-US"); Assert.Equals(CultureInfo.CurrentUICulture.Name, "en-US"); } // No cookies, have accept languages and it can be used, no default language using (HttpManager.OverrideContext("", "GET")) { var request = (HttpRequestMock)HttpManager.CurrentContext.Request; request.headers["Accept-Language"] = "NotExist,zh-CN;q=0.7"; Assert.IsTrue(LocaleUtils.SetThreadLanguageAutomatic(true, null)); Assert.Equals(CultureInfo.CurrentCulture.Name, "zh-CN"); Assert.Equals(CultureInfo.CurrentUICulture.Name, "zh-CN"); } // Have cookies, no accept languages, no default language context.PutCookie(LocaleUtils.LanguageKey, "en-US"); Assert.IsTrue(LocaleUtils.SetThreadLanguageAutomatic(false, null)); Assert.Equals(CultureInfo.CurrentCulture.Name, "en-US"); Assert.Equals(CultureInfo.CurrentUICulture.Name, "en-US"); }
public void Render() { LocaleUtils.SetThreadLanguage("zh-CN"); Assert.Equals(Template.Parse("{% html_lang %}").Render(), "zh-CN"); LocaleUtils.SetThreadLanguage("en-US"); Assert.Equals(Template.Parse("{% html_lang %}").Render(), "en-US"); }
private void GisConnectionsForm_Load(object sender, System.EventArgs e) { LocaleUtils.Localize(this); LoadData(); MinimumSize = Size; UpdateControls(); }
public static string GetDetailedName(Entity marketItem) { GarageItem item = GarageItemsRegistry.GetItem <GarageItem>(marketItem); string savedLocaleCode = LocaleUtils.GetSavedLocaleCode(); return(!"ru".Equals(savedLocaleCode) ? (Instance.GetGarageItemName(item) + " " + Instance.GetCategoryName(marketItem)) : (Instance.GetCategoryName(marketItem) + " " + Instance.GetGarageItemName(item))); }
public void All() { var cache = new IsolatedKeyValueCache <string, string>( new[] { new CacheIsolateByLocale() }, new MemoryCache <IsolatedCacheKey <string>, string>()); // Set LocaleUtils.SetThreadLanguage("zh-CN"); cache.Put("Key", "ValueForCN", TimeSpan.FromSeconds(5)); LocaleUtils.SetThreadLanguage("en-US"); cache.Put("Key", "ValueForUS", TimeSpan.FromSeconds(5)); // Get LocaleUtils.SetThreadLanguage("zh-CN"); Assert.Equals(cache.GetOrDefault("Key"), "ValueForCN"); LocaleUtils.SetThreadLanguage("en-US"); Assert.Equals(cache.GetOrDefault("Key"), "ValueForUS"); // Remove LocaleUtils.SetThreadLanguage("zh-CN"); cache.Remove("Key"); Assert.Equals(cache.GetOrDefault("Key"), null); LocaleUtils.SetThreadLanguage("en-US"); Assert.Equals(cache.GetOrDefault("Key"), "ValueForUS"); cache.Remove("Key"); Assert.Equals(cache.GetOrDefault("Key"), null); }
public void ToClientTimeString() { HttpManager.CurrentContext.RemoveData(LocaleUtils.TimeZoneKey); Assert.IsTrue(LocaleUtils.SetThreadTimezone("Asia/Shanghai")); var time = new DateTime(2000, 1, 2, 13, 14, 50, DateTimeKind.Utc); var timeString = time.ToClientTimeString(); Assert.Equals(timeString, "2000/01/02 21:14:50"); }
/// <summary> /// 处理请求 /// </summary> public void OnRequest() { var configManager = Application.Ioc.Resolve <GenericConfigManager>(); var localeSettings = configManager.GetData <LocaleSettings>(); LocaleUtils.SetThreadLanguageAutomatic( localeSettings.AllowDetectLanguageFromBrowser, localeSettings.DefaultLanguage); LocaleUtils.SetThreadTimezoneAutomatic(localeSettings.DefaultTimezone); }
void SetRegionOption(RegionUtils.Provider provider) { EnvironmentInfo environmentInfo = LocaleUtils.GetEnvironmentInfo(); environmentInfo.provider = provider; environmentInfo.cloudEnvironment = CloudEnvironment.Production; Dispatcher.Dispatch(SetLoginSettingActions <EnvironmentInfo> .From(environmentInfo)); SetActiveRegionPopup(false); }
public void InitLocaleItem(ListItemSelectedEvent e, LocaleItemNode node, [JoinByScreen] SelectedLocaleNode selected, LocaleItemNode nodeA, [JoinByScreen] SingleNode <SelectLocaleScreenComponent> screen) { selected.selectedLocale.Code = node.locale.Code; if (node.locale.Code == LocaleUtils.GetSavedLocaleCode()) { screen.component.DisableButtons(); } else { screen.component.EnableButtons(); } }
public void OnAddCustomText(NodeAddedEvent e, SingleNode <CustomDiscountTextComponent> customDiscountText, SingleNode <CustomDiscountUIComponent> customDiscountUI, [JoinAll] Optional <SaleNode> sale, [JoinAll] Optional <SingleNode <SteamComponent> > steam) { if (sale.IsPresent() && sale.Get().activePaymentSale.Personal) { customDiscountUI.component.description.text = string.Empty; } else { string str = customDiscountText.component.Get(LocaleUtils.GetSavedLocaleCode(), steam.IsPresent()); customDiscountUI.component.description.text = str; } }
public void InitSelectedLocaleItem(NodeAddedEvent e, LocaleItemNode node, [Context, JoinByScreen] SelectedLocaleNode selected, [Context, JoinByScreen] LocaleListNode localesList) { LocaleComponent locale = node.locale; node.localeItem.SetText(locale.Caption, locale.LocalizedCaption); string savedLocaleCode = LocaleUtils.GetSavedLocaleCode(); if (locale.Code == savedLocaleCode) { this.SetLocaleText(selected, node.locale); localesList.simpleHorizontalList.Select(node.Entity); } }
private void GisConnectionForm_Load(object sender, System.EventArgs e) { LocaleUtils.Localize(this); tbName.Text = gisConnection.Name; tbConnStr.Text = gisConnection.ConnectionString; InitDataProviderList(); cbDataProvider.Text = gisConnection.ProviderName; tbOptions.Text = gisConnection.Options; formLoaded = true; UpdateControls(); MinimumSize = Size; MaximumSize = new Size(GConfig.Instance.geometry.maxFormWidth, Size.Height); }
public void ByLocale() { var policy = Application.Ioc.Resolve <ICacheIsolationPolicy>(serviceKey: "Locale"); LocaleUtils.SetThreadLanguage("zh-CN"); LocaleUtils.SetThreadTimezoneAutomatic("China Standard Time"); Assert.Equals(policy.GetIsolationKey(), Pair.Create( "zh-CN", LocaleUtils.GetTimezoneInfo("China Standard Time"))); LocaleUtils.SetThreadLanguage("en-US"); LocaleUtils.SetThreadTimezoneAutomatic("GMT Standard Time"); Assert.Equals(policy.GetIsolationKey(), Pair.Create( "en-US", LocaleUtils.GetTimezoneInfo("GMT Standard Time"))); }
public void SerializeT() { using (Application.OverrideIoc()) { Application.Ioc.Unregister <ITranslateProvider>(); Application.Ioc.Unregister <TranslateManager>(); Application.Ioc.RegisterMany <TranslateManagerTest.TestTranslateProviderCN>(); Application.Ioc.RegisterMany <TranslateManager>(ReuseType.Singleton); LocaleUtils.SetThreadLanguage("zh-CN"); var obj = new { field = new T("Original") }; var json = JsonConvert.SerializeObject(obj); Assert.Equals(json, "{\"field\":\"TranslatedCN\"}"); } }
public void DeserializeT() { using (Application.OverrideIoc()) { Application.Ioc.Unregister <ITranslateProvider>(); Application.Ioc.Unregister <TranslateManager>(); Application.Ioc.RegisterMany <TranslateManagerTest.TestTranslateProviderCN>(); Application.Ioc.RegisterMany <TranslateManager>(ReuseType.Singleton); LocaleUtils.SetThreadLanguage("zh-CN"); var json = "\"Original\""; var t = JsonConvert.DeserializeObject <T>(json); Assert.Equals(t.ToString(), "TranslatedCN"); } }
public void SetThreadLanguage() { Assert.IsTrue(LocaleUtils.SetThreadLanguage("zh-CN")); Assert.Equals(CultureInfo.CurrentCulture.Name, "zh-CN"); Assert.Equals(CultureInfo.CurrentUICulture.Name, "zh-CN"); Assert.IsTrue(LocaleUtils.SetThreadLanguage("en-US")); Assert.Equals(CultureInfo.CurrentCulture.Name, "en-US"); Assert.Equals(CultureInfo.CurrentUICulture.Name, "en-US"); Assert.IsTrue(!LocaleUtils.SetThreadLanguage(null)); Assert.IsTrue(!LocaleUtils.SetThreadLanguage("NotExist")); Assert.Equals(CultureInfo.CurrentCulture.Name, "en-US"); Assert.Equals(CultureInfo.CurrentUICulture.Name, "en-US"); }
public void ToClientTime() { HttpManager.CurrentContext.RemoveData(LocaleUtils.TimeZoneKey); var time = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); Assert.Equals(time.ToClientTime(), time.ToLocalTime()); Assert.IsTrue(LocaleUtils.SetThreadTimezone("China Standard Time")); var localTime = time.ToClientTime(); Assert.Equals(localTime, new DateTime(2000, 1, 1, 8, 0, 0, DateTimeKind.Local)); Assert.IsTrue(LocaleUtils.SetThreadTimezone("GMT Standard Time")); localTime = time.ToClientTime(); Assert.Equals(localTime, new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local)); }
void OnCloudOKButtonClicked() { SetActiveCloudPopup(false); var optionItemButton = m_CloudButtons.FirstOrDefault(e => e.selected); if (optionItemButton == null) { return; } // if set to Default, remove player pref if (optionItemButton.cloudOption == CloudOption.Default) { Dispatcher.Dispatch(DeleteCloudEnvironmentSetting <EnvironmentInfo> .From(true)); Dispatcher.Dispatch(DeleteCloudEnvironmentSetting <EnvironmentInfo> .From(false)); return; } EnvironmentInfo environmentInfo = LocaleUtils.GetEnvironmentInfo(); environmentInfo.cloudEnvironment = CloudEnvironment.Production; switch (optionItemButton.cloudOption) { case CloudOption.Production: environmentInfo.cloudEnvironment = CloudEnvironment.Production; break; case CloudOption.Local: environmentInfo.cloudEnvironment = CloudEnvironment.Local; break; case CloudOption.Staging: environmentInfo.cloudEnvironment = CloudEnvironment.Staging; break; case CloudOption.Test: environmentInfo.cloudEnvironment = CloudEnvironment.Test; break; case CloudOption.Other: environmentInfo.cloudEnvironment = CloudEnvironment.Other; break; } environmentInfo.customUrl = m_CloudURLInput.text; Dispatcher.Dispatch(SetLoginSettingActions <EnvironmentInfo> .From(environmentInfo)); }
public void FromClientTime() { HttpManager.CurrentContext.RemoveData(LocaleUtils.TimeZoneKey); var time = new DateTime(2000, 1, 1, 8, 0, 0, DateTimeKind.Local); Assert.Equals(time.FromClientTime(), time.ToUniversalTime()); Assert.IsTrue(LocaleUtils.SetThreadTimezone("Asia/Shanghai")); var utcTime = time.FromClientTime(); Assert.Equals(utcTime, new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc)); Assert.IsTrue(LocaleUtils.SetThreadTimezone("Etc/GMT")); utcTime = time.FromClientTime(); Assert.Equals(utcTime, new DateTime(2000, 1, 1, 8, 0, 0, DateTimeKind.Utc)); }
public void SetThreadTimezone() { Assert.IsTrue(LocaleUtils.SetThreadTimezone("China Standard Time")); var time = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); var localTime = time.ToClientTime(); Assert.Equals(localTime, new DateTime(2000, 1, 1, 8, 0, 0, DateTimeKind.Local)); Assert.IsTrue(LocaleUtils.SetThreadTimezone("GMT Standard Time")); localTime = time.ToClientTime(); Assert.Equals(localTime, new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local)); Assert.IsTrue(!LocaleUtils.SetThreadTimezone(null)); Assert.IsTrue(!LocaleUtils.SetThreadTimezone("NotExist")); localTime = time.ToClientTime(); Assert.Equals(localTime, new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local)); }
/// <summary> /// 根据传入的Http头设置语言和时区 /// </summary> public void OnRequest() { var request = HttpManager.CurrentContext.Request; var language = request.GetHeader(LanguageHeader); var timezone = request.GetHeader(TimezoneHeader); if (!string.IsNullOrEmpty(language)) { LocaleUtils.SetThreadLanguage(language); } if (!string.IsNullOrEmpty(timezone)) { LocaleUtils.SetThreadTimezone(timezone); } }
public static void TrackViewerLoaded(string userId, string sessionId = "") { var payload = new EventDataWithEmptyParams { eventName = "reflectViewerLoaded", userID = userId, sessionID = sessionId, deviceUniqueIdentifier = SystemInfo.deviceUniqueIdentifier, cloudProvider = LocaleUtils.GetProvider().ToString(), platform = Application.platform.ToString(), viewerVersion = Application.version, reflectVersion = Assembly.GetAssembly(typeof(UnityProject)).GetName().Version.ToString(), }; SendEvent(payload); }
public static CaseType GetCase(int count) { string twoLetterISOLanguageName = LocaleUtils.GetCulture().TwoLetterISOLanguageName; if (twoLetterISOLanguageName != null) { if (twoLetterISOLanguageName == "ru") { return(GetRUCase(count)); } if (twoLetterISOLanguageName == "en") { return(GetENCase(count)); } } return(CaseType.DEFAULT); }
public void Translate() { using (Application.OverrideIoc()) { Application.Ioc.Unregister <ITranslateProvider>(); Application.Ioc.Unregister <TranslateManager>(); Application.Ioc.RegisterMany <TestTranslateProviderCN>(); Application.Ioc.RegisterMany <TestTranslateProviderUS>(); Application.Ioc.RegisterMany <TranslateManager>(ReuseType.Singleton); var translateManager = Application.Ioc.Resolve <TranslateManager>(); Assert.Equals(translateManager.Translate("Original", "zh-CN"), "TranslatedCN"); Assert.Equals(translateManager.Translate("Original", "en-US"), "TranslatedUS"); LocaleUtils.SetThreadLanguage("zh-CN"); Assert.Equals(translateManager.Translate("Original"), "TranslatedCN"); LocaleUtils.SetThreadLanguage("en-US"); Assert.Equals(translateManager.Translate("Original"), "TranslatedUS"); } }
public void TrackEvent(string userId, string eventName, string sessionId = "") { var payload = new EventData <EventParam> { eventName = eventName, userID = userId, sessionID = sessionId, eventParams = new EventParam { deviceUniqueIdentifier = SystemInfo.deviceUniqueIdentifier, cloudProvider = LocaleUtils.GetProvider().ToString(), platform = Application.platform.ToString(), viewerVersion = Application.version, reflectVersion = Assembly.GetAssembly(typeof(UnityProject)).GetName().Version.ToString() } }; SendEvent(payload); }
public void TrackUserLicence(string userId, bool isFloating, string licenceType, string sessionId = "") { var payload = new EventData <EventLicence>() { eventName = "reflectUserLicenceUsed", userID = userId, sessionID = sessionId, eventParams = new EventLicence() { isFloating = isFloating, licenceType = licenceType, deviceUniqueIdentifier = SystemInfo.deviceUniqueIdentifier, cloudProvider = LocaleUtils.GetProvider().ToString(), platform = Application.platform.ToString(), viewerVersion = Application.version, reflectVersion = Assembly.GetAssembly(typeof(UnityProject)).GetName().Version.ToString(), } }; SendEvent(payload); }
public void SetThreadTimezoneAutomatic() { var context = HttpManager.CurrentContext; // No cookies, with default timezone context.RemoveCookie(LocaleUtils.TimeZoneKey); LocaleUtils.SetThreadTimezoneAutomatic("China Standard Time"); var timezone = context.GetData <TimeZoneInfo>(LocaleUtils.TimeZoneKey); Assert.Equals(timezone.StandardName, "China Standard Time"); LocaleUtils.SetThreadTimezoneAutomatic("GMT Standard Time"); timezone = context.GetData <TimeZoneInfo>(LocaleUtils.TimeZoneKey); Assert.Equals(timezone.StandardName, "GMT Standard Time"); // No cookies, no default timezone Assert.IsTrue(!LocaleUtils.SetThreadTimezoneAutomatic(null)); timezone = context.GetData <TimeZoneInfo>(LocaleUtils.TimeZoneKey); Assert.Equals(timezone.StandardName, "GMT Standard Time"); // Have cookies, no default timezone context.PutCookie(LocaleUtils.TimeZoneKey, "China Standard Time", new HttpCookieOptions()); Assert.IsTrue(LocaleUtils.SetThreadTimezoneAutomatic(null)); timezone = context.GetData <TimeZoneInfo>(LocaleUtils.TimeZoneKey); Assert.Equals(timezone.StandardName, "China Standard Time"); }
public void Awake() { m_exceptionExtraInfo.deviceUniqueIdentifier = SystemInfo.deviceUniqueIdentifier; m_exceptionExtraInfo.cloudProvider = LocaleUtils.GetProvider().ToString(); m_exceptionExtraInfo.platform = Application.platform.ToString(); m_exceptionExtraInfo.viewerVersion = Application.version; m_exceptionExtraInfo.reflectVersion = Assembly.GetAssembly(typeof(UnityProject)).GetName().Version.ToString(); if (string.IsNullOrEmpty(m_exceptionExtraInfo.EnvTrace)) { m_exceptionExtraInfo.userId = unsetConstant; } if (string.IsNullOrEmpty(m_exceptionExtraInfo.EnvTrace)) { m_exceptionExtraInfo.reflectUpid = unsetConstant; } if (string.IsNullOrEmpty(m_exceptionExtraInfo.EnvTrace)) { m_exceptionExtraInfo.EnvTrace = unsetConstant; } onExceptionExtraInfoChanged?.Invoke(JsonUtility.ToJson(m_exceptionExtraInfo)); UIStateManager.projectStateChanged += CheckActiveProject; }
public void Awake() { m_exceptionExtraInfo.deviceUniqueIdentifier = SystemInfo.deviceUniqueIdentifier; m_exceptionExtraInfo.cloudProvider = LocaleUtils.GetProvider().ToString(); m_exceptionExtraInfo.platform = Application.platform.ToString(); m_exceptionExtraInfo.viewerVersion = Application.version; m_exceptionExtraInfo.reflectVersion = Assembly.GetAssembly(typeof(UnityProject)).GetName().Version.ToString(); if (string.IsNullOrEmpty(m_exceptionExtraInfo.EnvTrace)) { m_exceptionExtraInfo.userId = unsetConstant; } if (string.IsNullOrEmpty(m_exceptionExtraInfo.EnvTrace)) { m_exceptionExtraInfo.reflectUpid = unsetConstant; } if (string.IsNullOrEmpty(m_exceptionExtraInfo.EnvTrace)) { m_exceptionExtraInfo.EnvTrace = unsetConstant; } onExceptionExtraInfoChanged?.Invoke(JsonUtility.ToJson(m_exceptionExtraInfo)); m_ActiveProjectSelector = UISelectorFactory.createSelector <Project>(ProjectManagementContext <Project> .current, nameof(IProjectDataProvider <Project> .activeProject), OnActiveProjectChanged); }
void OnSessionStateDataChanged(UISessionStateData data) { if (m_LoginState != data.sessionState.loggedState) { switch (data.sessionState.loggedState) { case LoginState.LoggedIn: m_NoProjectPanel.SetActive(false); m_FetchingProjectsPanel.SetActive(true); break; case LoginState.LoggedOut: ClearProjectListItem(); m_NoProjectPanel.SetActive(false); m_FetchingProjectsPanel.SetActive(false); break; case LoginState.LoggingIn: case LoginState.LoggingOut: // todo put spinner break; } m_LoginState = data.sessionState.loggedState; } if (m_LoginState == LoginState.LoggedIn) { // Display Cloud environment debug info when it's not "Production" var environmentInfo = LocaleUtils.GetEnvironmentInfo(); if (environmentInfo.cloudEnvironment != CloudEnvironment.Production) { m_CloudSettingDebugInfo.gameObject.SetActive(true); if (environmentInfo.cloudEnvironment == CloudEnvironment.Other) { if (PlayerPrefs.HasKey(LocaleUtils.SettingsKeys.CloudEnvironment)) { m_CloudSettingDebugInfo.text = $"Environment: {environmentInfo.customUrl}"; } else { m_CloudSettingDebugInfo.text = $"Environment: {ProjectServerClient.ProjectServerAddress(environmentInfo.provider)}"; } } else { m_CloudSettingDebugInfo.text = $"Environment: {environmentInfo.cloudEnvironment}"; } } else { m_CloudSettingDebugInfo.gameObject.SetActive(false); } UpdateProjectItems(data.sessionState.rooms); if (m_Rooms != data.sessionState.rooms || !EnumerableExtension.SafeSequenceEquals(m_Rooms, data.sessionState.rooms)) { m_Rooms = data.sessionState.rooms; } else if (HasNoProjectsAvailable()) { m_NoProjectPanel.SetActive(true); m_FetchingProjectsPanel.SetActive(false); } } }