Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unable to add localization for .NET MAUI app in VS Code on macOS due to the missing *.resx support #1545

Open
mariuszmatusiak opened this issue Oct 17, 2024 · 2 comments
Labels
area-maui bug Something isn't working delighter-sc

Comments

@mariuszmatusiak
Copy link

Describe the Issue

I am creating a .NET MAUI application on macOS (M1 Pro) in VS Code (due to the recently dropped support for Visual Studio for Mac).
I followed the official documentation https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/localization?view=net-maui-8.0 but since not using Visual Studio I was forced to add the *.resx file manually. I figured out the format by using the resgen port available in Mono (version 6.12.0.0). Unfortunately though my compilation fails due to the "Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'App.Resources.Languages' that could not be found." error thrown in the main page xaml definition
xmlns:strings="clr-namespace:App.Resources.Languages"
inside the ContentPage. After a thorough search, I then figured out that this might be due to the missing *.Designer.cs file which is normally generated by Visual Studio. I think resgen should also support its generation but the available Mono port version lacks this feature.
How can I proceed further in this case?

Redirected from the thread: dotnet/maui#25260 (comment)

Steps To Reproduce

  1. Create a new .NET MAUI project with command line for Visual Studio Code
  2. Follow the Localization guide in .NET MAUI documentation

Expected Behavior

Be able to create a proper *.resx file with *.cs code behind

Environment Information

macOS Sonoma v14.7
VS Code Version: 1.94.2 (Universal)
Commit: 384ff7382de624fb94dbaf6da11977bba1ecd427
Date: 2024-10-09T16:08:44.566Z
Electron: 30.5.1
ElectronBuildId: 10262041
Chromium: 124.0.6367.243
Node.js: 20.16.0
V8: 12.4.254.20-electron.0
OS: Darwin arm64 23.6.0
.NET MAUI Version: 8.0.91 SR9.1

@emaf
Copy link
Member

emaf commented Oct 17, 2024

This looks like a C# Dev Kit issue as there is no support for resx files for any project type.

@mariuszmatusiak
Copy link
Author

I have finally found a workaround by adding these blocks in app's .csproj:

<EmbeddedResource Update="Resources\Languages\Locale.resx">
<Generator>MSBuild:Compile</Generator>
<StronglyTypedFileName>Resources\Languages\Locale.Designer.cs</StronglyTypedFileName>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>App.Resources.Languages</StronglyTypedNamespace>
<StronglyTypedClassName>Locale</StronglyTypedClassName>
</EmbeddedResource>

<EmbeddedResource Update="Resources\Languages\Locale.pl-PL.resx">
<Generator>MSBuild:Compile</Generator>
<StronglyTypedFileName>Resources\Languages\Locale.pl-PL.Designer.cs</StronglyTypedFileName>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>App.Resources.Languages</StronglyTypedNamespace>
<StronglyTypedClassName>Locale.pl-PL</StronglyTypedClassName>
</EmbeddedResource>

It solves the compiling problem but the app language is not changed to Polish (pl-PL), even if I explicitly set Polish as the default language for the MAUI app in the macOS settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-maui bug Something isn't working delighter-sc
Projects
None yet
Development

No branches or pull requests

3 participants