Skip to content

Unable to switch language dynamically when using AOT compilation #22

Description

@SydneyOwl

Hi Antelcat team,

Thanks for bringing such an excellent project!

I'm encountering an issue with dynamic language switching when using AOT compilation. Under non-AOT compilation, I can successfully switch languages via I18NExtension.Culture = new CultureInfo("xxx"). However, after enabling AOT compilation, the project only displays default language (in my case, en-US). Switching languages through CultureInfo no longer works, and this issue occurs on both Linux and Windows platforms.

I also attempted to use rd.xml to exclude Antelcat.I18N.Avalonia from trimming, but it appears to have no effect.

On Linux platform, I use net10 for AOT compilation, while on Windows I use net10-windows. Below is the simplified csproj file:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup> 
        <TargetFrameworks>net10.0</TargetFrameworks>
        <OutputType>WinExe</OutputType>
        <Nullable>enable</Nullable>
        <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
        <PublishAot>true</PublishAot>
        <BuiltInComInteropSupport>false</BuiltInComInteropSupport>
        <TrimMode>partial</TrimMode>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Antelcat.I18N.Avalonia" Version="1.1.2"/>
        <PackageReference Include="Avalonia" Version="11.3.1"/>
        <PackageReference Include="Avalonia.Desktop" Version="11.3.1"/>
        <!-- (Other deps skipped) -->
    </ItemGroup>

    <ItemGroup>
        <EmbeddedResource Update="Resources\Language\Language.resx">
          <Generator>PublicResXFileCodeGenerator</Generator>
        </EmbeddedResource>
        <EmbeddedResource Update="Resources\Language\Language.en-us.resx">
          <Generator>PublicResXFileCodeGenerator</Generator>
        </EmbeddedResource>
        <EmbeddedResource Update="Resources\Language\Language.zh-hans.resx">
          <Generator>PublicResXFileCodeGenerator</Generator>
        </EmbeddedResource>
        <EmbeddedResource Update="Resources\Language\Language.ja-jp.resx">
          <Generator>PublicResXFileCodeGenerator</Generator>
        </EmbeddedResource>
        <EmbeddedResource Update="Resources\Language\Language.zh-hant.resx">
          <Generator>PublicResXFileCodeGenerator</Generator>
        </EmbeddedResource>
    </ItemGroup>

<!-- Skipped other confs -->

</Project>

and I am building it using:

 dotnet publish -c Release -r "$runtime" \
             -f "$framework_name" \
             -p:TrimUnusedDependencies=true

Could you give me some suggestions on how to resolve this? Thanks in advance!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions