Panlingo.LanguageCode 0.0.0.14

There is a newer version of this package available.
See the version list below for details.
dotnet add package Panlingo.LanguageCode --version 0.0.0.14                
NuGet\Install-Package Panlingo.LanguageCode -Version 0.0.0.14                
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="Panlingo.LanguageCode" Version="0.0.0.14" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Panlingo.LanguageCode --version 0.0.0.14                
#r "nuget: Panlingo.LanguageCode, 0.0.0.14"                
#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.
// Install Panlingo.LanguageCode as a Cake Addin
#addin nuget:?package=Panlingo.LanguageCode&version=0.0.0.14

// Install Panlingo.LanguageCode as a Cake Tool
#tool nuget:?package=Panlingo.LanguageCode&version=0.0.0.14                

Panlingo.LanguageCode

Panlingo.LanguageCode is a comprehensive .NET library designed for managing and converting language codes using various normalization and conversion rules. The library supports multiple language code entities, including two-letter ISO codes, three-letter ISO codes, and English names.

What are Language Codes?

Language codes are standardized codes used to identify languages. The ISO 639 standard defines sets of codes for the representation of names of languages. There are several parts to the ISO 639 standard:

  • ISO 639-1: Defines two-letter codes (e.g., "en" for English, "ru" for Russian).
  • ISO 639-2: Defines three-letter codes (e.g., "eng" for English, "rus" for Russian).
  • ISO 639-3: Extends the code set to cover all known languages.

These codes are essential in various applications, including software localization, data exchange between systems, and linguistic research.

Features

  • Convert language codes to their normalized forms.
  • Resolve both two-letter and three-letter ISO codes.
  • Handle deprecated and legacy language codes.
  • Reduce specific language codes to their macrolanguage equivalents.
  • Retrieve English names for language codes.
  • Handle IETF language tags.
  • Normalize inputs by converting to lowercase and trimming spaces.

Installation

To install the Panlingo.LanguageCode library, you can use the .NET CLI:

dotnet add package Panlingo.LanguageCode

Usage

You can use the library to convert and resolve language codes. Below are some examples to illustrate how to use the provided functionalities.

Basic Configuration

Before using the library, set up a basic resolver with your desired rules:

var resolver = new LanguageCodeResolver()
    .ToLowerAndTrim()
    .ConvertFromIETF()
    .ConvertFromDeprecatedCode()
    .ReduceToMacrolanguage();

Convert a Single Language Code

You can convert a single language code to its two-letter or three-letter ISO equivalent:

string twoLetterCode = LanguageCodeHelper.GetTwoLetterISOCode("rus");
// twoLetterCode => "ru"

string threeLetterCode = LanguageCodeHelper.GetThreeLetterISOCode("en");
// threeLetterCode => "eng"

Resolve Language Codes with Options

You can resolve language codes using specific options, such as converting deprecated codes or reducing to macrolanguages:

string resolvedCode = LanguageCodeHelper.Resolve("iw", resolver);
// resolvedCode => "heb"

Handle Legacy Codes with Conflicts

For resolving legacy codes that may have conflicts, you can specify how to handle such conflicts:

var options = resolver
    .ConvertFromDeprecatedCode((sourceCode, candidates) =>
    {
        return candidates.Any() ? candidates.First() : sourceCode;
    })
    .Select(LanguageCodeEntity.Alpha3);

string resolvedLegacyCode = LanguageCodeHelper.Resolve("mof", options);
// resolvedLegacyCode => "xpq"

Retrieve English Names for Language Codes

You can also get the English names for language codes:

string englishName = LanguageCodeHelper.GetLanguageEnglishName("ru");
// englishName => "Russian"

Handle IETF Language Tags

You can resolve language codes from IETF language tags like "en-US":

var options = new LanguageCodeResolver().ConvertFromIETF();
string resolvedIETFCode = LanguageCodeHelper.Resolve("en-US", options);
// resolvedIETFCode => "en"

Normalize Input by Converting to Lowercase and Trimming Spaces

You can normalize inputs by converting to lowercase and trimming spaces:

var options = new LanguageCodeResolver().ToLowerAndTrim();
string normalizedCode = LanguageCodeHelper.Resolve(" UK  ", options);
// normalizedCode => "uk"

Contributing

Contributions and feedback are welcome! Feel free to submit issues, fork the repository, and send pull requests.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.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.

Version Downloads Last updated
0.2.0 91 11/10/2024
0.1.2 80 10/23/2024
0.1.1 82 10/22/2024
0.0.0.23 82 10/7/2024
0.0.0.22 86 9/22/2024
0.0.0.21 128 9/10/2024
0.0.0.20 105 9/8/2024
0.0.0.19 107 9/1/2024
0.0.0.18 110 8/26/2024
0.0.0.17 132 8/21/2024
0.0.0.16 118 8/9/2024
0.0.0.15 132 8/8/2024
0.0.0.14 80 8/3/2024
0.0.0.13 95 8/1/2024
0.0.0.12 92 8/1/2024

- Initial release