LocalText

Share your advanced PureBasic knowledge/code with the community.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

LocalText

Post by Droopy »

Code updated For 5.20+

An easy way to set the language of your Sortware.

Code: Select all

;/ Return the default primary language identifier ( 0 system / 1 User )
ProcedureDLL GetLanguage(wich)
  If wich
    ProcedureReturn GetUserDefaultLangID_() & 511
  Else
    ProcedureReturn GetSystemDefaultLangID_() & 511
  EndIf
EndProcedure

;/ Initialise the LocalText function with a Primary language identifier
;/ German = 7 / English 9 / French 12 / Spanish = 10 / Italian = 16 / Portuguese = 22
ProcedureDLL LocalTextInit(LocalLanguageIdentifier)
  Global LocaltextIsLocal
  LocaltextIsLocal=0
  If GetLanguage(1)=LocalLanguageIdentifier
    LocaltextIsLocal=1
  EndIf
EndProcedure

;/ Return the correct text regarding the user language
ProcedureDLL.s LocalText(Local.s,International.s)
  If LocaltextIsLocal
    ProcedureReturn Local
  Else
    ProcedureReturn International
  EndIf
EndProcedure


;/ Test
LocalTextInit(12) ;/ French Language as local

WindowsTitle.s=LocalText("Version Française","English Version")
OpenWindow(0,0,0,200,120,WindowsTitle,#PB_Window_SystemMenu|#PB_Window_ScreenCentered)


CreateStatusBar(0,WindowID(0))
AddStatusBarField(90)

StatusBarText(0,0,LocalText("C'est juste un test","It's just a test"),#PB_StatusBar_Center)

ButtonGadget(0, 10, 10, 180, 80, LocalText("Cliquez Moi","Clic Me"))
GadgetToolTip(0,LocalText("Ce texte est en Français","This text is in English"))

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Cool!

That is very good for MUI developers.

Droopy, how come you are so great?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I don't understand how this is supposed to work. What do you do if you've got 25 languages?

Also I don't get how to show the French string, it always shows the English version.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

@Trond : This function manage only 2 language ( yours and international )

For example
1st language : Local Language ( French in the Example )
2nd language : International language ( English)

For a french user the software is in French.
For other people the software is in English.

It's automatic :wink:

Here the code to retrieve the Language Identifier (Norway for you):

Code: Select all

;/ Return the default primary language identifier ( 0 system / 1 User ) 
ProcedureDLL GetLanguage(wich) 
  If wich 
    ProcedureReturn GetUserDefaultLangID_() & 511 
  Else 
    ProcedureReturn GetSystemDefaultLangID_() & 511 
  EndIf 
EndProcedure 

MessageRequester("Default Primary Language Identifier","Your Language Identifier is : "+Str(GetLanguage(1)))
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

If you want to use several languages, you shouldn't do this way. Your program can only have two languages (custom and international).

Probably better to use ini files or stringtables (resources). Look at those functions, you can also choose the lang ;)
viewtopic.php?t=17244

Dri ;)
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Very nice.

But why, you didn't used Shared LocaltextIsLocal instead Global LocaltextIsLocal ?
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

@Hroudtwolf : Because i want to use LocaltextIsLocal value in another procedure, and in this case 'shared' doesn't works.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Try to use Shared LocaltextIsLocal in every procedure you need this variable.
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

That's works.

Thanks Hroudtwolf :D
Post Reply