Page 1 of 1
Multiple languages
Posted: Mon Jul 03, 2006 10:17 pm
by srod
Hi,
can anyone advise on writing a program to target more than one language? Afraid I have no experience with this.
My first idea is to place all strings (messages, titles, gadget captions etc.) within a file (preference file???) which the program will then access on startup etc. This file could then be translated into multiple languages etc.
Is this a reasonable way of proceeding? If so, should I read the entire contents of the language file into memory at program startup, or should I access it as needed?
Of course, this also raises the question of whether I should compile in unicode mode - again something I have no experience with.
Any advice gratefully received.
Thanks.
Posted: Mon Jul 03, 2006 11:15 pm
by GeoTrail
It doesnt matter what format you use, ie ini, preference or just plain text file.
I usually make an english language file that I compile inside the exe. But also include the english lang file with the published program. So when the program starts, it automatically reads from the english lang file. Should all lang files be missing, it will read the internal language file, that way you are sure not to have a "wierd" looking app if the user deletes them or something like that.
I don't have any experience with unicode files so I can't really give you any advice there.
Posted: Mon Jul 03, 2006 11:20 pm
by srod
That's a good idea - I didn't think of that.
How do you read from the embedded language file? Do you first write it out to disk or use PeekS() etc?
Posted: Tue Jul 04, 2006 4:28 am
by Dare
Good idea on the default language, GeoTrail. I'm pinching it.
Hi srod,
Unicode seems to be pretty simple to use on PureBasic, provided you remember to use SizeOf(Character) where required (eg, copying strings to a memory allocation, etc). Only real curly after getting into it (and thus far) was with http stuff.
FWIW, I've used a couple of methods for multiple languages, starting with a simple key=value via preferences. Currently I use, and prefer, constant numbers and an array:
Code: Select all
Enumeration
#lang_title
; yada
EndEnumeration
#lang_max = #PB_Compiler_EnumerationValue - 1
Global Dim lang.s(#lang_max)
(above just typed in here, excuse typos/errors).
The language files are simple strings which I ReadString into the array and then use that, eg SetGadgetText(#gad,lang(#lang_something)).
Also you've probably seen the neat tricks on Right-to-Left posted on the forum. Haven't tried/needed that yet, but I think it is possible to build a truely "multilingual" app provided you have dynamic gadget sizing. For example, German is about 40% more expensive on average (and in characters) than English. However as you were one of the people who gave me some clues on text metrics, I guess you'll have that under control.

Posted: Tue Jul 04, 2006 7:29 am
by srod
Also you've probably seen the neat tricks on Right-to-Left posted on the forum. Haven't tried/needed that yet, but I think it is possible to build a truely "multilingual" app provided you have dynamic gadget sizing. For example, German is about 40% more expensive on average (and in characters) than English.
Good point, I didn't think of that either!
I will probably use an array as you've indicated.
Thanks GeoTrail + Dare.
Posted: Tue Jul 04, 2006 8:21 am
by Flype
hello srod,
for a simple translation example, you might have a look at the source of SysColorRequester_i18n.pb (in the archive) :
http://www.purebasic.fr/english/viewtop ... highlight=
if the tool is small, with not many strings to translate you can insert/compile them in the executable, but if the tool is going to grow a lot, external languages files are a must.
here is the code i alway use to detect user language :
Code: Select all
Macro SUBLANGID(lgid)
((lgid)>>10)
EndMacro
Macro PRIMARYLANGID(lgid)
((lgid)&$3FF)
EndMacro
Macro MAKELANGID(primary, sublang)
(((sublang)<<10)|(primary))
EndMacro
Global Dim lang.s(10)
Select PRIMARYLANGID( GetUserDefaultLangID_() )
Case #LANG_FRENCH
lang(00) = "Sélecteur de couleurs système"
lang(01) = "..."
Case #LANG_GERMAN
lang(00) = "SysColor Requester"
lang(01) = "..."
Case #LANG_SPANISH
lang(00) = "Selector de colores del sistema"
lang(01) = "..."
Default
lang(00) = "SysColor Requester"
lang(01) = "..."
EndSelect
Posted: Tue Jul 04, 2006 10:22 am
by srod
Thanks Flype, that's a nice example. I was wondering if such a thing was possible using api.
It's definitely a language file!
