Multilanguage application - how to refresh form object ?

You need some new stunning features ? Tell us here.
agb2008
User
User
Posts: 60
Joined: Fri Jan 15, 2016 2:22 pm

Multilanguage application - how to refresh form object ?

Post by agb2008 »

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 ?
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Multilanguage application - how to refresh form object ?

Post by Keya »

have a look at SetGadgetAttribute with #PB_Button_Image flag
User avatar
Andre
PureBasic Team
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 ?

Post by Andre »

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).
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Multilanguage application - how to refresh form object ?

Post by TI-994A »

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?
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:

* 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
If you do not wish to load those images, simply substitute them with some of your own.

Hope it helps. :wink:
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 :D
agb2008
User
User
Posts: 60
Joined: Fri Jan 15, 2016 2:22 pm

Re: Multilanguage application - how to refresh form object ?

Post by agb2008 »

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 ! :D
Post Reply