I have done a VB for small projects. Customers need software to support Chinese and English. I wrote an automatic language switching module. I don't dare to enjoy it. I will give you a reference. If you have any improvement Can write to me. . Mailto: tonyki@citiz.net module
MDLLANMGR.BAS: Attribute VB_Name = "MODULANMGR" Option Explicit
Private Declare Function GetPrivateProfileString & Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String)
Private languagefilename as string 'Choosing language
Public Sub SelectLanguage (Lanname As String) On Error Resume Next Select Case Lanname 'The name of the language selection, reads different language files "English": LanguageFileName = addsplash (app.path) & "English.lan" Case "Chinese (Simplify)": LanguageFileName = AddSplash (App.Path) & "ChineseS.Lan" Case "Chinese (Traditional)": LanguageFileName = AddSplash (App.Path) & "ChineseT.Lan" Case Else: LanguageFileName = " "End selected sub 'translation text
Public Function TranslateStr (sSection As String, sKey As String, sDefVal As String) As String Dim sValue As String * 128 Dim N As Long On Error Resume Next TranslateStr = sDefVal If Not FileExists (LanguageFileName) Then Exit Function End If N = GetPrivateProfileString ( SSECTION, SKEY, SDEFVAL, SVALUE, 127, LANGUAGEFILENAME) IF N> 0 THEN THENTESTR = Left (svalue, n) End (sValue, n) End (Svalue, N) End (SVALUE, N) End (SVALUE, N) End Function 'Automatically convert some basic controls on Form (can also be extended, currently support CommandButton, Label, Optionbutton CheckButton
Public Sub Translateform (FRM AS FORM) DIM I as Long On Error ResM.caption = Translatestr (FRM.NAME, "CAPTION", frm.caption) for i = 0 to frm.controls.count - 1 IF (TypeOf FRM .Controls (i) IS commandbutton or (TypeOf frm.controls (i) is label) _ or (TypeOf frm.controls (i) is optionbutton or (typeofffrontrols (i) is checkbox) THENFM.CONTROLS I) .caption = translatestr (frm.name, frm.controls (i) .name, frm.controls (i) .caption) End if next Ind Sub call is simple, written in the form of the program main window: Private Sub form_load () on error goto errfun language = "English" if FileExists (add.pLash (app.path) & "sys.ini") THEN 'The last setup language file name reads the last setup language file name Open AddSplash (App) .Path) & "sys.ini" for Input As # 1 Input # 1, Language Close # 1 End If SELECTLANGUAGE (LANGUAGE) 'Setting global variables, specifying the language translateform me' automatic conversion interface errfun: Resume Nextend Sub A similar way of writing is used in FormLoad, and the translateform (ME) is called to switch language text on the Form. Finally, the use of the language file format like this: [FormMain] Caption = PCTV PlayerLabelCmd1 = Start PlayLabelCmd2 = Edit Play ListLabelCmd3 = Options ... LabelCmd4 = HelpLabelCmd5 = ExitLabelCmd6 = Exit && Shut down computer