dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.06k stars 1.73k forks source link

Unable to add localization for .NET MAUI app in VS Code on macOS #25260

Open mariuszmatusiak opened 4 days ago

mariuszmatusiak commented 4 days ago

Description

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?

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

Link to public reproduction project repository

No response

Version with bug

8.0.91 SR9.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

macOS Sonoma v14.7

Did you find any workaround?

No

Relevant log output

/usr/local/share/dotnet/packs/Microsoft.MacCatalyst.Sdk/17.2.8053/targets/Xamarin.Shared.Sdk.targets(297,3): warning : RuntimeIdentifier was set on the command line, and will override the value for RuntimeIdentifiers set in the project file. [/Users/mariusz/Projects/App/App.csproj::TargetFramework=net8.0-maccatalyst] Views/CreateProfilePage.xaml(13,62): XamlC XC0022 warning : Binding could be compiled if x:DataType is specified. [/Users/mariusz/Projects/App/App.csproj::TargetFramework=net8.0-maccatalyst] Views/CreateProfilePage.xaml(25,13): XamlC XC0022 warning : Binding could be compiled if x:DataType is specified. [/Users/mariusz/Projects/App/App.csproj::TargetFramework=net8.0-maccatalyst] Views/MainPage.xaml(30,16): XamlC error XFC0000: Cannot resolve type "clr-namespace:App.Resources.Languages:Locale". [/Users/mariusz/Projects/App/App.csproj::TargetFramework=net8.0-maccatalyst] 3 Warning(s) 1 Error(s)

similar-issues-ai[bot] commented 4 days ago

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

StephaneDelcroix commented 2 days ago

we do not maintain the tooling for this

dotnet-policy-service[bot] commented 1 day ago

Thanks for the issue report @mariuszmatusiak! This issue appears to be a problem with Visual Studio, so we ask that you use the VS feedback tool to report the issue. That way it will get to the routed to the team that owns this experience in VS.

If you encounter a problem with Visual Studio, we want to know about it so that we can diagnose and fix it. By using the Report a Problem tool, you can collect detailed information about the problem, and send it to Microsoft with just a few button clicks.

  1. Go to the Visual Studio for Windows feedback tool or Visual Studio for Mac feedback tool to report the issue
  2. Close this bug, and consider adding a link to the VS Feedback issue so that others can follow its activity there.
dotnet-policy-service[bot] commented 1 day ago

Thanks for the issue report @mariuszmatusiak! This issue appears to be a problem with Visual Studio (Code), so we ask that you use the VS feedback tool to report the issue. That way it will get to the routed to the team that owns this experience in VS (Code).

If you encounter a problem with Visual Studio or the .NET MAUI VS Code Extension, we want to know about it so that we can diagnose and fix it. By using the Report a Problem tool, you can collect detailed information about the problem, and send it to Microsoft with just a few button clicks.

  1. Go to the Visual Studio for Windows feedback tool or .NET MAUI VS Code Extension repository to report the issue
  2. Close this bug, and consider adding a link to the VS Feedback issue so that others can follow its activity there.
drasticactions commented 1 day ago

As mentioned by @StephaneDelcroix, this is unrelated to the MAUI UI Project. This is generic tooling handled by the runtime and to the best of my knowledge, MAUI does not handle Resx files any different than the runtime.

https://github.com/drasticactions/MauiLang/blob/main/src/MauiLang/MauiLang.csproj#L73-L78 https://github.com/drasticactions/MauiLang/tree/main/src/MauiLang/Translations My guess would be is you're missing the generator commands in your csproj. If you add those, then compile, it should generate the needed glue logic to get you what you need. If it still doesn't work, you should probably request this in VSCode or dotnet runtime.

mariuszmatusiak commented 1 day ago

Hi @StephaneDelcroix, @drasticactions Thanks for your insights. According to your suggestions, I registered a similar thread in the vscode-dotnet repository: https://github.com/microsoft/vscode-dotnettools/issues/1545 In the meantime, I will try the @drasticactions's suggestions though I've already tried similar approaches.