LocaleNames 49.0.0

dotnet add package LocaleNames --version 49.0.0
                    
NuGet\Install-Package LocaleNames -Version 49.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LocaleNames" Version="49.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LocaleNames" Version="49.0.0" />
                    
Directory.Packages.props
<PackageReference Include="LocaleNames" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LocaleNames --version 49.0.0
                    
#r "nuget: LocaleNames, 49.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LocaleNames@49.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LocaleNames&version=49.0.0
                    
Install as a Cake Addin
#tool nuget:?package=LocaleNames&version=49.0.0
                    
Install as a Cake Tool

LocaleNames

NuGet Downloads Coverage Status CodeFactor

Names of languages, countries and currencies in almost any language, for .NET. Look a name up by its code, or a code by its name.

The data comes from Unicode CLDR, is embedded in the package, and needs no network access or OS culture data. Targets netstandard2.0 and net10.0.

Install

dotnet add package LocaleNames

LocaleNames is a meta package that references two others, which you can use on their own:

Package Contents
LocaleNames.Core The code. Contains no data.
LocaleNames.Data The CLDR data of all locales, embedded in an assembly. Depends on LocaleNames.Core.

Take LocaleNames to get everything. The data lives in one shared assembly, LocaleNames.Data.

Selecting locales

To ship only some locales, reference LocaleNames.Data (it brings LocaleNames.Core with it) and list the locales you need. Their data is then embedded into your own assembly during the build, and the LocaleNames.Data assembly is left out of your output:

<PropertyGroup>
  
  <LocaleNamesLocales>cs;en;en_GB</LocaleNamesLocales>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="LocaleNames.Data" Version="..." />
</ItemGroup>

Set it in the project that is deployed (the application). The list works the same when you reference LocaleNames, but then there is no need for it.

  • Every locale has its own complete data, en_GB does not depend on en.
  • A locale that is not listed has no translations: its lookups return nothing. If the requested culture has no data of its own, the lookup falls back to its parent culture, so list that one too. For example en-US has no data of its own and uses en, so a user with the en-US culture gets translations only when en is listed.
  • When no locale data can be found at all (not for a single locale, but nowhere), the first lookup throws InvalidOperationException. Its message names what was searched and how to fix it. This is a setup problem, such as a trimmed LocaleNames.Data assembly or a missing assembly attribute, and it is deliberately not reported as empty translations.

LocaleNames.Core finds the resources in loaded assemblies marked by the package. The mark is an assembly attribute generated by the SDK, so it is missing when GenerateAssemblyInfo is false. In that case, register your assembly yourself, once at startup, before the first lookup:

LocaleResourceProvider.Register(typeof(SomeTypeInYourAssembly).Assembly);

Without a selection no registration is needed, LocaleNames.Data is found on its own. A registered assembly is searched before it, so registering one deliberately overrides the data in LocaleNames.Data.

Trimming and native AOT

The library uses no reflection or runtime code generation, so it is trimming and native AOT compatible. The data is stored in a compact binary format, read by hand rather than deserialized from JSON, see the data format.

LocaleNames.Data is found by its name and nothing references it from code, so the package roots the assembly (TrimmerRootAssembly) to keep it from being trimmed. This is done by the package automatically. If the data is missing in a published AOT app anyway, check that build/LocaleNames.Data.targets of the package is imported. With a selection there is nothing to keep, the data is part of your assembly.

Usage

Get a translations object for the language you want the names in, then query it.

var cs = LocaleTranslationsFactory.ForLanguageCode("cs-CZ");
var en = LocaleTranslationsFactory.ForCultureInfo(new CultureInfo("en-US"));

Languages

en.FindLanguageName("cs-CZ");   // Czech
en.FindLanguageCode("Czech");   // cs
en.GetAllLanguageCodes();

Countries

en.FindCountryName("DE");       // Germany
en.FindCountryCode("Germany");  // DE
en.GetAllCountryCodes();

Currencies

cs.FindCurrencyName("CZK");                      // česká koruna
cs.FindCurrencyName("CZK", PluralCategory.Few);  // české koruny
cs.FindCurrencyPluralNames("CZK");               // all plural forms
cs.FindCurrencyCode("česká koruna");             // CZK

en.FindCurrencySymbol("CZK");                       // CZK
en.FindCurrencySymbol("CZK", AltVariant.Narrow);    // Kč
en.GetAllCurrencyCodes();

License

The code is licensed under the MIT License.

The locale data comes from Unicode CLDR and is licensed under the Unicode License v3 (Unicode-3.0). Copyright © 2015-2024 Unicode, Inc. The LocaleNames.Data package and assemblies that embed selected locales (LocaleNamesLocales) contain this data.

Contributing

Issues and pull requests are welcome. See CONTRIBUTING.md.

Activity

Repobeats

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
49.0.0 335 10/31/2026
48.1.1 677 10/8/2026 48.1.1 is deprecated because it is no longer maintained.
48.1.0 283 10/6/2026 48.1.0 is deprecated because it is no longer maintained.
48.0.1 117 10/4/2026
48.0.0 115 10/3/2026
47.0.0 79,555 5/4/2025
45.0.0 42,501 7/7/2024
43.0.0 63,140 7/3/2023
42.0.1 7,946 12/6/2022
41.0.1 3,463 10/17/2022
41.0.0 1,399 4/19/2022
40.0.0 2,431 11/9/2021
39.0.5 698 10/21/2021
39.0.4 622 10/15/2021
39.0.3 628 9/10/2021
39.0.2 564 7/20/2021
39.0.1 545 5/12/2021
39.0.0 585 5/11/2021
Loading failed