Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #118 from ErikApption/master
Browse files Browse the repository at this point in the history
added support to split i18n files into multiple json files
  • Loading branch information
AlexTeixeira authored Dec 6, 2021
2 parents aac274c + 5f33e2d commit 9404f5e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public ConcurrentDictionary<string, LocalizatedFormat> ConstructLocalization(IEn
_options = options;

var enumerable = myFiles as string[] ?? myFiles.ToArray();
var neutralFile = enumerable.FirstOrDefault(file => Path.GetFileName(file)
.Count(s => s.CompareTo('.') == 0) == 1);
var neutralFiles = enumerable.Where(file => Path.GetFileName(file)
.Count(s => s.CompareTo('.') == 0) == 1).ToList();
var isInvariantCulture =
currentCulture.DisplayName == CultureInfo.InvariantCulture.ThreeLetterISOLanguageName;

Expand Down Expand Up @@ -61,9 +61,10 @@ public ConcurrentDictionary<string, LocalizatedFormat> ConstructLocalization(IEn
}
else
{
if (neutralFile != null)
if (neutralFiles.Any())
{
AddValueToLocalization(options, neutralFile, true);
foreach (var neutralFile in neutralFiles)
AddValueToLocalization(options, neutralFile, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
"WeatherForecastDesc": "This component demonstrates fetching data from a service.",
"Loading": "Loading...",
"Date": "Date",
"TempC": "Temp. (C)",
"TempF": "Temp. (F)",
"Summary": "Summary",
"CurrentCount": "Current count",
"ClickMe": "Click me",
"About": "About",
"Freezing": "Freezing",
"Bracing": "Bracing",
"Chilly": "Chilly",
"Cool": "Cool",
"Mild": "Mild",
"Warm": "Warm"
"About": "About"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
"WeatherForecastDesc": "Ce volet montre comment obtenir des données à partir d'un service.",
"Loading": "Chargement...",
"Date": "Date",
"TempC": "Temp. (C)",
"TempF": "Temp. (F)",
"Summary": "Sommaire",
"CurrentCount": "Valeur courante",
"ClickMe": "Cliquer",
"About": "À propos de",
"Freezing": "Geler",
"Bracing": "Bracing",
"Chilly": "Froid",
"Cool": "Frais",
"Mild": "Doux",
"Warm": "Chaud"
"About": "À propos de"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"TempC": "Temp. (C)",
"TempF": "Temp. (F)",
"Freezing": "Freezing",
"Bracing": "Bracing",
"Chilly": "Chilly",
"Cool": "Cool",
"Mild": "Mild",
"Warm": "Warm"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"TempC": "Temp. (C)",
"TempF": "Temp. (F)",
"Freezing": "Geler",
"Bracing": "Bracing",
"Chilly": "Froid",
"Cool": "Frais",
"Mild": "Doux",
"Warm": "Chaud"
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ public void Should_Read_Color_FallbackToParent()

}

[TestMethod]
public void Should_Read_Luminosity_FallbackToParent()
{
InitLocalizer("fr-FR");
LocalizedString result = localizer.GetString("Luminosity");
Assert.AreEqual("Luminosité", result);
Assert.IsFalse(result.ResourceNotFound);

InitLocalizer("en-NZ");
result = localizer.GetString("Luminosity");
Assert.AreEqual("Luminosity", result);
Assert.IsFalse(result.ResourceNotFound);

InitLocalizer("zh-CN");
result = localizer.GetString("Luminosity");
Assert.AreEqual("Luminosity", result);
Assert.IsFalse(result.ResourceNotFound);

}

//[TestMethod]
public void Should_Read_ResourceMissingCulture_FallbackToResourceName()
{
Expand Down Expand Up @@ -97,7 +117,8 @@ public void Should_Read_AllStringsWithParentFallback()
LocalizedString[] results = localizer.GetAllStrings(includeParentCultures: true).ToArray();
LocalizedString[] expected = new[] {
new LocalizedString("Color", "Colour (specific)", false),
new LocalizedString("Empty", "Empty", false)
new LocalizedString("Empty", "Empty", false),
new LocalizedString("Luminosity", "Luminosity", false)
};
CollectionAssert.AreEqual(expected, results.OrderBy(s => s.Name).ToArray(), new LocalizedStringComparer());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Luminosity" : "Luminosity"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Luminosity": "Luminosité"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Luminosity" : "Luminosity"
}

0 comments on commit 9404f5e

Please sign in to comment.