0

I need to generate another language translation file automatically based on my Resources.resx file.

I already have the following lines present in my .csproj project file:

<ItemGroup>
  <Compile Update="Properties\Resources.Designer.cs">
    <DesignTime>True</DesignTime>
    <AutoGen>True</AutoGen>
    <DependentUpon>Resources.resx</DependentUpon>
  </Compile>
</ItemGroup>
<ItemGroup>
    <EmbeddedResource Update="Properties\Resources.resx">
        <Generator>PublicResXFileCodeGenerator</Generator>
        <LastGenOutput>Resources.Designer.cs</LastGenOutput>
        <SubType>Designer</SubType>
    </EmbeddedResource>
    <EmbeddedResource Update="Properties\Resources.de.resx">
        <DependentUpon>Resources.resx</DependentUpon>
    </EmbeddedResource>
</ItemGroup>

With the above settings in place, the expected file Resources.de.resx neither gets generated automatically nor does it gets updated automatically when I add a new key to the Resources.resx file.

enter image description here

skm
  • 5,015
  • 8
  • 43
  • 104
  • Have a look at [XLocalizer](https://docs.ziyad.info/en/XLocalizer/v1.0/index.md), it can generate resource files and translations automatically, and it supports XML, DB, RESX or any custom resource type to store localization texts. – LazZiya Jan 15 '23 at 08:16

1 Answers1

0

I think you need to change

    <EmbeddedResource Update="Properties\Resources.de.resx">
        <DependentUpon>Resources.resx</DependentUpon>
    </EmbeddedResource>

to also include a generator like so

    <EmbeddedResource Update="Properties\Resources.de.resx">
        <Generator>PublicResXFileCodeGenerator</Generator>
        <DependentUpon>Resources.resx</DependentUpon>
    </EmbeddedResource>

At least this is how it looks in my projects, I usually just add the resource files through the solution explorer

EDIT:

Sorry I should have read your .csproj more carefully, your approach is different from what I'm familiar with.

In fact, I've changed the project files of one of my project to mirror yours and it generates both files correctly.

    <ItemGroup>
        <Compile Update="Resources\EntityLocalizations.Designer.cs">
            <DesignTime>True</DesignTime>
            <AutoGen>True</AutoGen>
            <DependentUpon>EntityLocalizations.resx</DependentUpon>
        </Compile>
    </ItemGroup>
    <ItemGroup>
        <EmbeddedResource Update="Resources\EntityLocalizations.de.resx">       
            <DependentUpon>EntityLocalizations.resx</DependentUpon>
        </EmbeddedResource>
        <EmbeddedResource Update="Resources\EntityLocalizations.resx">
            <Generator>PublicResXFileCodeGenerator</Generator>           
            <LastGenOutput>EntityLocalizations.Designer.cs</LastGenOutput>
            <SubType>Designer</SubType>
        </EmbeddedResource>
    </ItemGroup>

result

So it should work

noel
  • 531
  • 2
  • 7