I am creating application that suppose to be available in multiple languages. I've got translation of all text labels,
combobox gadgets, link gadgets e.t.c. I've also would like to change image button picture when I change application language,
so that it display proper language flag image.
My question is - what's the best way to handle such task in PB ? Right now I am closing and recreating form window when I am
changing languages... But something tells me that there should be another way of doing so. I was expecting some kind of "refresh"
option that I could apply to my form so that I would update all items within form or am I asking about something that does not exist
in PB ?
Multilanguage application - how to refresh form object ?
Re: Multilanguage application - how to refresh form object ?
have a look at SetGadgetAttribute with #PB_Button_Image flag
- Andre
- PureBasic Team
- Posts: 2058
- Joined: Fri Apr 25, 2003 6:14 pm
- Location: Germany (Saxony, Deutscheinsiedel)
- Contact:
Re: Multilanguage application - how to refresh form object ?
If you're using Dialogs (see: http://purebasic.com/documentation/dialog/index.html) take a look to the new command RefreshDialog(). This one you can use after changing the gadget contents to recalc the Window/Gadget dimensions (if you've previously created your GUI using the dialog feature).
Re: Multilanguage application - how to refresh form object ?
Here's a simple example to illustrate your requirements. It reads some text from the data section, and loads some sample images from my DropBox folder:agb2008 wrote:I am creating application that suppose to be available in multiple languages ... change image button picture when I change application language ... what's the best way to handle such task in PB?
* note: PureBasic v5.40 minimum required for the ReceiveHTTPFile() function to work properly with DropBox:
Code: Select all
;requires PureBasic v5.40 minimum for ReceiveHTTPFile() to work properly with DropBox
Enumeration
#MainWindow
#Label1
#Label2
#Label3
#Language
EndEnumeration
Enumeration regions
#USA
#Italy
#France
EndEnumeration
InitNetwork()
ReceiveHTTPFile("https://www.dropbox.com/s/axjsl3w7kgnf3sp/USA.bmp?dl=1",
GetTemporaryDirectory() + "USA.bmp")
ReceiveHTTPFile("https://www.dropbox.com/s/uqmvo5pcftnqdem/Italy.bmp?dl=1",
GetTemporaryDirectory() + "Italy.bmp")
ReceiveHTTPFile("https://www.dropbox.com/s/1ydvr4vmc4g8vtx/France.bmp?dl=1",
GetTemporaryDirectory() + "France.bmp")
LoadImage(#USA, GetTemporaryDirectory() + "USA.bmp")
LoadImage(#Italy, GetTemporaryDirectory() + "Italy.bmp")
LoadImage(#France, GetTemporaryDirectory() + "France.bmp")
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 300, 120, "Multi-Language System", wFlags)
TextGadget(#Label1, 20, 20, 200, 25, "Current language: English")
TextGadget(#Label2, 20, 45, 200, 25, "Welcome to PureBasic!")
TextGadget(#Label3, 20, 70, 280, 30, "Click the flag to change language...")
ButtonImageGadget(#Language, 210, 15, 70, 43, ImageID(#USA))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case #Language
language + 1
If language > #France
language = #USA
EndIf
SetGadgetAttribute(#Language, #PB_Button_Image, ImageID(language))
Select language:
Case #USA
Restore USA
Case #Italy
Restore Italy
Case #France
Restore France
EndSelect
Read.s text$
SetGadgetText(#Label1, text$)
Read.s text$
SetGadgetText(#Label2, text$)
Read.s text$
SetGadgetText(#Label3, text$)
EndSelect
EndSelect
Until appQuit = 1
DataSection:
USA:
Data.s "Current language: English", "Welcome to PureBasic!",
"Click the flag to change language..."
Italy:
Data.s "Lingua corrente: Italiano", "Benvenuti a PureBasic!",
"Cliccando sulla bandiera cambiare la lingua..."
France:
Data.s "Langage courant : Français", "Bienvenue à PureBasic!",
"Cliquez sur le drapeau pour changer de langue..."
EndDataSection
Hope it helps.
EDITS wrote:18th February 2019: updated download links
Last edited by TI-994A on Mon Feb 18, 2019 7:30 am, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
Re: Multilanguage application - how to refresh form object ?
Keya:
Thanks ! I am using that function.
Andre:
I do not use Dialogs (was not aware of this option, would have a look, thanks !)
TI-994A:
Thank you for providing this great example ! Looks like main issue that I am facing is an attempt
to bring (use) slightly different approach in programming brought from other flavor of Basic implementation...
But looks like there are slightly different was of implementing same tasks in PB that could improve
all process !
Thanks ! I am using that function.
Andre:
I do not use Dialogs (was not aware of this option, would have a look, thanks !)
TI-994A:
Thank you for providing this great example ! Looks like main issue that I am facing is an attempt
to bring (use) slightly different approach in programming brought from other flavor of Basic implementation...
But looks like there are slightly different was of implementing same tasks in PB that could improve
all process !