1

I need for an if or switch statement the current name. I couldn't find a solution.

This code doesn't work.

        if (Thread.CurrentThread.CurrentCulture == new CultureInfo("en"))
        {
            // EN (default)
        }

        if (Thread.CurrentThread.CurrentCulture == new CultureInfo("de"))
        {
            // DE
        }
AxelS
  • 314
  • 1
  • 4
  • 11
  • 1
    Eh, `Thread.CurrentThread.CurrentCulture.Name`? Yet anther possibility is `Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName` (depending on what you mean "CultureName") – Dmitry Bychenko Aug 27 '15 at 15:52

1 Answers1

4

Depending on what you mean as "CultureName"

  // "ru-RU" on my workstation: Russian language (Russia dialect/subculture)
  String name = Thread.CurrentThread.CurrentCulture.Name;
  // "ru" - just Russian
  String isoName = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;

So in your case

  // German, Germany (and not Austria)
  if (Thread.CurrentThread.CurrentCulture.Name.Equals("de-DE")) {
    ...
  }
  else if (Thread.CurrentThread.CurrentCulture.Name.Equals("de-AT")) {
    // German, but Austrian subculture
    ...
  }

or

  // German, any subculture, dialect ect.
  if (Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Equals("de")) {
    ...
  }
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
  • Thanks :-) Sorry, I mean the language of current language of application and not from system. I use System.Speech.Synthesis. `synth.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Senior, 12, CultureInfo.CreateSpecificCulture("en"));` Your example is for current system language. – AxelS Aug 27 '15 at 16:20