admin管理员组

文章数量:1287487

I want try to use .resx files for localization in my .NET 9 Maui app. My resource file is in the Resources folder like:

/Resources/Languages/Resources.en.resx

with a key "title".

I try to access this in my views as follows:

xmlns:lang="clr-namespace:MyApp.Resources.Languages"
Title="{x:Static lang:Resources.title}">

It tells me the CLR namespace could not be found. For some reason in .NET 9, you can't access the Resources folder like this anymore.

I already tried various approaches I found on Stackoverflow, but it seems be a .NET 9 specific problem.

I'd be happy if anyone could tell me how to use localization in .NET 9 MAUI apps.

EDIT - Solution For some reason in net9 it has to be named AppResources like AppResources.de.resx which is not clear by documentation (at least at this momenta)

I want try to use .resx files for localization in my .NET 9 Maui app. My resource file is in the Resources folder like:

/Resources/Languages/Resources.en.resx

with a key "title".

I try to access this in my views as follows:

xmlns:lang="clr-namespace:MyApp.Resources.Languages"
Title="{x:Static lang:Resources.title}">

It tells me the CLR namespace could not be found. For some reason in .NET 9, you can't access the Resources folder like this anymore.

I already tried various approaches I found on Stackoverflow, but it seems be a .NET 9 specific problem.

I'd be happy if anyone could tell me how to use localization in .NET 9 MAUI apps.

EDIT - Solution For some reason in net9 it has to be named AppResources like AppResources.de.resx which is not clear by documentation (at least at this momenta)

Share Improve this question edited Feb 25 at 5:28 Dura asked Feb 24 at 16:21 DuraDura 832 silver badges12 bronze badges 2
  • we use a custom translation markup extension – Jason Commented Feb 24 at 16:53
  • I cannot see any issue with what you posted. Perhaps you can share more information. Show the entire ContentPage declaration. It would be a bonus if you could upload your project to GitHub and share a link. – Stephen Quan Commented Feb 25 at 0:57
Add a comment  | 

2 Answers 2

Reset to default 2

.NET MAUI 9 localization handles things a bit differently.

In your case, .xaml is expected to look like something below assuming the resource file is named as AppResources.

<ContentPage ...
    xmlns:strings="clr-namespace:<your-project-name>.Resources.Languages">
...
    <Label Text="{x:Static strings:AppResources.title}"/>

Localization - Best Practices

(Not sure if it's ok on stackoverflow to add additional question to my original question, but opening a new thread sesms like overkill)

I was researching best-practices for localization files, but couldn't find anything useful:

Any advices how to structure these files, naming conventions, etc... (Maybe real-life repos examples - couldn't find any either)

Currently it looks something like this:

 <data name="view_list" xml:space="preserve">
        <value>My List-View Title</value>
    </data>
    <data name="view_list_button_add" xml:space="preserve">
        <value>My List-View add button text</value>
    </data>
    <data name="view_list_headding1" xml:space="preserve">
        <value>My List-View Heading One</value>
    </data>
    <data name="view_list_headding2" xml:space="preserve">
        <value>My List-View Heading Two</value>
    </data>

... and so on. And like this for 3 languages.

本文标签: Use resx files for localization in NET 9 MauiStack Overflow