简体   繁体   中英

Automatic generation of translation file for Resource.resx is not working

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.

在此处输入图像描述

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>

结果

So it should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM