Westwind.Globalization
Set default resource text when user's selected language has no value
Gravatar is a globally recognized avatar based on your email address. Set default resource text when user's selected language has no value
  Greg
  All
  Dec 6, 2018 @ 02:09pm

Hello,

I would like to be able to set the default culture to retrieve a resource from when the user's current culture does not have a value.

For Example:

  • ResourceKey = HelloWorld

  • UserCurrentCulture = en-US

  • Value for en-US does not exist

  • Value for en-CA = "Hello World"

If a user's culture is set to en-US and there is no associated value with that resource key for en-US, it only shows the resource key in the UI. I would like to auto default to a different culture like en-CA if the value does not exist for the user's current culture.

Does this package support that? Or do I need to do find a way to do some magical hacks?

Thanks!

Gravatar is a globally recognized avatar based on your email address. re: Set default resource text when user's selected language has no value
  Rick Strahl
  Greg
  Dec 7, 2018 @ 01:41am

No that scenario you describe (en-CA falls back to en-US) doesn't work because that's not how .NET resource fallback works.

The way you can do this is to set up your languages like this:

  • en
  • en-US
  • en-CA

Add only things that actually differ to the specialized languages - the bulk of the translation goes to the generic language. Then when something is missing fallback happens to the generic language. So if you have value in en they'll work for either en-US or en-CA if they are missing.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Set default resource text when user's selected language has no value
  Greg
  Greg
  Dec 7, 2018 @ 07:00am

Thanks for confirming Rick. Awesome package, I will set up the resources in this way and it should achieve the desired result. It's okay that it won't do a fallback to another language, as long as there is a generic version I can use, which you said is en. I will give it a shot.

© 1996-2018