Yaml.Localizer
10.3.0
dotnet add package Yaml.Localizer --version 10.3.0
NuGet\Install-Package Yaml.Localizer -Version 10.3.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="Yaml.Localizer" Version="10.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Yaml.Localizer" Version="10.3.0" />
<PackageReference Include="Yaml.Localizer" />
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 Yaml.Localizer --version 10.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Yaml.Localizer, 10.3.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 Yaml.Localizer@10.3.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=Yaml.Localizer&version=10.3.0
#tool nuget:?package=Yaml.Localizer&version=10.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Yaml.Localizer
A tool for managing localized texts via a YAML definition file.
Usage
First, register YamlLocalizer in the services collection.
using Yaml.Localizer.DependencyInjection;
...
services.RegisterYamlLocalizer("{path-to-the-yaml-file}.yaml");
Ensure the YAML file has the correct format.
NOTE: The default culture will be the first iso-code of the first message-id.
- Id: "{message-id}"
Messages:
{iso-code1}: "{text1}"
{iso-code2}: "{text2}"
...
Example
- Id: "MSG_GREETING"
Messages:
es: "Hola"
en: "Hello"
- Id: "MSG_GOODBYE"
Messages:
es: "Adiós"
en: "Goodbye"
- Id: "MSG_MULTILINE_TEXT"
Messages:
es: |
Esto es un mensaje con
múltiples líneas
en: |
This is a
multiline message
Then, in order to get a translated text for your app's current culture, you can do as in this example:
Example
[TestCase("es", "MSG_GREETING", "Hola")]
[TestCase("en", "MSG_GREETING", "Hello")]
[TestCase("en-GB", "MSG_GOODBYE", "Goodbye")]
public void CanTranslateExistingMessage(string culture, string msgId, string expected)
{
// Arrange
this.Localizer.UseCultureOrDefault(culture);
// Act
var result = this.Localizer[msgId];
// Assert
Assert.That(result, Is.EqualTo(expected));
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.11)
- YamlDotNet (>= 18.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.