Gu.Localization icon indicating copy to clipboard operation
Gu.Localization copied to clipboard

Translator.Culture should allow setting neutral language

Open Anlo2846 opened this issue 4 years ago • 2 comments

When a .csproj has a neutral language set, for example:

<NeutralLanguage>en</NeutralLanguage>

and the following assignment is executed:

Translator.Culture = CultureInfo.GetCultureInfo("en");

the following exception is thrown:

System.ArgumentException : Can only set culture to an existing culture.
Check the property Cultures for a list of valid cultures.

Anlo2846 avatar Jun 18 '20 15:06 Anlo2846

I failed to repro this bug using:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWPF>true</UseWPF>
    <NeutralLanguage>en</NeutralLanguage>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Gu.Localization\Gu.Localization.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Compile Update="Properties\Resources.Designer.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>

    <EmbeddedResource Update="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

</Project>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        this.InitializeComponent();
        Translator.Culture = CultureInfo.GetCultureInfo("en");
    }
}

JohanLarsson avatar Jun 30 '20 06:06 JohanLarsson

Published a new version https://www.nuget.org/packages/Gu.Localization/6.5.0 no intentional fix for this but we can check if it is still an issue.

In a test project with no <NeutralLanguage>en</NeutralLanguage> I can see this being an issue as there is no mechanism for inheriting neutral culture in place.

JohanLarsson avatar Jul 01 '20 07:07 JohanLarsson