Page 1 of 1

LocalText

Posted: Fri Dec 23, 2005 5:53 pm
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

Posted: Fri Dec 23, 2005 8:02 pm
by josku_x
Cool!

That is very good for MUI developers.

Droopy, how come you are so great?

Posted: Fri Dec 23, 2005 9:02 pm
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.

Posted: Fri Dec 23, 2005 9:32 pm
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)))

Posted: Fri Dec 23, 2005 9:47 pm
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 ;)

Posted: Fri Dec 23, 2005 11:08 pm
by Hroudtwolf
Very nice.

But why, you didn't used Shared LocaltextIsLocal instead Global LocaltextIsLocal ?

Posted: Fri Dec 23, 2005 11:59 pm
by Droopy
@Hroudtwolf : Because i want to use LocaltextIsLocal value in another procedure, and in this case 'shared' doesn't works.

Posted: Sat Dec 24, 2005 4:05 am
by Hroudtwolf
Try to use Shared LocaltextIsLocal in every procedure you need this variable.

Posted: Sat Dec 24, 2005 8:03 am
by Droopy
That's works.

Thanks Hroudtwolf :D