Hello,
There is an official sample, you can refer to it- maui-samples/8.0/Fundamentals/Localization/LocalizationDemo at main · dotnet/maui-samples (github.com)
In which folder to create resource files.
If you follow this doc- Localization - .NET MAUI | Microsoft Learn, please create a folder named Strings
under Resources
folder, then create the resource file there.
You can use the Resources/Languages folder, and already inside the language resources.
You name the folder to Languages
, it's also allowed.
How to access static values in these files in C#, if what is written in the first empty is possible.
You could use it like the following:
Label notesLabel = new Label();
notesLabel.Text = AppResources.NotesLabel,// find the key in the AppResources.resx
replacing the namespace "LocalizationDemo" with your own, I still get an error
Because you set the name Languages
, please replace the Strings
with Languages
.
xmlns:strings="clr-namespace:XXX.Resources.Languages"
Update
You have created a Languages
folder, it's better to move the "AppResources" file there, and the namespace will be changed after moving the file in a folder.
then in the "Resources/Languages/AppResources.ru.resx" file these values can be translated into the appropriate language?
Yes, it will. Please follow the doc- Localization - .NET MAUI | Microsoft Learn to specify the app's neutral language and set the language of your machine, then you can see the translated text.
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.