private void SetTexts() { GettextResourceManager catalog = new GettextResourceManager(PathResolver.Default); // If satellite assemblies have another base name use GettextResourceManager("Examples.HelloForms.Messages") constructor // If you call from another assembly, use GettextResourceManager(anotherAssembly) constructor Localizer.Localize(this, catalog, store); // We need pass 'store' argument only to be able revert original text and switch languages on fly // Common use case doesn't required it: Localizer.Localize(this, catalog); // Manually formatted strings label2.Text = catalog.GetStringFmt("This program is running as process number \"{0}\".", System.Diagnostics.Process.GetCurrentProcess().Id); label3.Text = String.Format( catalog.GetPluralString("found {0} similar word", "found {0} similar words", 1), 1); label4.Text = String.Format( catalog.GetPluralString("found {0} similar word", "found {0} similar words", 2), 2); label5.Text = String.Format( catalog.GetPluralString("found {0} similar word", "found {0} similar words", 5), 5); label6.Text = String.Format("{0} ('computers')", catalog.GetParticularString("Computers", "Text encoding")); label7.Text = String.Format("{0} ('military')", catalog.GetParticularString("Military", "Text encoding")); label8.Text = String.Format("{0} (non contextual)", catalog.GetString("Text encoding")); }
static void ShowMessages() { Console.WriteLine("Current culture {0}", System.Threading.Thread.CurrentThread.CurrentUICulture); GettextResourceManager catalog = new GettextResourceManager(); Console.WriteLine(catalog.GetString("Hello, world!")); // GetStringFmt is an Gettext.NET extension Console.WriteLine(catalog.GetStringFmt("This program is running as process number \"{0}\".", Process.GetCurrentProcess().Id)); Console.WriteLine(String.Format( catalog.GetPluralString("found {0} similar word", "found {0} similar words", 1), 1)); // GetPluralStringFmt is an Gettext.NET extension Console.WriteLine(catalog.GetPluralStringFmt("found {0} similar word", "found {0} similar words", 2)); Console.WriteLine(String.Format( catalog.GetPluralString("found {0} similar word", "found {0} similar words", 5), 5)); Console.WriteLine("{0} ('computers')", catalog.GetParticularString("Computers", "Text encoding")); Console.WriteLine("{0} ('military')", catalog.GetParticularString("Military", "Text encoding")); Console.WriteLine("{0} (non cotextual)", catalog.GetString("Text encoding")); Console.WriteLine(catalog.GetString( "Here is an example of how one might continue a very long string\nfor the common case the string represents multi-line output.\n")); }
/// <summary> /// Returns the translation of <paramref name="msgid"/> and /// <paramref name="msgidPlural"/>, choosing the right plural form /// depending on the number <paramref name="n"/>. /// </summary> /// <param name="msgid">the key string to be translated, an ASCII /// string</param> /// <param name="msgidPlural">the English plural of <paramref name="msgid"/>, /// an ASCII string</param> /// <param name="n">the number, should be >= 0</param> /// <param name="treatZeroAsPlural">if set to true then the number 0 is considered being plural /// (for situations like where strings like "0 records" are to be displayed).</param> /// <returns>the translation, or <c>null</c> if none is found</returns> public static string GetPluralString(String msgid, String msgidPlural, long n, bool treatZeroAsPlural = false) { bool Plural = treatZeroAsPlural ? ((n != 1) && (n != -1)) : (((n != 1) && (n != -1)) && (n != 0)); if (catalog == null) { return(Plural ? msgidPlural : msgid); } else { string result = msgid; if ((n == 0)) { // Calling 'catalog.GetPluralString' does not know about our 'treatZeroAsPlural = false' and would return plural in case of n = 0 // so we call 'catalog.GetPluralString' in case 'treatZeroAsPlural = false' ... if (treatZeroAsPlural) { try { result = catalog.GetPluralString(msgid, msgidPlural, n); } catch (Exception Exc) { TLogging.Log( "GetText: Catalog.GetPluralString: problem for getting text for \"" + msgid + "\" and/or \"" + msgidPlural + "\""); TLogging.Log(Exc.ToString()); } return(result); } else { // ...and we make n 1 to get the call to 'catalog.GetPluralString' (further below) to return the singular string! n = 1; } } // Calling 'catalog.GetPluralString' does not work with negative numbers... if (n < 0) { // ...so we make them positive n = n * -1; } try { result = catalog.GetPluralString(msgid, msgidPlural, n); } catch (Exception Exc) { TLogging.Log("GetText: Catalog.GetPluralString: problem for getting text for \"" + msgid + "\" and/or \"" + msgidPlural + "\""); TLogging.Log(Exc.ToString()); } return(result); } }
public MainController() { //Type t = typeof(MainCatalog_ru_RU); View = new UIView(); View.Frame = new RectangleF(0f, 0f, 320f, 460f); View.BackgroundColor = UIColor.White; UILabel l = new UILabel(); l.Frame = new RectangleF(0f, 0f, 320f, 200f); l.Lines = 0; l.LineBreakMode = UILineBreakMode.WordWrap; View.AddSubview(l); CultureInfo ci = new CultureInfo("ru-RU"); GettextResourceManager catalog = new GettextResourceManager("MainCatalog", new DifferentNamesSingleFolderPathResolver()); StringBuilder sb = new StringBuilder(); sb.AppendLine(catalog.GetString(Text.MyNameIs, ci)) .AppendLine(catalog.GetString(Text.MyAge, ci)) .AppendLine(catalog.GetString(Text.ILove, ci)); for (int i = 0; i < 6; i++) { sb.AppendLine(string.Format(catalog.GetPluralString(Text.PluralDay, Text.PluralDays, i, ci), i)); } l.Text = sb.ToString(); }
/// <inheritdoc /> /// <seealso cref="GettextResourceManager.GetPluralString(string,string,long)"/> public string GetPluralString(string text, [NotNull] string textPlural, long count) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (textPlural == null) { throw new ArgumentNullException(nameof(textPlural)); } return(resourceManager.GetPluralString(text, textPlural, count)); }