[RESOLVED] Including Russian Cyrillic characters in VB-code
Hi,
My app supports dynamic switching between various languages. All translated texts are available through external language files, that are loaded when the specific language is selected.
The welcome screen that is displayed the first time that the app is started allows the initial selection of the language (as part of various settings). As soon as the user selects a language, all texts/controls in the dialog are displayed in the selected language. To make this happen instantly, the texts on the dialog (5 strings for each available language) are included as constants in the code. This works perfectly fine with western languages as English, Dutch, German, Italian, and French.
Now I’m trying to include Russian with the Cyrillic character set. Loading the texts from a file and the applying to all controls works fine, obviously with all the required settings of fonts and character sets for each control, but I can’t figure out how to include the welcome-screen strings as constants in the VB-code.
Is this possible at all? If so, any suggestions on how to do that?
Re: Including Russian Cyrillic characters in VB-code
Originally Posted by Erwin69
Is this possible at all? If so, any suggestions on how to do that?
Store the welcome screen text as string resources instead of string constants.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Re: Including Russian Cyrillic characters in VB-code
Hi Bonnie,
Thanks for pointing me in the right direction. Unfortunately, it doesn't work yet though...
As the VB6 resource editor doesn't allow me to copy/paste the Russian texts (all characters change into ?) I decided to go the "external" route: I created a stringtable in a resource file with Notepad. Saved it in Unicode format with extension rc. Then compiled it with RC.EXE, and added it to my project.
Now when I assign the texts using the LoadResString function, I still get all questionmarks. The font/charmap settings for the controls are correct, as it displays Russian characters when they're loaded from a text-file.
What am I missing? Any suggestions would be greatly appreciated!
Re: Including Russian Cyrillic characters in VB-code
Have you considered using Unicode aware controls?
That way you won`t have to worry about Font/CharSet.
And your Unicode Cyrillic resource file should work just fine.
See: http://www.vbforums.com/showthread.p...=1#post4277565
Re: Including Russian Cyrillic characters in VB-code
There is an alternative. I hesitate to mention it because it is quite a hack but it does work for the most part.
If you take some Russian text in Unicode, then translate this to ANSI using the correct Russion codepage value (1251), then take that ANSI and translate it back to "Unicode" this time using the IDE's codepage...
.. you get text that can be pasted into VB6 as a String literal.
This allows you to use something on the order of:
Code:
Private Sub lstLanguage_Click()
With lblPain
.Font.Charset = Choose(lstLanguage.ListIndex + 1, _
ANSI_CHARSET, _
ANSI_CHARSET, _
RUSSIAN_CHARSET)
.Caption = Choose(lstLanguage.ListIndex + 1, _
"My butt hurts.", _
"Mes maux de bout.", _
"Ìîé æèâîò áîëèò.")
End With
End Sub
Of course the trick is running the text through that set of translations. For that you can cobble together a translator program as in my AnsiWarp utility (included in the attached archive).
You need a Unicode textbox of some sort, so here I just used the standard InkEdit control that is included in Windows from Vista forward. If you are stuck on XP yet, this should also still be available as an XP add-on from Microsoft, at least in the crippled inkless form.
Or you could substitute some other Unicode-aware textbox alternative.
Re: Including Russian Cyrillic characters in VB-code
Using Unicode aware controls is the plan for the next big update of the application. So your link above is greatly appreciated!
The app currently supports on-the-fly switching between English, French, German, Italian and Dutch. Russian is the first step into non-western languages. The translations for each language are in an external file, to allow language updates to be done without requiring a recompile of the software. The welcome screen, displayed only at first startup, is an exception. The translations (effectively 5 labels) are included in the code. This is where my problems started.
The local Russian team is doing the translations, and have sent me a unicode-textfile with the 5 lines for the welcome screen. If I do a simple load using "Open For Input", and assign the texts to the labels, they display correctly. If I copy them from Notepad and paste them in the VB IDE they're all changed into ?????. Hence the route through the resource file. The issue is that the file compiles well, yet doesn't display the Cyrillic characters. So I was wondering if I should be using something else than the LoadResString function to get the texts out of the resource file correctly.
Re: Including Russian Cyrillic characters in VB-code
Oops, I thought the question was:
Originally Posted by Erwin69
Loading the texts from a file and the applying to all controls works fine, obviously with all the required settings of fonts and character sets for each control, but I can’t figure out how to include the welcome-screen strings as constants in the VB-code.
Is this possible at all? If so, any suggestions on how to do that?
Re: Including Russian Cyrillic characters in VB-code
Thanks for the little "hack" dilettante! That worked perfectly fine for the handful of words that I'm dealing with in this case. I can now wrap this up as a "beta 1" so that the guys can start testing their translations, buying myself some time to investigate the unicode controls to see if I may implement those even quicker than originally scheduled.
Re: Including Russian Cyrillic characters in VB-code
Originally Posted by dilettante
It's always good to have time to investigate long-term alternatives.
My problem was that when I pasted Russian or Japanese characters to Microsoft Visual Basic 6 Resource Editor when creating a resource (.RES) file, the characters would appear as question marks (?) both in Resource Editor and when I displayed them on a computer with Russian or Japanese locale, respectively, using the resource DLL that I build from the RES file through MSVB6. However, if I added the characters to the resource file by pasting them into Resource Hacker <http://www.angusj.com/resourcehacker>, the characters still would display as question marks in MSVB6 Resource Editor, but would display correctly on a computer with appropriate locale after I built the resource DLLs through MSVB6.
Re: [RESOLVED] Including Russian Cyrillic characters in VB-code
by pasting them into Resource Hacker
There is a much better way.
Just create a resource file with Notepad and save as Unicode (Ex: UnicodeStrings.rc).
Compile with Rc.exe which should be in folder C:\Program Files (x86)\Microsoft Visual Studio\VB98\Wizards\RC.EXE
Then you can use LoadResString in Vb6 and it will load strings as Unicode.
You must have a Unicode control though to display them.
but would display correctly on a computer with appropriate locale
If you use Unicode controls it is not required to set locale, it works with all Locales.
If you plan on making a multilanguage app you need Unicode controls so that you don't need to fiddle with Locales.