2

On my home PC using Google Chrome (28.0.1500.72m version) I can't enter non-English text into Silverlight application TextBox: I can switch keyboard and I see it is changed in the mini-tray, but when I press any key on the Keyboard I keep receiving English characters. If I enter non-English text in other application (NotePad), copy it, and paste into my silverlight control - it is copied properly.

In the same time:

  • Everything works in IE
  • I was able to find other silverlight apps that allows enterring text in non-English language

Why that happens and how to resolve and enable entering non-English characters the problems?

P.S. I have following environment configuration:

  • OS: Windows 8, x64
  • locally installed 5.1.20513.0 x64 version of Silverlight
  • the SilverLight application itself is compiled using VS2012, update 3
  • the SilverLight application it is written using Silverlight 4.

P.P.S. Same problem reported by other Google Chrome users.

Budda
  • 18,015
  • 33
  • 124
  • 206

2 Answers2

2

I have changed the Regional Settings in my computer to Russian and have observed that VS 2010 delivers the expected performance for all the situations (SilverLight, ASP, winforms). Note that I have done my tests with Chrome (same version than yours) and Windows 7. I don't know why happens the error you report.

What you can do is making sure that your application will always output Russian characters, independently upon the exact configuration in the target machine. I found a quite interesting post on this front.; the option I like the most is the first one: relying on a conversion dictionary. Applied to your case, it would be something like this:

Dictionary declared globally:

Dictionary<string, string> enToRus;

Function called at Form Load populating the aforementioned dictionary:

private void populateDict()
{
    enToRus = new Dictionary<string, string>();
    enToRus.Add("P", "П");
    enToRus.Add("e", "e");
    enToRus.Add("t", "т");
    enToRus.Add("r", "р");
    //etc.
}

Method (on textBox1 TextChanged Event) dealing with the character replacement in case of being applicable.

private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
    textBox1.Select(textBox1.Text.Length - 1, 1);
    if (textBox1.SelectedText.Trim().Length > 0)
    {
        if (!enToRus.ContainsValue(textBox1.SelectedText) && enToRus.ContainsKey(textBox1.SelectedText))
        {
            textBox1.SelectedText = enToRus[textBox1.SelectedText];
        }
    }
    textBox1.Select(textBox1.Text.Length, 1);
}

Bear in mind that it comes from a pretty simplistic approach (checks whether the given character is not listed within the Russian ones before performing the change) which might drive to not so accurate results. I don't have any Russian knowledge (neither understand the exact conditions under which the problem you refer appear) and thus cannot be of further help on this front; but I guess that you will not find any problem to improve the accuracy of this pre-analysis (deciding when a character should be replaced).

Community
  • 1
  • 1
varocarbas
  • 12,354
  • 4
  • 26
  • 37
  • Changing regional settings helped... Thank you! But now I can't enter English :) Solution is better than nothing, but not an ideal. Don't really like idea to do text conversion on the fly, but that could be an option. – Budda Jul 21 '13 at 02:23
  • @Budda sorry about that but I don't have more ideas. From my tests, I would recommend you to rely on VS 2010 to be completely sure (as far as it seems to work perfectly). If the default configuration fails anyway, the only option you have is changing characters on the fly (as you can see in my code, the process is really quick). Regarding the character-changing methodology, I did some research on this front but couldn't find anything better than what I have proposed. – varocarbas Jul 21 '13 at 08:01
  • @Budda sorry but perhaps I haven't understood your point properly: you are saying that the regional settings in your computer weren't set to Russian language? You can only type Russian characters if your regional settings are set to Russian (I guess that you know that). Everything in my computer is in Spanish, when I changed the regional settings into Russian, all what I typed were Russian characters. For example, when I tried to write a code in the VS, Russian characters appeared and thus everything was an error (because my VS recognises only western (or whatever the name) characters). – varocarbas Jul 21 '13 at 08:21
  • @Budda bear in mind that what appears in the screen after each key stroke is defined by the regional settings. For example, with my Spanish keyboard + Spanish regional settings, if I type @, it appears @; if I change my regional settings to English, for example, when I press the @ key other symbol appears because, in English keywords, the @ is somewhere else. If despite your regional settings, you want to show different characters, the only way is the proposed replacement; or, eventually, a local (to the app) regional-settings-change which I am afraid that is impossible. – varocarbas Jul 21 '13 at 08:37
  • @Budda ... or you might do a replacement based on the key being pressed rather than on the text displayed. But a replacement is required in any case as far as what you want is displaying different characters than what the corresponding regional settings are instructed to deliver. But I am afraid that there is no error in VS/Silverlight (if I have understood your point properly). – varocarbas Jul 21 '13 at 08:41
0

Silverlight has somewhat limited globalization support. In particular, you might need to set Thread.CurrentThread.CurrentUICulture to a Russian culture (like this):

// Change the current and current UI culture to ru-RU (Russian).
CultureInfo ruCulture = new CultureInfo("ru-RU");
Thread.CurrentThread.CurrentCulture = ruCulture;
Thread.CurrentThread.CurrentUICulture = ruCulture;
Eric Brown
  • 13,774
  • 7
  • 30
  • 71