public RouteValueTranslation TranslateToTranslatedValue(string routeValue, CultureInfo culture) { RouteValueTranslation translation = null; // Find translation in specified CultureInfo translation = this.Translations.Where( t => t.RouteValue == routeValue && (t.Culture.ToString() == culture.ToString() || t.Culture.ToString().Substring(0, 2) == culture.ToString().Substring(0, 2))) .OrderByDescending(t => t.Culture) .FirstOrDefault(); if (translation != null) { return translation; } // Find translation without taking account on CultureInfo translation = this.Translations.Where(t => t.RouteValue == routeValue) .FirstOrDefault(); if (translation != null) { return translation; } // Return the current values return new RouteValueTranslation { Culture = culture, RouteValue = routeValue, TranslatedValue = routeValue }; }
/// <summary> /// Prints the calendar for a month and year. /// </summary> /// <param name="month">Month to print.</param> /// <param name="year">Year to specify the month.</param> /// <param name="culture">Given Culture info.</param> public static void PrintCalendar(int month, int year, CultureInfo culture) { Console.WriteLine(new CultureInfo(culture.ToString()).DateTimeFormat.GetMonthName(month)); for (int i = 0; i < 7; i++) { Console.Write(new CultureInfo(culture.ToString()).DateTimeFormat.GetDayName((DayOfWeek)i) + " "); } }
private static ResourceBase CreateResource(string resourceName, CultureInfo culture, string resourceLocation) { Func<string, string> fixResourceName = c => resourceName + ((c != null) ? "." + c : string.Empty) + ".resx"; IVirtualPathProvider vpp = ServiceLocator.Current.Resolve<IVirtualPathProvider>(); // First try the file path Resource.fr-CA.resx string fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(culture.ToString())); bool exists = vpp.FileExists(fullResourcePath); // If not found, try Resource.fr.resx if (!exists) { fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(culture.TwoLetterISOLanguageName)); exists = vpp.FileExists(fullResourcePath); } // If nothing is found try Resource.resx if (!exists) { fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(null)); exists = vpp.FileExists(fullResourcePath); } ResourceBase resource = exists ? new ResXResource(ServiceLocator.Current.Resolve<IPathResolver>().Resolve(fullResourcePath)) : new EmbeddedResource(resourceName, culture) as ResourceBase; return resource; }
public static ResourceBundle GetBundle (string bundleClass, CultureInfo culture) { Assembly asm = null; foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) { if (a.GetType (bundleClass) != null) { asm = a; break; } } if (asm == null) throw new MissingResourceException (); Stream manifestResourceStream; manifestResourceStream = asm.GetManifestResourceStream (bundleClass + "_" + culture.ToString().Replace ('-','_') + ".properties"); if (manifestResourceStream == null) manifestResourceStream = asm.GetManifestResourceStream (bundleClass + "_" + culture.TwoLetterISOLanguageName + ".properties"); if (manifestResourceStream == null) manifestResourceStream = asm.GetManifestResourceStream (bundleClass + ".properties"); if (manifestResourceStream != null) { ResourceBundle bundle = new ResourceBundle (); bundle.culture = culture; bundle.Load (manifestResourceStream); return bundle; } else throw new MissingResourceException (); }
public Region(CultureInfo culture) { DisplayName = culture.DisplayName; EnglishName = culture.EnglishName; NativeName = culture.NativeName; ShortName = culture.ToString(); }
public string LoadTemplate(string templateName, CultureInfo culture, FogBugzCase cases) { if (culture == null) culture = CultureInfo.InvariantCulture; string text = File.ReadAllText(Path.Combine("Views", culture.ToString(), templateName + ".cshtml")); return Razor.Parse(text, cases); }
/// <summary> /// Set language culture for the application. /// </summary> /// <param name="cultureInfo"><see cref="CultureInfo"/> to be set.</param> public static void SetLanguage(CultureInfo cultureInfo) { LanguageManager.cultureInfo = cultureInfo; resourceManager = new ResourceManager(string.Format("PawnPlus.Language.Languages.{0}", cultureInfo.ToString()), typeof(LanguageManager).Assembly); // Use this way because I don't want "satellite assembly" for language. Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; }
public string GetEulaText(string packageServerUrl, Guid eulaId, CultureInfo userCulture) { PackagesSoapClient client = CreateClient(packageServerUrl); string eulaText = client.GetEulaText(eulaId, userCulture.ToString()); return eulaText; }
protected override ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents) { ResourceSet rs = (ResourceSet)ResourceSets[culture]; if (rs == null) { string resourceFileName = null; //lazy-load default language (without caring about duplicate assignment in race conditions, no harm done); if (_neutralResourcesCulture == null) { _neutralResourcesCulture = GetNeutralResourcesLanguage(MainAssembly); } // if we're asking for the default language, then ask for the // invariant (non-specific) resources. if (_neutralResourcesCulture.Equals(culture)) culture = CultureInfo.InvariantCulture; resourceFileName = GetResourceFileName(culture); // Only bother to try the lookup based on the resource property if we haven't tried this language before if (!_prevCultures.Contains(culture.ToString()) && culture != CultureInfo.InvariantCulture) { _prevCultures.Add(culture.ToString()); // The T4 template resource generator will link the culture specific resources in to the invariant culture resource // We'll try and load the culture specific resource here var content = GetString("Resources." + culture); if (content != null) { using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(content))) using (var reader = new ResXResourceReader(stream)) { rs = new ResourceSet(reader); } } } if (rs == null) rs = base.InternalGetResourceSet(culture, createIfNotExists, tryParents); } return rs; }
public void SetCulture(CultureInfo culture, HttpContextBase httpContext) { var currentCulture = httpContext.Request.Cookies["CurrentCulture"]; if (currentCulture == null || currentCulture.Value != culture.ToString()) { var cookie = new HttpCookie("CurrentCulture") { Value = culture.ToString(), Expires = DateTime.Now.AddYears(30) }; httpContext.Response.Cookies.Add(cookie); } Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; }
public System.Resources.IResourceWriter GetResourceWriter(CultureInfo info) { try { LoggingService.Debug("ResourceWriter requested for culture: " + info.ToString()); return this.store.GetWriter(info); } catch (Exception e) { MessageService.ShowException(e); return null; } }
public System.Resources.IResourceReader GetResourceReader(System.Globalization.CultureInfo info) { try { LoggingService.Debug("ResourceReader requested for culture: " + info.ToString()); return(this.store.GetReader(info)); } catch (Exception e) { MessageService.ShowException(e); return(null); } }
public IEnumerable<PackageDescription> GetPackageDescriptions(string packageServerUrl, Guid installationId, CultureInfo userCulture) { List<PackageDescription> packageDescriptions = _packageServerFacadeImplCache.GetCachedPackageDescription(packageServerUrl, installationId, userCulture); if (packageDescriptions != null) return packageDescriptions; PackageDescriptor[] packageDescriptors = null; try { PackagesSoapClient client = CreateClient(packageServerUrl); packageDescriptors = client.GetPackageList(installationId, userCulture.ToString()); } catch (Exception ex) { Log.LogError("PackageServerFacade", ex); } packageDescriptions = new List<PackageDescription>(); if (packageDescriptors != null) { foreach (PackageDescriptor packageDescriptor in packageDescriptors) { if (ValidatePackageDescriptor(packageDescriptor)) { packageDescriptions.Add(new PackageDescription { PackageFileDownloadUrl = packageDescriptor.PackageFileDownloadUrl, PackageVersion = packageDescriptor.PackageVersion, Description = packageDescriptor.Description, EulaId = packageDescriptor.EulaId, GroupName = packageDescriptor.GroupName, Id = packageDescriptor.Id, InstallationRequireLicenseFileUpdate = packageDescriptor.InstallationRequireLicenseFileUpdate, IsFree = packageDescriptor.IsFree, IsTrial = packageDescriptor.IsTrial, LicenseRuleId = packageDescriptor.LicenseId, MaxCompositeVersionSupported = packageDescriptor.MaxCompositeVersionSupported, MinCompositeVersionSupported = packageDescriptor.MinCompositeVersionSupported, Name = packageDescriptor.Name, PriceAmmount = packageDescriptor.PriceAmmount, PriceCurrency = packageDescriptor.PriceCurrency, ReadMoreUrl = packageDescriptor.ReadMoreUrl, TechicalDetails = packageDescriptor.TechicalDetails, TrialPeriodDays = packageDescriptor.TrialPeriodDays, UpgradeAgreementMandatory = packageDescriptor.UpgradeAgreementMandatory, Vendor = packageDescriptor.Author }); } } _packageServerFacadeImplCache.AddCachedPackageDescription(packageServerUrl, installationId, userCulture, packageDescriptions); } return packageDescriptions; }
public Store(int version, string displayName, string storeName, string storeID, bool storeEnabled, Uri storeImage, CultureInfo storeLocale) { this.datVersion = version; this.displayName = displayName; this.storeName = storeName; this.storeID = storeID; this.storeEnabled = storeEnabled; this.storeImage = storeImage; this.storeLocale = storeLocale.ToString(); }
private string InitLanguage() { System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; string lang = ci.ToString(); if (lang.Length < 3) //create the specific culture if the neutral one was passed in request { lang = System.Globalization.CultureInfo.CreateSpecificCulture(lang).ToString(); } Session[langSessionName] = lang; return(lang); }
public void save_settings() { // Check for null values. (except profile) if (!validate_profile()) { MessageBox.Show("Cannot save profile, one or more values currently unset."); return; } try{ XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlWriter writer = XmlWriter.Create(DEFUALT_SETTINGS_FILENAME, settings); writer.WriteStartDocument(); writer.WriteStartElement("gavpi"); writer.WriteStartElement("Settings"); // Warning : can be null writer.WriteAttributeString("default_profile_name", default_profile_name); // Warning : can be null writer.WriteAttributeString("default_profile_filepath", default_profile_filepath); writer.WriteAttributeString("voice_info", voice_info); writer.WriteAttributeString("pushtotalk_mode", pushtotalk_mode); writer.WriteAttributeString("pushtotalk_key", pushtotalk_key); writer.WriteAttributeString("recognizer_info", recognizer_info.ToString()); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); } catch (Exception err_saving) { MessageBox.Show("Error saving settings to file : " + err_saving.Message); } } // public void save_settings()
static void Main(string[] args) { DateTime d = new DateTime(2002, 2, 13); // current culture System.Console.WriteLine(d.ToLongDateString()); // use IFormatProvider System.Console.WriteLine(d.ToString("D", new CultureInfo("fr-fr"))); // use culture of thread CultureInfo ci = Thread.CurrentThread.CurrentCulture; Console.WriteLine(ci.ToString() + ": " + d.ToString("D")); ci = new CultureInfo("de-de"); Thread.CurrentThread.CurrentCulture = ci; Console.WriteLine(ci.ToString() + ": " + d.ToString("D")); }
public static string getLanguage() { string strOut = string.Empty; LanguageSettings objLanguageSetting = Globals.ThisAddIn.Application.LanguageSettings; CultureInfo ci = new CultureInfo(objLanguageSetting.get_LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI)); switch (ci.ToString()) { case "zh-CN": strOut = "zh-CN"; break; case "en-US": strOut = "en-US"; break; case "ja-JP": strOut = "ja-JP"; break; case "ja": strOut = "ja"; break; case "pl": strOut = "pl"; break; case "it": strOut = "it"; break; case "ru-RU": strOut = "ru-RU"; break; case "ru": strOut = "ru"; break; case "fr": strOut = "fr"; break; case "de": strOut = "de"; break; case "es": strOut = "es"; break; default: strOut = "others"; break; } return strOut; }
public static string CultureToShortString(CultureInfo culture) { string str; switch (culture.ToString()) { case "cs-CZ": str = "cz"; break; case "en-US": str = "en"; break; default: str = "en"; break; } return str; }
public Region(string cultureString) { // Special cases, where the WP7 SDK lacks certain cultures if (cultureString.Equals("en-HK")) { DisplayName = "English (Hong Kong S.A.R.)"; EnglishName = "English (Hong Kong S.A.R.)"; NativeName = "English (Hong Kong S.A.R.)"; ShortName = "en-HK"; return; } CultureInfo culture = new CultureInfo(cultureString); DisplayName = culture.DisplayName; EnglishName = culture.EnglishName; NativeName = culture.NativeName; ShortName = culture.ToString(); }
public void ParseFormattedStandardPattern(CultureInfo culture, string patternText) { if (culture.ToString() == "af-ZA") { // Still need to handle Afrikaans having just a PM designator. return; } // Some cultures use two-digit years, so let's put them in the right century. var pattern = LocalDateTimePattern.Create(patternText, NodaFormatInfo.GetFormatInfo(culture)) .WithTemplateValue(new LocalDateTime(1400, 1, 1, 0, 0)); string formatted = pattern.Format(SampleLocalDateTime); var parseResult = pattern.Parse(formatted); Assert.IsTrue(parseResult.Success); var parsed = parseResult.Value; Assert.IsTrue(parsed == SampleLocalDateTime || parsed == SampleLocalDateTimeNoTicks || parsed == SampleLocalDateTimeNoMillis || parsed == SampleLocalDateTimeNoSeconds); }
private static void FormatData(CultureInfo ci) { // Display the selected culture. Console.WriteLine(ci.ToString() + ":"); // Identify the number and copy it to a string double d = 1234567.89; string formattedNumber = d.ToString(); // Identify the locatino of the culture-sensitive decimal point in the number int decimalIndex = formattedNumber.IndexOf(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator) + 1; // Extract only the decimal portion of the number formattedNumber = formattedNumber.Substring(decimalIndex, formattedNumber.Length - decimalIndex); // Add the culture-specific decimal point before the number formattedNumber = ci.NumberFormat.NumberDecimalSeparator + formattedNumber; // Extract only the whole portion of the number string wholeDigits = Math.Floor(d).ToString(); // Add each whole digit to formatted Number, with grouping separators for (int a = 0; a < wholeDigits.Length; a++) { // Examine CultureInfo.NumberFormat.NumberGroupSizes to determine // whether the current locatino requires a separator foreach (int sep in ci.NumberFormat.NumberGroupSizes) { if ((a > 0) && ((a % sep) == 0)) { formattedNumber = ci.NumberFormat.NumberGroupSeparator + formattedNumber; } // Add the number to the final string formattedNumber = wholeDigits.ToCharArray()[wholeDigits.Length - a - 1] + formattedNumber; } } // Display the manual results and the automatically formatted version Console.WriteLine(" Manual: {0}", formattedNumber); Console.WriteLine(" Automatic: {0}", d.ToString("N", ci)); }
/// <summary> /// Sets the culture information for the current user. The current /// culture is fetched and the default date format string for the /// culture is generated. /// </summary> private void SetupCultureInformation() { // Get the current culture mSystemCulture = CultureInfo.CurrentCulture; // Set the default date format based on the current culture switch (mSystemCulture.ToString()) { case "en-AU": mDefaultDateFormatString = "dd/MM/yyyy"; break; case "en-CA": case "en-US": mDefaultDateFormatString = "MM/dd/yyyy"; break; default: mDefaultDateFormatString = "MM/dd/yyyy"; break; } }
public System.Resources.IResourceReader GetResourceReader(System.Globalization.CultureInfo info) { try { LoggingService.Debug("ResourceReader requested for culture: " + info.ToString()); ResourceStorage resourceStorage; if (resources != null && resources.ContainsKey(info.Name)) { resourceStorage = resources[info.Name]; } else { resourceStorage = new ResourceStorage(); resources[info.Name] = resourceStorage; } return(resourceStorage.GetReader(CalcResourceFileName(FormFileName, info.Name))); } catch (Exception e) { MessageService.ShowError(e.Message); return(null); } }
/// <summary> /// Gives an instance of resource bundle. /// </summary> /// <param name="aName">Name of the bundle you are looking for (ex: CanonMarkernote)</param> /// <param name="aCulturalInfo">a cultural info. Can be null</param> /// <param name="aType">a type of bundle (See USE_MANAGER or USE_TXTFILE)</param> /// <returns>the bundle found or loade.</returns> public static IResourceBundle CreateBundle(string aName, CultureInfo aCulturalInfo, int aType) { string key = aName; if (aCulturalInfo != null) { key += "_" + aCulturalInfo.ToString(); } IResourceBundle resu = null; if (!ResourceBundleFactory.BUNDLES.ContainsKey(key)) { try { if (aType == ResourceBundleFactory.USE_MANAGER) { resu = new ResourceBundleWithManager(aName, aCulturalInfo); } else if (aType == ResourceBundleFactory.USE_TXTFILE) { resu = new ResourceBundle(aName, aCulturalInfo); } } catch (Exception e) { Trace.TraceError("Could not load bundle '" + aName + "' (" + e.Message + ")"); } if (resu == null || resu["TEST"] == null) { throw new Exception("Error while loading bundle '" + aName + "' for cultural '" + aCulturalInfo + "'"); } ResourceBundleFactory.BUNDLES.Add(key, resu); } else { resu = ResourceBundleFactory.BUNDLES[key]; } return resu; }
public static void ChangeCultureCurrentWindow(CultureInfo newCulture, MainWindow mainWindow) { Thread.CurrentThread.CurrentCulture = newCulture; Thread.CurrentThread.CurrentUICulture = newCulture; var oldWindow = Application.Current.MainWindow; MainWindow wnd = new MainWindow(); wnd = mainWindow; Application.Current.MainWindow = wnd; wnd.Show(); Application.Current.MainWindow.Show(); if (newCulture.ToString() == "ar-AE") { Application.Current.MainWindow.FlowDirection = FlowDirection.RightToLeft; } else { Application.Current.MainWindow.FlowDirection = FlowDirection.LeftToRight; } oldWindow.Close(); }
public static void ChangeCulture(CultureInfo newCulture) { newCulture.NumberFormat.DigitSubstitution = DigitShapes.None; Thread.CurrentThread.CurrentCulture = newCulture; Thread.CurrentThread.CurrentUICulture = newCulture; Thread.CurrentThread.CurrentUICulture.NumberFormat.DigitSubstitution = DigitShapes.None; var oldWindow = Application.Current.MainWindow; Application.Current.MainWindow = new MainWindow(); Application.Current.MainWindow.Show(); if (newCulture.ToString() == "ar-AE") { Application.Current.MainWindow.FlowDirection = FlowDirection.RightToLeft; } else { Application.Current.MainWindow.FlowDirection = FlowDirection.LeftToRight; } Thread.CurrentThread.CurrentCulture.NumberFormat.DigitSubstitution = DigitShapes.None; oldWindow.Close(); }
public static bool IsSupportedCulture(CultureInfo culture, out bool isParentSupported) { string child = culture.ToString(); string parent = (culture.IsNeutralCulture) ? culture.ToString() : culture.Parent.ToString(); bool childSupport = ResourceManager.Locales.Contains(child); bool parentSupport = ResourceManager.Locales.Contains(parent); isParentSupported = !childSupport && parentSupport; return (childSupport || parentSupport); }
public static int OSCompare(CultureInfo ci, string str1, int offset1, int length1, string str2, int offset2, int length2, CompareOptions options) { // The OS blows up on nulls. So should we. These are handled in managed code and should be tested as ordinal, even if the ordinal // compare option has not been selected. if (str1 == null || str2 == null) throw new NotSupportedException("Null strings should not be tested by the OS; these are managed code platform-agnostic cases."); string str1offset = str1.Substring(offset1); string str2offset = str2.Substring(offset2); if (length1 > str1offset.Length) length1 = str1offset.Length; if (length2 > str2offset.Length) length2 = str2offset.Length; int ret; if ((options & CompareOptions.Ordinal) != 0) // these flags cannot be used with other flags { if (Utilities.IsVistaOrLater) ret = CompareStringOrdinal(str1offset, length1, str2offset, length2, false); // Supported VistaOrLater else ret = GlobLocHelperCompareOrdinalForXP(str1offset, length1, str2offset, length2); } else if ((options & CompareOptions.OrdinalIgnoreCase) != 0) // these flags cannot be used with other flags { if (Utilities.IsVistaOrLater) ret = CompareStringOrdinal(str1offset, length1, str2offset, length2, true); // Supported VistaOrLater else throw new NotSupportedException("GlobLocHelper doesn't handle OrdinalIgnoreCase for earlier OSs than Vista"); } else { int nativeCompareFlags = 0; if ((options & CompareOptions.IgnoreCase) != 0) { nativeCompareFlags |= NORM_IGNORECASE; } if ((options & CompareOptions.IgnoreKanaType) != 0) { nativeCompareFlags |= NORM_IGNOREKANATYPE; } if ((options & CompareOptions.IgnoreNonSpace) != 0) { nativeCompareFlags |= NORM_IGNORENONSPACE; } if ((options & CompareOptions.IgnoreSymbols) != 0) { nativeCompareFlags |= NORM_IGNORESYMBOLS; } if ((options & CompareOptions.IgnoreWidth) != 0) { nativeCompareFlags |= NORM_IGNOREWIDTH; } if ((options & CompareOptions.StringSort) != 0) { nativeCompareFlags |= SORT_STRINGSORT; } if (Utilities.IsVistaOrLater) { // NORM_LINGUISTIC_CASING: Windows Vista and later. Uses linguistic rules for casing, rather than file system rules (the default) if (CultureInfo.InvariantCulture == ci) nativeCompareFlags |= NORM_LINGUISTIC_CASING; ret = CompareStringEx(ci.ToString(), nativeCompareFlags, str1offset, length1, str2offset, length2, (IntPtr)null, (IntPtr)null, IntPtr.Zero); } else ret = CompareStringW(LCIDFromCultureInfo(ci), nativeCompareFlags, str1offset, length1, str2offset, length2); } switch (ret) { case 0: return -5; case 1: return -1; case 2: return 0; case 3: return 1; default: return -6; } }
public static string OSToLower(string str, CultureInfo ci) { if (str.Contains("\0")) { string[] subStrs = str.Split(new char[] { '\0' }); StringBuilder sbOut = new StringBuilder(OSToLower(subStrs[0], ci)); for (int i = 1; i < subStrs.Length; i++) { sbOut.Append("\0"); sbOut.Append(OSToLower(subStrs[i], ci)); } return sbOut.ToString(); } if (string.IsNullOrEmpty(str)) return str; string output = new string(' ', str.Length); int lcid = LCIDFromCultureInfo(ci); // ci.LCID; int length = str.Length; int nativeFlags = LCMAP_LOWERCASE; if (ci != CultureInfo.InvariantCulture) nativeFlags |= LCMAP_LINGUISTIC_CASING; int retValue = 0; if (Utilities.IsVistaOrLater) retValue = LCMapStringEx(ci == null ? Utilities.CurrentCulture.ToString() : ci.ToString(), nativeFlags, str, length, output, length, (IntPtr)null, (IntPtr)null, IntPtr.Zero); else retValue = LCMapStringW(lcid, nativeFlags, str, length, output, length); if (retValue == 0) throw new InvalidOperationException("Unexpected return value from LCMapStringW/LCMapStringEx: " + retValue.ToString()); return output; }
public static string OSToUpper(string str, CultureInfo ci) { if (string.IsNullOrEmpty(str)) return str; string output = new string(' ', str.Length); int lcid = LCIDFromCultureInfo(ci); // ci.LCID; int length = str.Length; int nativeFlags = LCMAP_UPPERCASE; if (ci != CultureInfo.InvariantCulture) nativeFlags |= LCMAP_LINGUISTIC_CASING; int retValue = 0; if (Utilities.IsVistaOrLater) retValue = LCMapStringEx(ci == null ? Utilities.CurrentCulture.ToString() : ci.ToString(), nativeFlags, str, length, output, length, (IntPtr)null, (IntPtr)null, IntPtr.Zero); else retValue = LCMapStringW(lcid, nativeFlags, str, length, output, length); if (retValue == 0) throw new InvalidOperationException("Unexpected return value from LCMapStringW: " + retValue.ToString()); return output; }
public string LoadTemplate(string templateName, CultureInfo culture) { if (culture == null) culture = CultureInfo.InvariantCulture; return File.ReadAllText(Path.Combine("Views", culture.ToString(), templateName + ".cshtml")); }
/// <summary> /// Construct a /// <see cref="TranslationStringMissingException">TranslationStringMissingException</see> /// for the specified /// bundle class, locale and translation key /// </summary> /// <param name="bundleClass">the bundle class for which a translation string was missing /// </param> /// <param name="locale">the locale for which a translation string was missing</param> /// <param name="key">the key of the missing translation string</param> /// <param name="cause"> /// the original exception thrown from the /// <see cref="Sharpen.ResourceBundle.GetString(string)">Sharpen.ResourceBundle.GetString(string) /// </see> /// method. /// </param> public TranslationStringMissingException(Type bundleClass, CultureInfo locale, string key, Exception cause) : base("Translation missing for [" + bundleClass.FullName + ", " + locale.ToString() + ", " + key + "]", bundleClass, locale, cause) { this.key = key; }
public void changelanguage(CultureInfo ci) { log.Info("change lang to " + ci.ToString() + " current " + Thread.CurrentThread.CurrentUICulture.ToString()); if (ci != null && !Thread.CurrentThread.CurrentUICulture.Equals(ci)) { Thread.CurrentThread.CurrentUICulture = ci; config["language"] = ci.Name; //System.Threading.Thread.CurrentThread.CurrentCulture = ci; Localizations.ConfigLang = ci; HashSet<Control> views = new HashSet<Control> { this, FlightData, FlightPlanner, Simulation }; foreach (Control view in MyView.Controls) views.Add(view); foreach (Control view in views) { if (view != null) { ComponentResourceManager rm = new ComponentResourceManager(view.GetType()); foreach (Control ctrl in view.Controls) { rm.ApplyResource(ctrl); } rm.ApplyResources(view, "$this"); } } } }
public virtual void TestMissingMessage() { System.Globalization.CultureInfo locale = new System.Globalization.CultureInfo("en"); System.String message = NLS.GetLocalizedMessage(MessagesTestBundle.Q0005E_MESSAGE_NOT_IN_BUNDLE, locale); Assert.AreEqual("Message with key:Q0005E_MESSAGE_NOT_IN_BUNDLE and locale: " + locale.ToString() + " not found.", message); }
/// <summary> /// Loads an embedded resource add-in. /// </summary> /// <param name="resourceName">Addin as 'embedded resource'</param> /// <returns>File name of the temporary file that the resource /// was written to.</returns> internal string LoadAddinFromEmbeddedResource(string resourceName) { Stream resourceStream = typeof(Instance).Assembly .GetManifestResourceStream(resourceName); if (resourceStream == null) { Logger.Error("LoadAddinFromEmbeddedResource: Unable to read embedded resource '{0}'", resourceName); throw new IOException("Unable to open resource stream " + resourceName); } string addinPath; Workbook loadedAddin = FindWorkbook(resourceName); if (loadedAddin == null) { string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(tempDir); addinPath = Path.Combine(tempDir, resourceName); Stream tempStream = File.Create(addinPath); resourceStream.CopyTo(tempStream); tempStream.Close(); resourceStream.Close(); try { Logger.Info("LoadAddinFromEmbeddedResource: Loading..."); Workbooks.Open(addinPath); } catch (System.Runtime.InteropServices.COMException) { Logger.Warn("LoadAddinFromEmbeddedResource: COM exception caught, falling back to CorruptLoad"); DisableDisplayAlerts(); // Temporarily set locale to en-US to prevent errors on opening add-in // See https://stackoverflow.com/a/27756126/270712 Logger.Info("LoadAddinFromEmbeddedResource: Temporarily setting locale to en-US"); System.Globalization.CultureInfo oldLocale = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); try { // Workbooks.Open(addinPath, CorruptLoad: XlCorruptLoad.xlExtractData); Workbooks.Open(addinPath); } catch (System.Runtime.InteropServices.COMException e) { Logger.Fatal("LoadAddinFromEmbeddedResource: COM exception occurred when calling Workbooks.Open"); Logger.Fatal(e); throw new XLToolbox.Excel.ExcelException("Excel failed to load the legacy Toolbox add-in", e); } finally { Logger.Info("LoadAddinFromEmbeddedResource: Setting locale back to #{0}", oldLocale.ToString()); System.Threading.Thread.CurrentThread.CurrentCulture = oldLocale; EnableDisplayAlerts(); } } Logger.Info("LoadAddinFromEmbeddedResource: Loaded {0}", addinPath); } else { addinPath = loadedAddin.FullName; Logger.Info("LoadAddinFromEmbeddedResource: Already loaded, path is {0}", addinPath); } return(addinPath); }