Jump to content

Setting up language packs


James
 Share

Recommended Posts

I was thinking about this earlier so I tried it.

I was thinking of making language packs. This is how it would work.

There would be an .ini file named "languages.ini" and it would be set up like:

[English]GuiName=EnglishGui

File1Name=EnglishFile1

etc

etc

[French]

GuiName=FrancaisGui

File1Name=Francais

etc

etc

Then you would make a function which would read the Keys and set $GUI to what ever the value is.

It's hard to explain, but I have tried my best.

The GUI of the program would be:

#include <GUIConstants.au3>

$GUI = GUICreate(LanguagePacks("English", ($GuiLang), "1"))), 378, 304, 193, 115)
$MenuItem3 = GUICtrlCreateMenu("")
$MenuItem2 = GUICtrlCreateMenu("")
$MenuItem1 = GUICtrlCreateMenu("")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

If you don't understand then I can try and explain again.

Secure

Edit: I forgot the question and why it would be used :) The question is, how would I make it read everything? And th reason, is so that programs can be used all the time, in all languages.

Edited by Secure_ICT
Link to comment
Share on other sites

How about having three arrays... Number one contains the default text for the controls, the second

contains the key-names for the INI-sections and the third contains the corresponding controlIds.

Start by setting the default text for the controls, by For/Next-looping the first and the third array.

When you want to change the language you just loop through the second array and checks every

INI-keys there. By setting INIRead's 4th parameter to "" you'll catch both if the key is missing and

if it has no specified value. So, if there's a blank key-value you skip it and leave the control's text

as it is, but if ain't you update the control, using the controlId contained in the third array.

Might become messy if you're thinking of frequently updating the arrays, making it hard to ensure

that they're actually corresponding but this was the first thing that came to my mind. It's effective,

short but as I said it could become messy if lengthy. Example for updating text at language-change :

For $i = 0 To Ubound($keynames) - 1
    
    $text = IniRead("language.ini", $langname, $keynames[$i], "")
    If $text <> "" Then GUICtrlSetData($controls[$i], $text)
Next
Edited by Helge
Link to comment
Share on other sites

Wow, ok, thats complicated. Would you show me where that would go? This is more difficult than I though it would be :S

It's not really that complicated, it's just that I'm not too good in wording my thoughts. I could make it easier for

me by explaining it in Norwegian but that wouldn't help you too much. I could show a simple example, but that

would have to wait about an hour as I'm on my way out... We'll see.

Link to comment
Share on other sites

Wow, ok, thats complicated. Would you show me where that would go? This is more difficult than I though it would be :S

I know there are better way. This is an example, it may give you an idea...

LanguageTest.au3

I couldn't attach the Language.ini file.

[English]

String_1 = Language Test

String_2 = Ready

String_3 = &File

String_4 = Open

String_5 = Help

String_6 = Save

String_7 = Info

String_8 = Exit

String_9 = Recent Files

String_10 = View

String_11 = Statusbar

Stirng_12 = This is just a test of how to switch language.....

String_13 = Select Language

String_14 = OK

String_15 = Cancel

String_16 = Choose file...

String_17 = Only a test...

[spanish]

String_1 = Prueba De Lenguaje

String_2 = Listo

String_3 = &Archivo

String_4 = Abrir

String_5 = Ayuda

String_6 = Guardar

String_7 = Info

String_8 = Salida

String_9 = Reciente Archivos

String_10 = Mirrar

String_11 = Barra de information

Stirng_12 = Esto es una prueba como cambiar idomas

String_13 = Seleccione Idiom

String_14 = OK

String_15 = Cancelar

String_16 = Selccione Archivo...

String_17 = Solamente una prueba...

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Here it goes... I made a Norwegian translation of the File-menu for notepad, and I also included

the English as well, just for the heck of it.

I made it as simple as possible so there's no selecting of languages GUI-wise for example...

It shouldn't be too hard to add though... Personally I would prefix all language- sections with "L:",

use IniReadSectionNames to get all sections and then filter out those not starting with the prefix.

I would then add them to a menu, use GUICtrlSetOnEvent on the items and then in the event-

function pass LangSet the value of GUICtrlRead(@GUI_CTRLID, 1).

I never use onEvent-mode, but I believe it will work...also I think remember seeing you use it

so there's no need to rewrite anything on your side. Hopefully it's less complicated now after you

see it in action.

EDIT : changed to onEvent-mode and added my suggestions mentioned above.

Edited by Helge
Link to comment
Share on other sites

Though wouldn't this method be limited as you would have to input every word in the entire language, or at least a great deal of them?

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

That's why I have many bi-lingual friends. They said they would do translations :D

Yeah that too, but I meant on size of the file :)
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
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...