Jump to content

Multi language


Recommended Posts

According to you, which is the most effective manner to have an interface in several languages ?

1 - To open a file in which are contained the various sentences in various languages ?

$langue_langue = FileOpen("langue.langue", 2)
Dim $langue_ligne1, $langue_ligne2 
$langue_ligne1 = FileReadLine($langue_langue, 1)
$langue_ligne2 = FileReadLine($langue_langue, 2)
MsgBox(0 + 16, "Nadia - " & $langue_ligne1, $langue_ligne2)

2 - To create different scripts reacting correctly at the requests of language?

-----> Gui for select a language ------> Start de GUI with the required language

3 - Another manner ?

Thank you for your opinions and your examples :)

Groumphy

----------------------GroumphyMore information about me [Fr]

Link to comment
Share on other sites

Something like the first one.

Dim $arCaption

$Language = "English"
_FileReadToArray($arCaption, $Language & ".txt")

Not sure about the FileReadToArray syntax, but something like that.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Hi Groumphy !

In a script Im coding Ive added support for the user to select between several languages to be used in a GUI.

As well as easily add new languages. The way this is done is by using a INI-file which looks something like this :

[settings]
language=Norwegian

[L:Norwegian]
hello=hallo
name=navn
age=alder

So when the script starts up, it sets some variables with the default text as value (English in my script).

It then INIReads the LANGUAGE-key in the SETTINGS-section, and the use this key to see if there

is a valid INI-section with that value (starting with "L:" just to make it more systematic), and checks

if all the required keys are filled in. If it is a valid languge-section it overwrites the variables with the new values.

Understand ? :)

Link to comment
Share on other sites

Thank you for your assistance, but unfortunately I does not understand.

How can I make go automatically script to the good language ?

How can I incorporate the variables in script?

Can you give a simple (most easyly for you) ?

For the moment, I use the opening of a file which I read, line by line...

----------------------GroumphyMore information about me [Fr]

Link to comment
Share on other sites

In one my script I have used very simple translation method (it's fairly similar Helge's method):

Dim $inifile = "language.ini"

MsgBox (0, "Translated", LocStr("My Program"))

Func LocStr($str)
    Local $ret = IniRead($inifile, @OSLang, StringStripWS($str, 3), $str)
    If $ret = "" Then Return $str
    Return $ret
EndFunc

where language.ini is (for example):

[040C]
My Program=Mon programme

[0419]
My Program=Моя программа

If string is not found then default string will be returned.

One possible disadvantage of this method - frequently access to ini file every time when string need to be translated.

Language codes you can find in the Appendix of Autoit help file.

Link to comment
Share on other sites

3 - Another manner ?

I prefer using an array to read from the file. It's much quicker than reading and evaluating line by line.

Here is an example I wrote in about 5 min.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Kerberuz
;
; Script Function:
;   Lang Switcher
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <File.au3>
#include <GUIConstants.au3>
Dim $aLang

$Lang = Iniread ("InitLang.ini", "Language", "Lang", "")
If $Lang = "" Then
    $Lang = 'NAE'
EndIf

_FileReadToArray ("Lang." & $Lang, $aLang)

$GuiName = GUICreate(StringReplace($aLang[1], @CR, ""), 200, 200)

$Label1 = GUICtrlCreateLabel($aLang[2], 10, 20)
$Label2 = GUICtrlCreateLabel($aLang[3], 10, 50)
$Label3 = GUICtrlCreateLabel($aLang[4], 10, 80)
$Label4 = GUICtrlCreateLabel($aLang[5], 10, 110)
$Label5 = GUICtrlCreateLabel($aLang[6], 10, 140)
$Switch = GUICtrlCreateButton("Language is " & $Lang, 10, 170)

GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $Switch Then
        if $Lang = 'NAE' Then
            IniWrite ("InitLang.ini", "Language", "Lang", "EUG")
            _FileReadToArray ("Lang.EUG", $aLang)
            SwitchLang()
        Else
            IniWrite ("InitLang.ini", "Language", "Lang", "NAE")
            _FileReadToArray ("Lang.NAE", $aLang)
            SwitchLang()
        EndIf
    EndIf
Wend

Func SwitchLang()
    $Lang = Iniread ("InitLang.ini", "Language", "Lang", "")
    WinSetTitle ( $GuiName, "", StringReplace($aLang[1], @CR, "") )
    GUICtrlSetData( $Label1, $aLang[2])
    GUICtrlSetData( $Label2, $aLang[3])
    GUICtrlSetData( $Label3, $aLang[4])
    GUICtrlSetData( $Label4, $aLang[5])
    GUICtrlSetData( $Label5, $aLang[6])
    GUICtrlSetData( $Switch, "Language is " & $Lang )
EndFunc

Here are examples of the lang files I built, but they could be much more elaborate.

Save this as Lang.EUG

German Language
German Elements
German Dog
German Fish
German Smurf
German Water

Save this as Lang.NAE

English Language
English Elements
English Dog
English Fish
English Smurf
English Water

Kerby

Link to comment
Share on other sites

Ok, I understood too !

Your script is preferential on large scripts, but here, the preceding method (LazyCat) is adapted better to script than I builds (simple script to build and generate a file via a GUI and to print this last on the default printer of the computer).

I keep your method for scripts more complete !

Thanks for you help !

be Groumphy

----------------------GroumphyMore information about me [Fr]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...