Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • Admin.resx
  • Admin.fr.resx
  • Admin.it.resx
  • Admin.de.resx

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!

like image 581
Steve Avatar asked Oct 10 '22 18:10

Steve


1 Answers

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);
}
like image 55
Steve Danner Avatar answered Oct 13 '22 09:10

Steve Danner