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 |2 Answers
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
版权声明:本文标题:Use resx files for localization in .NET 9 Maui - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741253554a2366240.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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