Skip to content
Frank Stüber edited this page Sep 11, 2026 · 5 revisions

Introduction

Enbrea.Bcp47 is a .NET implementation of IETF BCP 47 for parsing, validating, inspecting, normalizing, building, and matching language tags and language ranges.

The repository contains two packages:

Both packages support .NET 10, .NET 9 and .NET 8.

Installation

Install the core package from NuGet using the .NET CLI:

dotnet add package Enbrea.Bcp47

Or using the Package Manager Console in Visual Studio:

Install-Package Enbrea.Bcp47

Or add the package reference directly to your project file:

<ItemGroup>
  <PackageReference Include="Enbrea.Bcp47" Version="x.y.z" />
</ItemGroup>

For registry-aware validation and registry metadata, install the IANA package instead:

dotnet add package Enbrea.Bcp47.Iana

Enbrea.Bcp47.Iana depends on Enbrea.Bcp47, so installing it automatically includes the core package.

Quick start

Types from the core package are located in the Enbrea.Bcp47 namespace:

using Enbrea.Bcp47;

Parse a language tag:

var tag = LanguageTag.Parse("zh-Hans-CN");

Console.WriteLine(tag.Language); // zh
Console.WriteLine(tag.Script);   // Hans
Console.WriteLine(tag.Region);   // CN
Console.WriteLine(tag);          // zh-Hans-CN

Value preserves the original input, while ToString() returns the normalized representation:

var tag = LanguageTag.Parse("ZH-hans-cn");

Console.WriteLine(tag.Value);      // ZH-hans-cn
Console.WriteLine(tag.ToString()); // zh-Hans-CN

A language tag can also be constructed using the fluent builder:

var tag = new LanguageTagBuilder()
    .Language("de")
    .Region("DE")
    .Variant("1901")
    .Build();

Console.WriteLine(tag); // de-DE-1901

Language ranges are parsed separately because RFC 4647 ranges are not the same thing as language tags:

var range = LanguageRangeParser.Parse("de-*-DE");

They can be used for filtering and lookup:

var tags = new[]
{
    LanguageTag.Parse("de-DE"),
    LanguageTag.Parse("de-Latn-DE"),
    LanguageTag.Parse("en-US")
};

var matches = range.ExtendedFilter(tags);

For IANA-aware validation, add the companion namespace:

using Enbrea.Bcp47.Iana;

var tag = LanguageTag.Parse("de-DE");

if (tag.IsValidAgainstIanaRegistry())
{
    // All applicable registry-controlled subtags are registered or reserved.
}

Using Enbrea.Bcp47

Advanced Topics

Standards and registries

Releases

Clone this wiki locally