Beispiel #1
0
		public void Can_load_czech()
		{
			using (var stream = _assembly.GetManifestResourceStream("Odachi.Gettext.Tests.Resources.cs.mo"))
			using (var reader = new MoReader(stream))
			{
				var catalog = Catalog.Load(reader);

				Assert.Equal("cs", catalog.Culture.Name);
				Assert.Equal(4, catalog.Count);

				var translation = catalog[new GettextKey(null, "String", null)];
				Assert.Equal(1, translation.Count);
				Assert.Equal("Řetězec", translation[0]);

				translation = catalog[new GettextKey(null, "Plural string", "Plural strings")];
				Assert.Equal(3, translation.Count);
				Assert.Equal("Řetězec", translation[0]);
				Assert.Equal("Řetězce", translation[1]);
				Assert.Equal("Řetězců", translation[2]);

				translation = catalog[new GettextKey("context", "Particular string", null)];
				Assert.Equal(1, translation.Count);
				Assert.Equal("Specifický řetězec", translation[0]);

				translation = catalog[new GettextKey("context", "Particular plural string", "Particular plural strings")];
				Assert.Equal(3, translation.Count);
				Assert.Equal("Specifický řetězec", translation[0]);
				Assert.Equal("Specifické řetězce", translation[1]);
				Assert.Equal("Specifických řetězců", translation[2]);
			}
		}
		private Catalog GetCatalog(CultureInfo culture)
		{
			Catalog catalog;

			if (!_catalogs.TryGetValue(culture.Name, out catalog))
			{
				var path = Path.Combine(_path, culture.Name + ".mo");
				if (File.Exists(path))
				{
					using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
					using (var reader = new MoReader(stream))
						catalog = Catalog.Load(reader, culture: culture);
				}
				else
					catalog = null;

				_catalogs[culture.Name] = catalog;
			}

			return catalog;
		}