EntityLocalizer 0.1.10

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

// Install EntityLocalizer as a Cake Tool
#tool nuget:?package=EntityLocalizer&version=0.1.10                

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
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in 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.1.11 488 5/30/2024
0.1.10 101 5/30/2024
0.1.9 816 12/30/2023
0.1.8 580 12/5/2023
0.1.7 116 12/5/2023
0.1.6 128 12/5/2023