0

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))

Freerk92
  • 55
  • 1
  • 9
  • It should work, maybe your current values aren't refreshed? Why do you think it doesn't work? Do you get any errors? – Gerald Versluis Jul 24 '18 at 13:58
  • No errors, in debug my CultureInfo is nl-NL, but I'm getting the default texts (english) – Freerk92 Jul 24 '18 at 14:05
  • 1
    Are you setting the culture on the `AppResources.Culture`? See also: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/text?tabs=vswin – Gerald Versluis Jul 24 '18 at 14:09
  • Found the problem thanks to your link. The problem was that i'm stupid and forgot to set the build action of the files to EmbeddedResource – Freerk92 Jul 24 '18 at 14:17
  • Haha it happens to the best of us! If you don't mind I will update it to an answer for future reference :) – Gerald Versluis Jul 24 '18 at 14:18

1 Answers1

1

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

Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100