简体   繁体   中英

.net localization - throw exception in hebrew on englisch operating system

I have an application that is translated into hebrew besides english and german.

To check the user input, i created a Validation rule that throws an ArgumentOutOfRangeException if the value exceeds it's limits.

public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
  double validationValue = 0;
  validationValue = double.Parse(value.ToString());

  if(validationValue < Min)
  {
    ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException();
    return new ValidationResult(false, ex.Message);
  }
  else if(validationValue > Max)
  {
    ArgumentOutOfRangeException ex = new ArgumentOutOfRangeException();
    return new ValidationResult(false, ex.Message);
  }

  return new ValidationResult(true, null); 
 }

The validation is working.
However, if i set the application language to hebrew by using CultureInfo.DefaultThreadCurrentCulture and CultureInfo.DefaultThreadCurrentUICulture I get an english exception. Setting the language to german or english, I get the correct exception message. The operating system is Windows 7 english.

  • Does the text of the exception depend on the installed languages of the OS?
  • Can I resolve the problem by installing the hebrew Language pack (only for Win 7 Enterprise/Ultimate Edition)?

I tried to set the region to Israel, but I cannot install the hebrew LP on my current test environment.

I found threads where people said that exceptions should not be translated. I could use my internal localization service to throw my specific exception with the translated text. But if there is a chance, I would like to avoid this.

The .Net language pack is working. Although i refactored my validation rule. A custom message is now returned if the value is out of the range.

  • I can include the minimum and maximum of the possible value.
  • Future translations are not dependent on installed .NET language packs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM