Multiple languages

Everything else that doesn't fall into one of the other PB categories.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Multiple languages

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post 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.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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?
I may look like a mule, but I'm not a complete ass.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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. :)
Dare2 cut down to size
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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
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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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! :)
I may look like a mule, but I'm not a complete ass.
Post Reply