Jump to content

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 :)


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

Link to post
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 post
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 :



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 post
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 post
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

where language.ini is (for example):

My Program=Mon programme

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 post
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'

_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)
            IniWrite ("InitLang.ini", "Language", "Lang", "NAE")
            _FileReadToArray ("Lang.NAE", $aLang)

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 )

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


Link to post
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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...