void CheckItems(POCatalog catalog, bool expectComments) { var key1 = new POKey("{0} hour to midnight", "{0} hours to midnight", "Home"); var key2 = new POKey($"Here is an example of how one might continue a very long string{Environment.NewLine}" + $"for the common case the string represents multi-line output.{Environment.NewLine}"); Assert.Equal(2, catalog.Count); Assert.Contains(key1, catalog.Keys); Assert.Contains(key2, catalog.Keys); Assert.Equal(2, catalog[key1].Count); Assert.Equal("Translation of {0} hour to midnight", catalog.GetTranslation(key1, 1)); Assert.Equal("Translation of {0} hours to midnight", catalog[key1][1]); Assert.Equal("Translation of {0} hour to midnight", catalog.GetTranslation(key1, 1)); Assert.Equal("Translation of {0} hours to midnight", catalog.GetTranslation(key1, 2)); Assert.Equal(1, catalog[key2].Count); Assert.Equal("Some translation of long text", catalog[key2][0]); if (expectComments) { Assert.Equal(6, catalog[key1].Comments.Count); Assert.Equal(0, catalog[key2].Comments.Count); var comments = catalog[key1].Comments; Assert.Equal(POCommentKind.Translator, comments[0].Kind); Assert.Equal("some translator comment", ((POTranslatorComment)comments[0]).Text); Assert.Equal(POCommentKind.Extracted, comments[1].Kind); Assert.Equal("some extracted comment", ((POExtractedComment)comments[1]).Text); Assert.Equal(POCommentKind.Reference, comments[2].Kind); var references = ((POReferenceComment)comments[2]).References; Assert.Equal(1, references.Count); Assert.Equal("/Views/Home/Index.cshtml", references[0].FilePath); Assert.Equal(8, references[0].Line); Assert.Equal(POCommentKind.Flags, comments[3].Kind); var flags = ((POFlagsComment)comments[3]).Flags; Assert.Equal(2, flags.Count); Assert.Contains("fuzzy", flags); Assert.Contains("csharp-format", flags); Assert.Equal(POCommentKind.PreviousValue, comments[4].Kind); Assert.Equal(POIdKind.Id, ((POPreviousValueComment)comments[4]).IdKind); Assert.Equal("{0} hour to midnite", ((POPreviousValueComment)comments[4]).Value); Assert.Equal(POCommentKind.PreviousValue, comments[5].Kind); Assert.Equal(POIdKind.PluralId, ((POPreviousValueComment)comments[5]).IdKind); Assert.Equal("{0} hours to midnite", ((POPreviousValueComment)comments[5]).Value); } else { Assert.Null(catalog[key1].Comments); Assert.Null(catalog[key2].Comments); } }
bool TryGetTranslationCore(POKey key, int pluralCount, out string value, POCatalog catalog = null) { if (catalog == null) { catalog = Catalog; } if (catalog != null) { var translation = catalog.GetTranslation(key, pluralCount); if (translation != null) { value = translation; return(true); } else { translation = ParentCultureCatalog?.GetTranslation(key, pluralCount); if (translation != null) { value = translation; return(true); } else if (Options.Value.FallBackNeutralCulture && catalog.GetCultureName() != Settings.NeutralCulture) { return(TryGetTranslationCore(key, pluralCount, out value, FallBackCatalog)); } } } value = null; return(false); }
public static string GetTranslation(string msg) { if (moCatalog != null) { return(moCatalog.GetString(msg)); } else if (poCatalog != null) { return(poCatalog.GetTranslation(new POKey(msg))); } return(msg); }
bool TryGetTranslation(POKey key, int pluralCount, out string value) { if (_catalog != null) { var translation = _catalog.GetTranslation(key, pluralCount); if (translation != null) { value = translation; return(true); } } value = null; return(false); }