ResxCodeGenerator 1.4.6
dotnet add package ResxCodeGenerator --version 1.4.6
NuGet\Install-Package ResxCodeGenerator -Version 1.4.6
<PackageReference Include="ResxCodeGenerator" Version="1.4.6" />
paket add ResxCodeGenerator --version 1.4.6
#r "nuget: ResxCodeGenerator, 1.4.6"
// Install ResxCodeGenerator as a Cake Addin #addin nuget:?package=ResxCodeGenerator&version=1.4.6 // Install ResxCodeGenerator as a Cake Tool #tool nuget:?package=ResxCodeGenerator&version=1.4.6
Snippet
Snippet
ResxCodeGenerator
Generates strongly typed wrapper classes. Include contants for each string resource. Avoid the usage of "magic string". Ensure code and resource file coherence.
The generated classes are named with the same name as their associated resx. These classes can then be used as follows:
file : MyResource.en.resx
@inject IMyResourceLocalizer Localizer
<span>@Localizer.Hello</span>
As the designated solution for localization is to use IStringLocalizer.
Usage
- Install the package
Install-Package ResxCodeGenerator
- Define .resx files
- On the paramters of the resx set <generation action> to "additionnal c# analyzer file"
in csproj this look like this
<ItemGroup>
<AdditionalFiles Include="*.en.resx" />
</ItemGroup>
❗ N.B. - Set this option for only one language per resource. Otherwise, the generated classes will conflict.
Add Interfaces services in App
The package also include a tools to register all Resources Interfaces. in Program.cs
*I'm a bit allergic to magic string. That's kind of why I reference my namespace from code reflection.*😉
var assemblyName = typeof(<YourNameSpaceRoot>.Resources.<AnyOfGeneratedClass>).Namespace);
But it also possible to reference like this
var assemblyName = "<YourNameSpaceRoot>.Resources";
Then use the extension method to add resources's Interfaces
using ResxCodeGeneration.Tools;
...
builder.Services
.AddLocalizedResources(
Assembly.GetExecutingAssembly(),
assemblyName);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
net8.0
- ResxCodeGenerator (>= 1.4.6)
- ResxCodeGenerator.Tools (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ResxCodeGenerator:
Package | Downloads |
---|---|
ResxCodeGenerator
A code generator for .resx files |
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release