Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Localization not working in .NET Maui Android project in combination with installing nuget package

$
0
0

I have 2 projects:

  • A library project (Home.BudgetPlanner.Data) containing some resource files with strings in the folder Localization. For example: TransactionType.resx and TransactionType.nl-BE.resx containing both the strings Expense and Income. This project is exported as a package.
  • A .NET Maui project (Home.BudgetPlanner.Mobile) with platforms Android and Windows. In this project the library package is installed.

But, when when the culture is set to nl-BE in my .NET Maui project, and I want to retrieve the dutch value of Home.BudgetPlanner.Data.Localization.TransactionType.Expense, I get the default english string.

cultureInfo = new CultureInfo("nl-BE");Thread.CurrentThread.CurrentCulture = cultureInfo;Thread.CurrentThread.CurrentUICulture = cultureInfo;CultureInfo.DefaultThreadCurrentCulture = cultureInfo;CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;var x = Home.BudgetPlanner.Data.Localization.TransactionType.Expense; // english string but expecting dutch value

This problem happens only on the Android platform. When I deploy to the Windows platform there is no problem.

Also, it looks like it is a package related problem in combination with Android. The problem only happens when I install Home.BudgetPlanner.Data as a package in my .NET Maui project. When I manually add a reference to the exported Home.BudgetPlanner.Data.dll (using project reference) it works.

When I add resource files in .NET Maui project itself, localization works also. So I think this problem is specific a combination of Android and localization in a package.

Does anyone else have this same problem?

I am using Microsoft Visual Studio Professional 2022 (64-bit) Version 17.6.2.

I have checked if resource file names and content are correct.

Added in csproj file:

<GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>

Added ConfigChanges.Locale in Android MainActivity class:

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, AllowEmbedded = true, ConfigurationChanges = ConfigChanges.Locale | ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]public class MainActivity : MauiAppCompatActivity

Tested it also on a physical device, with the same result.I also changed the language of my device to dutch without any result. I have added also next to nl-BE, nl resource files, maybe because my phone was set to nl instead of nl-BE. But that did not help either.


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>