Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi Language problems

Status
Not open for further replies.

SteveGlover

Programmer
Mar 25, 2003
19
GB
Using the Resource editor I've set up a number of string tables for different languages. VB picks the string table to use by looking at the Regional setting of the PC, and in most cases this works fine. However, in a few cases I need to override the automatic selection. For example, the Region could be "Italian(Standard)" but I may want to force the App to use "English". How can I do this?
Thanks
 

I see by your other threads you have been trying for a year to get this working.

This is a slight problem with the VB resource file, as you cannot identify the LCID to use, and you cannot have more than one resource within the same project, at least not that I know of.

What I would suggest to do is to create two new different VB projects each with a different resource file: One just in English (not just the text, but also the country id selection is "English x") as default, and one with all languages (you can just copy the *.RES file and in the copy remove all other languages)
Every change made in the Multi-language resource file you will need to repeat the file copy and columns delete

Start two new seperate ActiveX Dll projects, each with their own resource file as mentioned above.

Add a public MultiUse class with some functions which act as wrappers for the VB resource loading functions(such as LoadResData) which extract the data from the resource file.
Create the Dlls each with a different name.

In your main project have a property to identify which resource dll to use, and then use CreateObject() to use the one desired, or set a reference to both dlls, , and call the class methods of that dll to get the ressource string.
 
>This is a slight problem with the VB resource file

No, the problem is firstly that there is no option to change locale within VB, and even if you do VB's LoadResString function fails to take account of it ...

Basically if you drop LoadResString and use the API version (which really isn't that much harder to use) instead then we can achieve the desired result.

Here is an example which assumes you have a RES file with at least two string tables (one being the default language, the other of which should be 'French (France)'). Then you need a command button. And the following code:
Code:
[blue]Option Explicit

Private Declare Function SetThreadLocale Lib "kernel32" (ByVal Locale As Long) As Long
Private Declare Function GetThreadLocale Lib "kernel32" () As Long
Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long

Private Sub Command1_Click()
    Dim result As Long
    result = GetThreadLocale ' save current thread locale
    MsgBox vbLoadResString(101) ' Ok, display current locale string
    SetThreadLocale (&H40C) 'Set locale of this thread to French (France) for this example
    MsgBox vbLoadResString(101) ' Now display French language string
    SetThreadLocale result ' Set locale back to original
    MsgBox vbLoadResString(101) ' Display string for original locale
End Sub

' Warning this replacement for the LoadResString only work's in compiled programs
' because of the use of App.hInstance in the LoadString function
Public Function vbLoadResString(id As Long) As String
    vbLoadResString = Space(256)
    LoadString App.hInstance, id, vbLoadResString, Len(vbLoadResString)
End Function[/blue]
Note that this will only work when the program is compiled as we are seeking the resources in t the application instance - and in the IDE they are not held in the app.

This trick can also be pulled for other localized resources in the VB RES file (bitmaps, icons, cursors, and other binary data)

 
>>This is a slight problem with the VB resource file

>No, the problem is firstly that there is no option to change locale within VB,

Isn't that what I mentioned, at leat what is meant, when the next part of the statement is considered?:
>... as you cannot identify the LCID to use


Anyways, the nice part about using dll solution is it prevents the VB RES from bloating the size of the Exe.
So using that, a single resource dll, in conjunction with SetThreadLocale, seeems to be a nice overall solution for a VB Resource file.
 
Ah, but the implication in your original post seemed to be that the issue was a shortcoming of the VB RES file functionality, which it isn't. I'm sorry if I misinterpreted what you were saying.
 
I see what you mean - bad wording on my part. Where I said "cannot identify " you said "no option" and that was the same for me in this manner and how I meant it. Sorry about the misunderstanding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top