xamarin.formsresourcescultureinforesourcemanager

using TwoLetterIsoLanguageName for ResourceManager


I have 6 resource files for 6 different languages (En, Nl, De, Es, It, Fr). I'm getting the string with ResourceManager.GetString, but it only seems to work if the AppResources file has the full en-EN, fr-FR etc.

Is it possible to name the files AppResources.es.resx, instead of es-ES, so it works in Spain and Mexico, or fr instead of fr-FR so it works for France and Canada?

The following solution was something I've tried, but it didn't seem to work:

ResourceManager.GetString(Text, new CultureInfo(cultureInfo.TwoLetterISOLanguageName))


Solution

  • The TwoLetterISOLanguageName should work just fine.

    Please check if you set the Culture on the AppResources so the values are enforced in your app, even if the device's locale is different.

    From our discussion in the comments, it turns out that the problem was that your resource files didn't have the right built action. Don't forget to set your resx files to Custom Tool: ResXFileCodeGenerator.

    Also see the documentation at https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/text?tabs=vswin