开发者

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

开发者 https://www.devze.com 2023-04-12 07:57 出处:网络
I have a project that has translations in multiple .resx files. e.g. Admin.resx Admin.fr.resx Admin.it.resx

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!


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号