CultureMatcher 1.0.1
See the version list below for details.
dotnet add package CultureMatcher --version 1.0.1
NuGet\Install-Package CultureMatcher -Version 1.0.1
<PackageReference Include="CultureMatcher" Version="1.0.1" />
paket add CultureMatcher --version 1.0.1
#r "nuget: CultureMatcher, 1.0.1"
// Install CultureMatcher as a Cake Addin #addin nuget:?package=CultureMatcher&version=1.0.1 // Install CultureMatcher as a Cake Tool #tool nuget:?package=CultureMatcher&version=1.0.1
CultureMatcher
Given a set of cultures an application has translations for and the set of cultures a user requests, find the best matching cultures.
This is the implementation of LocaleMatcher in C# version, and the source code is directly translated from FormatJS.
Usage
using System.Globalization;
using CultureInfoMatcher;
CultureMatcher.Match(
new CultureInfo[] { new CultureInfo("fr-XX"), new CultureInfo("en-GB") },
new CultureInfo[] { new CultureInfo("fr-FR"), new CultureInfo("en-US") },
new CultureInfo("en-US")
); // fr-FR
Now declare the languages for which the application has translated, and the default language.
CultureInfo[] availableCultures = {
new CultureInfo("en-US"),
new CultureInfo("zh-CN"),
new CultureInfo("zh-TW"),
new CultureInfo("ja-JP"),
new CultureInfo("ko-KR"),
new CultureInfo("no-NO"),
new CultureInfo("vi-VN"),
new CultureInfo("id-ID"),
};
CultureInfo defaultCulture = new CultureInfo("en-US");
CultureMatcher.Match(new CultureInfo("zh-HK"), availableCultures, defaultCulture); // zh-TW
zh-HK uses traditional Chinese, so it matches zh-TW, even though zh-CN is in front.
CultureMatcher.Match(new CultureInfo("fr-FR"), availableCultures, defaultCulture); // en-US
French is not in the list, so English is matched.
CultureMatcher.Match(new CultureInfo("ms-MY"), availableCultures, defaultCulture); // id-ID
Malay and Indonesian are mutually intelligible.
CultureMatcher.Match(new CultureInfo("da-DK"), availableCultures, defaultCulture); // no-NO
Danish and Norwegian are mutually intelligible.
CultureMatcher.Match(new CultureInfo[] {
new CultureInfo("fr-FR"),
new CultureInfo("vi-VN"),
new CultureInfo("ko-KR"),
}, availableCultures, defaultCulture); // vi-VN
If someone is proficient in French, fluent in Vietnamese, and knows Korean, even though the list includes both Korean and Vietnamese, it matches Vietnamese which has a higher level of understanding.
API
Find the best matching culture info with a list of requested cultures.
public static CultureInfo Match(
IList<CultureInfo> requestedCultures,
IList<CultureInfo> availableCultures,
CultureInfo defaultCulture,
MatcherAlgorithm matcherAlgorithm = MatcherAlgorithm.BestFit
);
Find the best matching culture info for a single requested culture.
public static CultureInfo Match(
CultureInfo requestedCulture,
IList<CultureInfo> availableCultures,
CultureInfo defaultCulture,
MatcherAlgorithm matcherAlgorithm = MatcherAlgorithm.BestFit
);
Options
Matcher Algorithm
Lookup
would continue to be the existingLookupMatcher
implementation within ECMA-402.BestFit
would be implementation-dependent.
Licence
CultureMatcher is available under the MIT License. See the LICENSE file for more info.
References
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.