DataStandardizer.LanguageTag
Strongly-typed support for IETF language tags as defined by BCP 47 — compose, deconstruct, and validate tags such as en, fr-CA, zh-Hans, and es-419.
dotnet add package DataStandardizer.LanguageTag
Standards
| Standard | What it provides |
|---|---|
| RFC 5646 | Tags for Identifying Languages (part of IETF BCP 47): language tags built from subtags for primary language, extended language, script, region, variant, extension, and private use, together with the format of the IANA Language Subtag Registry (section 3.1). The package implements both conformance classes of section 2.2.9: well-formed and valid. |
BCP 47 also includes RFC 4647, Matching of Language Tags, which defines filtering and lookup of language ranges against tags. This package does not implement RFC 4647 matching.
Creating a language tag checks that it’s well-formed: it matches the grammar, and nothing is looked up. To check that it’s valid, pass a loaded copy of the IANA Language Subtag Registry. If you can’t load a registry, you can opt in to checking against the codes implemented by the other Data Standardizer packages (ISO 639 languages, ISO 15924 scripts, ISO 3166-1 / UN M49 regions). See Well-formed, valid and the ISO code lists.
Platform support
Targets .NET Standard 1.1 and 2.0 for use in legacy applications, as well as in-support modern .NET runtimes (net10.0).
The netstandard1.1 and netstandard2.0 builds depend on the System.Memory package, which provides the span types they use. NuGet installs it automatically. The net10.0 build has the span types built in, so it has no extra dependency.
Applies to: the
ReadOnlySpan<char>overloads ofTryCreate,IsWellFormed,IsValidand theCheck…Subtagmethods, andBcp47LanguageTag.AsSpan(), exist on every target.Bcp47LanguageTagimplementsISpanFormattable,IParsable<T>andISpanParsable<T>onnet10.0only. The builder’sparams ReadOnlySpan<string>overloads exist onnet10.0only. Loading a subtag registry from a file path (SubtagRegistry.CreateFromFileandCreateFromFileAsync) needsnetstandard2.0or later; onnetstandard1.1, load it from aStreamor a string.
See Platform support for the full matrix, and Use language tags for performance notes.
How-to guides
Concepts
- Anatomy of a language tag
- The language-tag builder pipeline
- Well-formed, valid and the ISO code lists
Reference
Table of contents
- Use language tags
- Create language tags using the builder
- Anatomy of a language tag
- The language-tag builder pipeline
- Well-formed, valid and the ISO code lists
- API reference
- Bcp47KeyedSubtag Struct
- Bcp47LanguageTag Struct
- Bcp47LanguageTagBuilder Class
- ISubtagRegistryRecord Interface
- LanguageTagConformance Enum
- LanguageTagFormatException Exception
- SubtagRegistry Class
- SubtagRegistryFileDateRecord Class
- SubtagRegistryLoadOptions Enum
- SubtagRegistryRecordBase Class
- SubtagRegistryRecordType Enum
- SubtagRegistrySubtagRecord Class
- SubtagRegistryTagRecord Class
- SubtagRegistryTagRecordBase Class