Multi-language:
The option "Multi-Language Support" will do most of the work for you, extracting and preparing the xxx_Lang.pb code.
The code is based on Freak's solution :
An easy to use solution for multilanguage programs and this is how it's done in PureBasic, IDE.
Or rather, the code is based on
GPI's version with a map, itself based on the same concept
The work is ready to go, but it's up to you to adapt xxx_Lang.pb, according to the way you want to use multi-language in your application:
By default, it will use the DataSection, label DefaultLang: for the default language (usually English) with all the interface text prepared for you.
Then, when running, it will create a language file (e.g. Français.lang) in your application's "Lang" subfolder in accordance with GetLocaleInfo_(#LOCALE_USER_DEFAULT,..) Api, here.
Now it's your turn to translate Français.lang and others language files.
If new gadgets with a texts are added in IceDesign, the DataSection will be updated in relation.
And when running again, the new texts, keys will automatically be added to the "locale user" language files, without overwriting the previously translated text.
It is made that way to work immediately, out of the box, but,
But it's probably not the way you want to use multi-Language. There is no standard method, there are so many possible ways to hanle it
You need to adapt by changing the included source xxx_Lang.pb to suit your needs. To help, some examples are included, commented at the bottom of xxx_Lang.pb.
Ex: with a Window and only 1 button, caption "My Button", and the Multi-Language option enabled in the settings.
The code generated (ex MyApp.pb) for the button will be:
Code: Select all
ButtonGadget(#Button, 30, 30, 200, 60, GetInterfaceLang("Button"))
GetInterfaceLang("Button") allows you to get the translation for the "Button" key according to the language previously loaded
And In MyApp_Lang.pb, you'll have:
Code: Select all
DataSection
; Here the default language is specified (usually in English). It is a list of Section and of Key name with its Value,
;
; With some special Keywords for the Section:
; "_SECTION_" will indicate a new Section in the datasection, the second value is the Section name
; "_END_" will indicate the end of the language list (as there is no fixed number)
;
; Note: The Section and Key name are case insensitive to make live easier :)
DefaultLang:
; =========================================================================
Data.s "_SECTION_", "Interface"
; =========================================================================
Data.s "Button", "My Button"
And In Français.lang:
There are different prepared sections at the bottom : Interface, Tooltip, Menu, ToolBar, StatusBar, Message.
To be used according to usage, interface text, menu options, MessageRequester text...
To add a new text to translate, enter the key and the text in the default language.
Example For a warning message, ajouter dans la section messsage
Code: Select all
Data.s "_SECTION_", "Message"
; =========================================================================
Data.s "Warn0001", "Warning!"
Data.s "Warn0002", "Warning, bla bla bla"
In "French.lang", it'll be:
Code: Select all
; Language File
[Info]
Program = Demo_MultiLangue.exe
Version = 1.00
[INTERFACE]
BUTTON = Mon Bouton
[MESSAGE]
WARN0001 = Avertissement!
WARN0002 = Avertissement, bla bla bla
Then in the source, you just need to use the macro GetMessageLang("Warn0001"), GetMessageLang("Warn0002")to get the translated message.
Ex: MessageRequester(GetMessageLang("Warn0001"), GetMessageLang("Warn0002"), #PB_MessageRequester_Ok|#PB_MessageRequester_Warning)
Now, how to use it in your app if, for example, you want to use a comboBoxGadget(#ComBoLang,...) to select the language between English, French and German:
The English, the default Language will be written in the DataSection (label DefaultLang:)
To create the 2 language files, French and German, use
Code: Select all
LangLoadDefault() ; Load the default language (usually English)
LangSave("French.lang") ; Save the loaded language in Lang\French.lang
LangSave("German.lang") ; Save the loaded language in Lang\German.lang
Once language file created, comment on this part.
Then to load the right language in your app, you can use something like:
Code: Select all
Select GetGadgetText(#ComBoLang)
Case "English"
LangLoadDefault() ; Load the default language (usually English)
Case "French"
LangSave("French.lang") ; (Optional) Update French.lang with possible new keys from the default language
LangLoad("French.lang") ; Load the French language from Lang\French.lang
Case "German"
LangSave("German.lang") ; (Optional) Update German.lang with possible new keys from the default language
LangLoad("German.lang") ; Load the German language from Lang\German.lang
Default
LangLoadDefault() ; Load the default language (usually English)
EndSelect
All translated texts will be loaded into the Map
All you have to do now, is use the macros with the right key to obtain the translated text GetInterfaceLang("MyButtonName"), GetMessageLang("Info0001"),...
An other way, without the language files is to create the different languages directly in the DataSection by copying the label DefaultLang: to French: and German:
Then you have to adapt MyApp_Lang.pb code to use the different labels by changing the procedure LangLoadDefault() ex:
Code: Select all
Procedure LangLoadDefault(Lang$)
Protected Section.s = "COMMON", Keyname.s, Value.s
ClearMap(Lang())
Select Lang$
Case "English"
Restore DefaultLang: ; Restore the default language (usually English)
Case "French"
Restore French: ; Restore the French language
Case "German"
Restore German: ; Restore the German language
Default
Restore DefaultLang: ; Restore the default language (usually English)
EndSelect
......
To load the choosen language at the beginning of the program, call: LangLoadDefault(GetGadgetText(#ComBoLang))
And then, use the macros GetIxxxLang("Key") to get the translated texts.
I hope it's a bit clearer, come back if needed
