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.
Multiple languages
Multiple languages
I may look like a mule, but I'm not a complete ass.
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.
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.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
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:
(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.
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)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.
Dare2 cut down to size
Good point, I didn't think of that either!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.
I will probably use an array as you've indicated.
Thanks GeoTrail + Dare.
I may look like a mule, but I'm not a complete ass.
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 :
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
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer

