LocalizationGenerator 1.0.2

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

// Install LocalizationGenerator as a Cake Tool
#tool nuget:?package=LocalizationGenerator&version=1.0.2                

Install

Install-Package LocalizationGenerator

Setup

Add a JSON file in your project root called localization.json. Follow the format below.

{
  "HELLO": {
    "en-US": "hello",
    "de-DE": "hallo"
  }
}

This source generator relies on AdditionalFiles, use one of the 3 methods below to complete setup.

Method 1

If using Rider

  • Right click file --> Properties
  • Change build action to AdditionalFiles

Method 2

If using Visual Studio XXXX

  • Click on file
  • View the item properties panel and change build action to AdditionalFiles

Method 3

Manually add the following group to your csproj

<ItemGroup>
  <None Remove="localization.json" />
  <AdditionalFiles Include="localization.json"/>
</ItemGroup>

How to use

At build - a couple things are generated for you.

  • Referencing the key values as strings can lead to typos and forces a developer to jump between files to know what's there. To combat this, keys are grouped under the LocalizationResource enum!
  • Supported languages are inferred and can also be referenced as an enum, LocalizationLanguage.

Given the above JSON example we could do the following:

Pull text using current culture

var translatedText = Localizer.Get(LocalizationResource.HELLO);

Pull text using specific culture

var translatedText = Localizer.Get(LocalizationResource.HELLO, LocalizationLanguage.de_DE);

Pass in a culture info reference

var translatedText = Localizer.Get(LocalizationResource.HELLO, CultureInfo.CurrentCulture);

Pass in a culture info as string

var translatedText = Localizer.Get(LocalizationResource.HELLO, "en-US");
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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
1.0.3 1,285 2/22/2022
1.0.2 1,316 2/15/2022
1.0.0 1,337 2/15/2022