Buttons with respective language

Windows specific forum
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Buttons with respective language

Post by Hroudtwolf »

Hello PB-World,

I want to make Buttons with the respective language of a country like in the requesters.

In Example:

Button in Window with german as systemlanguage ->Fertig<-
Button in Window with english as systemlanguage ->Finish<-


Do anyone knows a way to realize this?
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Use a ini file.

Make sure that you use

ReadPreferenceString("WINDOW_FINISH","Finish")

That way if a text is missing, it will default back to english.

Also you need to make a list() where the result of ReadPreferenceString() is put into.

Like:

list()=ReadPreferenceString("WINDOW_FINISH","Finish")


Use Enumeration to make the needed constants.
i.e #WINDOW_FINISH

Then simply make a procedure like this:

Procedure.s Lang(id.l)
SelectElement(list(),id)
ProcedureReturn list()
EndProcedure


Then to simply get/use the text for WINDOW_FINISH,
wether it is german on english or spanish being used.
Simply use:

Lang(#WINDOW_FINISH)

where you would normally have used

"Finish"

in your code.

Then just allow the user to choose in the program settings
what language he wish to use.
Using a INI would make it easy for people to make translations too.

I.e:

German.ini
Swedish.ini
etc.

Maybe make a Languages\ folder they could be in,
and then automatically list them in a selection box in the preference window.

Just some ideas for you.
Sorry I don't have any actual sourcecode,
but I bet it won't be long until someone makes some ready to use code for this,
or maybe there allready is?
Tension
User
User
Posts: 29
Joined: Tue Mar 22, 2005 3:19 pm

Post by Tension »

Use dictionary or pref or ini files, as Rescator suggests.

PureBasic is an example of using files for languages, see the catalogs folder in the PureBasic folder.

Also I think JaPBe has similar.

And check out PureVision as there may be a solution there for you. Not 100% sure of this though, or how it works. Just saw something about languages.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

In need it for a Requester-LIB.

I can't make an INI with all languages on the earth.
In the other dialog and requesters of Windows exists also buttons
with respective language of the system settings.

I need the API of Dialog-Buttons.

OK.
Finish.
Cancel
Yes
No.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Hmm. Yes Ok and so on are automatic.
And those are automatically changed.
A PB MessageRequester() Ok Yes button afaik should use the Windows API Yes text.

Just try to change the language of your computer to something else and you should see.

I have no idea how to "access" the Windows language database so you can use that text in your own program...

But anyway. for those interested, here is a working example of the thing I talked about. Maybe someone will find it interesting! :)

Code: Select all

Enumeration
 #L_WINDOW_FINISH   ;This should get the value 0
 #L_WINDOW_FAILED   ;This should get the value 1
                    ;etc etc.
EndEnumeration

NewList language.s()

OpenPreferences("Language\German.ini")
 ;Make sure the order of lines below match the enumeration above
 AddElement(language()) : language()=ReadPreferenceString("WINDOW_FINISH","Finish") ;Becomes entry 0 in list
 AddElement(language()) : language()=ReadPreferenceString("WINDOW_FAILED","Failed") ;Becomes entry 1 in list
 ;etc etc.
ClosePreferences()

Procedure.s lang(id.l) ;This is the routine that will fetch the language strings.
 SelectElement(language(),id)
 ProcedureReturn language()
EndProcedure


;Example:

MessageRequester("Test",lang(#L_WINDOW_FAILED))
In the German.ini file the language lines would be stored as:
WINDOW_FINISH=Fertig wohoo!
WINDOW_FAILED=Felen, bah!
etc etc.

Have fun!
Tension
User
User
Posts: 29
Joined: Tue Mar 22, 2005 3:19 pm

Post by Tension »

Post Reply