public string GetText(string resourceName, string uiCultureTab = null, params Object[] list) { var rc = "[not found]"; try { if (SupportedCultures != null) { if (_rm == null) { var baseName = GetResourcesAsm().GetName().Name + ".Properties.Resources"; _rm = new ResourceManager(baseName, GetResourcesAsm()); } var cookies = new MxCookies(HttpContextAccessor); if (SupportedCultures.IsSupported(uiCultureTab) == false) { uiCultureTab = SupportedCultures.GetUiCultureTab(cookies.GetValue(MxSupportedCultures.CookieName)); } var uiCultureInfo = SupportedCultures.GetCultureInfo(uiCultureTab); if (uiCultureInfo != null) { var res = _rm?.GetString(resourceName ?? "NotFound", uiCultureInfo) ?? "[Not Found]"; rc = string.Format(uiCultureInfo, res, list); } } } catch (Exception e) { // ReSharper disable once UnusedVariable var msg = e.Message; //ignore } return(rc); }
public Instant ParseTimeDate(string timeDate, bool withoutDaylightSaving = false, MxCultureInfo.FormatType formatType = MxCultureInfo.FormatType.DateTime, bool longFormat = false, string cultureTab = null) { var rc = ExtNodatime.InstantError; var cookies = new MxCookies(HttpContextAccessor); if (SupportedCultures.IsSupported(cultureTab) == false) { cultureTab = SupportedCultures.GetCultureTab(cookies.GetValue(MxSupportedCultures.CookieName)); } if (timeDate.ParseDateTime(DateTimeZoneProviders.Tzdb[SupportedTimeZones.GetTzDbName(cultureTab)], cultureTab, withoutDaylightSaving, formatType, longFormat, out var result)) { rc = result; } return(rc); }
public string InstantToString(Instant timeInstant, string cultureTab = null, bool withoutDaylightSaving = false, MxCultureInfo.FormatType formatType = MxCultureInfo.FormatType.DateTime, bool longFormat = false) { var rc = "[error]"; try { var cookies = new MxCookies(HttpContextAccessor); if (SupportedCultures.IsSupported(cultureTab) == false) { cultureTab = SupportedCultures.GetCultureTab(cookies.GetValue(MxSupportedCultures.CookieName)); } rc = timeInstant.ToString(cultureTab, DateTimeZoneProviders.Tzdb[SupportedTimeZones.GetTzDbName(cultureTab)]); } catch (Exception) { //ignore } return(rc); }
public bool SetCurrentCulture(string cultureTab = null, string uiCultureTab = null) { var rc = false; try { if (SupportedCultures.IsSupported(cultureTab)) { Thread.CurrentThread.CurrentCulture = SupportedCultures.GetCultureInfo(cultureTab); } if (SupportedCultures.IsSupported(uiCultureTab)) { Thread.CurrentThread.CurrentUICulture = SupportedCultures.GetCultureInfo(uiCultureTab); } rc = true; } catch (Exception) { //ignore } return(rc); }