Vey.Localization 0.0.3

dotnet add package Vey.Localization --version 0.0.3
                    
NuGet\Install-Package Vey.Localization -Version 0.0.3
                    
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="Vey.Localization" Version="0.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Vey.Localization" Version="0.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Vey.Localization" />
                    
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 Vey.Localization --version 0.0.3
                    
#r "nuget: Vey.Localization, 0.0.3"
                    
#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 Vey.Localization@0.0.3
                    
#: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=Vey.Localization&version=0.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Vey.Localization&version=0.0.3
                    
Install as a Cake Tool

Localization

Simple manager for handling localization.

Its main difference from most is the ability to get a translation of a string not by key but using one of the translated strings.

To start, you need to create a translation file and load it into a package. This can be done in several ways.

JSON

var pack = LocalizationPack.FromJson("lang-pack.json");

The lang-pack.json package will look like this:

[
  {
    "en": "Language select",
    "ru": "Выбор языка",
    "es": "Seleccionar idioma",
    "fr": "Sélection de la langue",
    "de": "Sprachauswahl",
    "it": "Selezione lingua"
  },
  {
    "en": "I agree",
    "ru": "Я согласен",
    "es": "Estoy de acuerdo",
    "fr": "Je suis d'accord",
    "de": "Ich stimme zu",
    "it": "Sono d'accordo"
  }
]

Simplified Text Format

var pack = LocalizationPack.FromLPack("lang-pack.lpack");

The lang-pack.lpack package will look like this:

en: Language select
ru: Выбор языка
es: Seleccionar idioma
fr: Sélection de la langue
de: Sprachauswahl
it: Selezione lingua

en: I agree
ru: Я согласен
es: Estoy de acuerdo
fr: Je suis d'accord
de: Ich stimme zu
it: Sono d'accordo

The separator : is used between the language code and the translation string. You can use any characters after the colon except for new line characters. Blocks are separated by one or more empty lines. It doesn't matter how many empty lines there are, as long as the block is separated by at least one empty line, it will be considered another translation block.

Translation

You can get the translation using the LocalizationPack directly through the Translate method. It ignores leading and trailing whitespace and case of characters.

Instead of keys, other strings are used. For example, in the "Language select" block - everything is a key! You can get the translation using any of the strings as a key.

pack.Translate("es", "Language select");            // -> "Seleccionar idioma"
pack.Translate("de", "Language select");            // -> "Sprachauswahl"
pack.Translate("de", "Sélection de la langue");     // -> "Sprachauswahl"
pack.Translate("ru", "Sprachauswahl");              // -> "Выбор языка"

LocalizationManager

It is better to use LocalizationManager, which eliminates the need to specify the language code every time. Essentially, that's all it does.

var manager = new LocalizationManager(pack, "es");

manager.Translate("Language select");               // -> "Seleccionar idioma"
manager.Translate("I agree");                       // -> "Estoy de acuerdo"

manager.code = "ru";

manager.Translate("Language select");               // -> "Выбор языка"
manager.Translate("I agree");                       // -> "Я согласен"

// If translation is not found
manager.code = "en";
manager.Translate("Información");                   // -> null
manager.TryTranslate("Información");                // -> "Información"

LocalizedString

There is also a helper class LocalizedString that creates a string and translates it when converted to a string.

var text = new LocalizedString(manager, "Sélection de la langue");
text.ToString();                // -> "Language select"
Console.WriteLine(text);        // -> "Language select"

var textTwo = manager.String("Sélection de la langue"); // -> LocalizedString
textTwo.ToString();             // -> "Language select"
Console.WriteLine(textTwo);     // -> "Language select"
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Vey.Localization:

Package Downloads
Telegram.Bot.UI

Convenient creation and localization of bots in Telegram

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.3 249 5/12/2025
0.0.2 124 3/1/2025
0.0.1 118 2/5/2025