Steve
Steve

Reputation: 2997

Programatically finding if an alternative translation exists or not in a .resx file

I have a project that has translations in multiple .resx files.

e.g.

Does anyone know of a way to programatically find out if a translation that exists in the default fallback, doesn't exist in the alternative language file?

I hope that makes sense!

Upvotes: 5

Views: 1853

Answers (1)

Steve Danner
Steve Danner

Reputation: 22158

This should do what you want.

public static bool StringExistsInCulture(string key, CultureInfo ci)
{
   ResourceManager resources = new ResourceManager(typeof(Admin));
   string defaultString = resources.GetString(key, CultureInfo.InvariantCulture);
   string transString = resources.GetString(key, ci);

   return (defaultString == transString);
}

Upvotes: 4

Related Questions