EntityLocalizer 0.2.4

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

Entity Localizer

https://github.com/EntitySystems/EntityLocalizer

Generate locales from JSON files

Easily create strong properties and methods from JSON localized translations, with optional arguments.

How to use:

Install latest package EntityLocalizer https://www.nuget.org/packages/EntityLocalizer/

Add this to .csproj.

<Project>
    <Target Name="CodeGen" BeforeTargets="BeforeBuild;BeforeRebuild">
        <EslGeneratorTask
                InputPath="./StaticResources/Locales"
                OutputPath="./GeneratedResources/Locales/"
                OutputNamespace="Entity"
        />
    </Target>
</Project>
  • InputPath is the directory from where to load the locales,
  • OutputPath is the directory where the output C# resource file will be generated.
  • OutputNamespace is the namespace for the generated C# file.

Once you have setup your project, you can add locales by creating *.loc.json files, the file names must end in .loc.json. Format below:

{
  "HelloWorld": {
    "EN": "Hello generated world!",
    "FR": "Bonjour monde!"
  },
  "Login": {
    "EN": "Log in",
    "FR": "Connexion",
    "?": "Default case override"
  }
}

Then you just run a build on consumer project, you can now access your locales/translations via C# using the following:

var locales = new EntityLocales()
{
    InstanceLanguage = "EN"
};

Console.WriteLine(locales.HelloWorld); // outputs "Hello generated world!"

If you want to generate translations that accept parameters, you can do the following in the JSON file:

{
  "LocaleWithArgument": {
    "args": [
      "string:name",
      "number:amount",
      "string:currency"
    ],
    "EN": "Welcome {0}, your bill is of {1} {2}",
    "FR": "Bienvenue {0}, votre facture est de {1} {2}"
  }
}

Only the 2 following types are supported: string and number. Supply a mandatory method argument name like so: [type]:[argName]

You can then access the locales and supply arguments like so:

var translated = locales.LocaleWithArgument("Jacob", 129.99m, "$");
// outputs "Welcome Jacob, your bill is of 129.99 $"
Use in JS/TS
type Locale = 'EN' | 'FR'
type I18nSource = Record<string, Record<Locale, string>>

const i18nSource = {
    HomeWelcome: {
        EN: 'Welcome to App',
        FR: 'Bienvenue',
    },
    Foo: {
        EN: 'Foo EN',
        FR: 'Foo FR',
    },
} satisfies I18nSource

let currentLocale: Locale = 'EN'

const translation = {} as Record<keyof typeof i18nSource, string>
for (const key in i18nSource) {
    Object.defineProperty(translation, key, {
        get: () => i18nSource[key as never][currentLocale],
    })
}

console.log(translation.HomeWelcome)
console.log(translation.Foo)

currentLocale = 'FR'

console.log(translation.HomeWelcome)
console.log(translation.Foo)

Built by Entity Systems || https://entitysystems.co
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

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
0.2.4 1,109 5/25/2025
0.2.2 161 5/25/2025
0.2.1 156 5/25/2025
0.2.0 162 5/25/2025
0.1.11 1,086 5/30/2024
0.1.10 167 5/30/2024
0.1.9 903 12/30/2023
0.1.8 650 12/5/2023
0.1.7 155 12/5/2023
0.1.6 169 12/5/2023