It is currently Sat Feb 23, 2019 6:15 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Language of Requester
PostPosted: Fri Nov 11, 2011 7:12 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 661
Location: Cologne, Germany
Hiya,

I've always wondered, why PureBasic on my Mac always uses English as the language for Requesters.
If you put an YESNO-Requester, it will - of course - display yes and no-buttons.

In German, there should be something like "JA" and "NEIN"...

Is it a bug, or am I too blind to find the appropriate settings?

_________________
Regards,
JamiroKwai

---
5.10-x64/x86 - MacBook Pro, Mountain Lion
My Blog (German): http://www.quadworks.de


Top
 Profile  
Reply with quote  
 Post subject: Re: Language of Requester
PostPosted: Sat Nov 12, 2011 6:52 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 21, 2005 10:21 pm
Posts: 290
Location: Germany
jamirokwai wrote:
Hiya,

I've always wondered, why PureBasic on my Mac always uses English as the language for Requesters.
If you put an YESNO-Requester, it will - of course - display yes and no-buttons.

In German, there should be something like "JA" and "NEIN"...

Is it a bug, or am I too blind to find the appropriate settings?

You are right. Seems to be not translated.

_________________
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta


Top
 Profile  
Reply with quote  
 Post subject: Re: Language of Requester
PostPosted: Mon Apr 09, 2012 8:57 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1591
Location: Germany
I have programmed an API solution to display a requester using
buttons with predefinable text. Currently it only works in ASCII
mode. If you need a unicode example please ask. A unicode
solution is a little bit more complicated because you have to
use two other API calls and CFStrings instead of the Pascal type
strings.

My example displays 3 buttons with German text and a question
mark in a round button. To suppress unwanted buttons you
simply have to comment out the unwanted buttons (take a look
into the remarks).

You may even change the icon of the requester by changing the
first parameter in StandardAlert() to another Alert type constant.
The constant #kAlertPlainAlert even allows to display a requester
without any icon.
Code:
EnableExplicit

; ----- Alert types
#kAlertStopAlert    = 0
#kAlertNoteAlert    = 1
#kAlertCautionAlert = 2
#kAlertPlainAlert   = 3

; ----- StandardAlert alert button numbers
#kAlertStdAlertOKButton     = 1
#kAlertStdAlertCancelButton = 2
#kAlertStdAlertOtherButton  = 3
#kAlertStdAlertHelpButton   = 4

ImportC ""
  StandardAlert(AlertType.W, *ErrorText, *ExplanationText, *AlertParam, *ButtonPressed)
EndImport

Structure AlertStdAlertParamRec
  Movable.B         ; Ignored on Mac OS X: all standard alerts are movable
  HelpButton.B
  ModalFilterUPP.L
  *DefaultText
  *CancelText
  *OtherText
  DefaultButton.W
  CancelButton.W
  Position.U
EndStructure

Procedure.S ConvertStringToPascalString(String.S)
  String = "#" + String
  PokeB(@String, Len(String) - 1)
  ProcedureReturn String
EndProcedure

Define AlertParam.AlertStdAlertParamRec
Define ButtonPressed.W

; ----- Define localized text for title, message and buttons
Define CancelButtonText.S = ConvertStringToPascalString("Nein")
Define DefaultButtonText.S = ConvertStringToPascalString("Ja")
Define OtherButtonText.S = ConvertStringToPascalString("Abbrechen")
Define Title.S = ConvertStringToPascalString("Localized Requester")
Define Explanation.S = ConvertStringToPascalString("Are all buttons translated to German?")

; ----- Define which buttons have to be displayed and point to localized text
AlertParam\DefaultButton = #kAlertStdAlertOKButton ; Set preselected button
AlertParam\DefaultText = @DefaultButtonText ; Comment out to display default text 'OK'
AlertParam\CancelText = @CancelButtonText   ; Comment out to suppress cancel button
AlertParam\OtherText = @OtherButtonText     ; Comment out to suppress other text button
AlertParam\HelpButton = #True               ; Comment out to suppress help button

; ----- Display requester with localized text on buttons
If StandardAlert(#kAlertNoteAlert, @Title, @Explanation, @AlertParam, @ButtonPressed) = 0
  Select ButtonPressed
    Case #kAlertStdAlertOKButton
      Debug "Default button 'Ja' was pressed"
    Case #kAlertStdAlertCancelButton
      Debug "Cancel button 'Nein' was pressed"
    Case #kAlertStdAlertOtherButton
      Debug "Other button 'Abbrechen' was pressed"
    Case #kAlertStdAlertHelpButton
      Debug "Help button was pressed"
  EndSelect
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Language of Requester
PostPosted: Tue Apr 10, 2012 2:13 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 20, 2008 2:12 am
Posts: 661
Location: Cologne, Germany
Hi there,

thanks for the API-stuff :-)
How would you add unicode?

My approach for my discontinued Reisekostenrechner was this... Needs some optimization, I think, but works.

Code:
ImportC ""
  HiliteControl(ControlRef.L, HiliteState.L)
  SetControlData(Control.L, ControlPartCode.L, TagName.L, BufferSize.L, *Buffer)
EndImport

#kControlButtonPart = 10
#kControlPushButtonDefaultTag = 'dflt'

Global ReqStandardBild

#de = 0
#en = 1
#fr = 2
#it = 3

#PB_MessageRequester_YesCancel = 99
#PB_MessageRequester_NoCancel  = 100
#PB_MessageRequester_OkCancel  = 101

Procedure QW_MessageRequester(Titel$,Text$,Art=#PB_MessageRequester_Ok,Sprache=0,Bild=-1)
 
  If Sprache = #de : Yes$ = "Ja" : No$ = "Nein" : Cancel$ = "Abbrechen" : OK$ = "OK" : EndIf
  If Sprache = #en : Yes$ = "Yes" : No$ = "No" : Cancel$ = "Cancel" : OK$ = "OK" : EndIf
  If Sprache = #fr : Yes$ = "Oui" : No$ = "Non" : Cancel$ = "Cancel" : OK$ = "OK" : EndIf
  If Sprache = #it : Yes$ = "Si" : No$ = "No" : Cancel$ = "Cancel" : OK$ = "OK" : EndIf
 
  ReqWin  = OpenWindow(#PB_Any,   0,  0, 400, 160, Titel$, #PB_Window_TitleBar|#PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_WindowCentered )
  If Bild = -1
    Bild = ReqStandardBild
    If IsImage(Bild)
      ReqImg = ImageGadget(#PB_Any, 10, 10, 120, 90, ImageID(Bild))
    EndIf
  EndIf
 
  ReqText1 = TextGadget(#PB_Any, 140, 10, 250, 20, Titel$)
  ReqText2 = TextGadget(#PB_Any, 140, 30, 250, 130, Text$)
  ReqFont = LoadFont(#PB_Any,"Arial",14,#PB_Font_Bold)
  SetGadgetFont(ReqText1,FontID(ReqFont))
 
;   AddKeyboardShortcut(ReqWin, #PB_Shortcut_Return, 1)
 
  Select Art
    Case #PB_MessageRequester_Ok
      OKKnopf = ButtonGadget(#PB_Any, WindowWidth(ReqWin) - 70, WindowHeight(ReqWin) - 30, 60, 20, OK$)
    Case #PB_MessageRequester_YesNo
      YESKnopf = ButtonGadget(#PB_Any, WindowWidth(ReqWin) - 140, WindowHeight(ReqWin) - 30, 60, 20, Yes$)
      NoKnopf  = ButtonGadget(#PB_Any, WindowWidth(ReqWin) - 70, WindowHeight(ReqWin) - 30, 60, 20, No$)
      HiliteControl(GadgetID(YESKnopf), #kControlButtonPart)
    Case #PB_MessageRequester_YesCancel
      YESKnopf  = ButtonGadget(#PB_Any, WindowWidth(ReqWin) - 140, WindowHeight(ReqWin) - 30, 60, 20, Yes$)
      CancKnopf = ButtonGadget(#PB_Any, 10, WindowHeight(ReqWin) - 30, 100, 20, Cancel$)
      HiliteControl(GadgetID(YESKnopf), #kControlButtonPart)
    Case #PB_MessageRequester_NoCancel
      NoKnopf  = ButtonGadget(#PB_Any, WindowWidth(ReqWin) - 70, WindowHeight(ReqWin) - 30, 60, 20, Yes$)
      CancKnopf = ButtonGadget(#PB_Any, 10, WindowHeight(ReqWin) - 30, 100, 20, Cancel$)
      HiliteControl(GadgetID(NoKnopf), #kControlButtonPart)
    Case #PB_MessageRequester_OkCancel
      OKKnopf  = ButtonGadget(#PB_Any, WindowWidth(ReqWin) - 70, WindowHeight(ReqWin) - 30, 60, 20, OK$)
      CancKnopf = ButtonGadget(#PB_Any, 10, WindowHeight(ReqWin) - 30, 100, 20, Cancel$)
      HiliteControl(GadgetID(OKKnopf), #kControlButtonPart)
    Case #PB_MessageRequester_YesNoCancel
      YESKnopf  = ButtonGadget(#PB_Any, WindowWidth(ReqWin) - 140, WindowHeight(ReqWin) - 30, 60, 20, Yes$)
      NoKnopf   = ButtonGadget(#PB_Any, WindowWidth(ReqWin) - 70, WindowHeight(ReqWin) - 30, 60, 20, No$)
      CancKnopf = ButtonGadget(#PB_Any, 10, WindowHeight(ReqWin) - 30, 100, 20, Cancel$)
      HiliteControl(GadgetID(YESKnopf), #kControlButtonPart)
  EndSelect
 
  ReqRaus = 234567
  Repeat
    event = WaitWindowEvent(25)
    If event = #PB_Event_Gadget
      gadget = EventGadget()
      Select Gadget
        Case OKKnopf   : ReqRaus = #PB_MessageRequester_Ok
        Case YESKnopf  : ReqRaus = #PB_MessageRequester_Yes
        Case NoKnopf   : ReqRaus = #PB_MessageRequester_No
        Case CancKnopf : ReqRaus = #PB_MessageRequester_Cancel
      EndSelect
;     ElseIf event = #PB_Event_Menu
;       Debug "jo"
;       Select EventMenu()
;         Case 1 : Debug "jo"
;       EndSelect
    EndIf
  Until ReqRaus <> 234567
  If IsGadget(ReqText1) : FreeGadget(ReqText1) : EndIf
  If IsGadget(ReqText2) : FreeGadget(ReqText2) : EndIf
  If IsGadget(OKKnopf) : FreeGadget(OKKnopf) : EndIf
  If IsGadget(YESKnopf) : FreeGadget(YESKnopf) : EndIf
  If IsGadget(NoKnopf) : FreeGadget(NoKnopf) : EndIf
  If IsGadget(CancKnopf) : FreeGadget(CancKnopf) : EndIf
  If IsGadget(ReqImg) : FreeGadget(ReqImg) : EndIf
  If IsFont(reqFont) : FreeFont(ReqFont) : EndIf
  If IsWindow(ReqWin) : CloseWindow(ReqWin) : EndIf
  ProcedureReturn ReqRaus
EndProcedure

QW_MessageRequester("Test","blablabla")

_________________
Regards,
JamiroKwai

---
5.10-x64/x86 - MacBook Pro, Mountain Lion
My Blog (German): http://www.quadworks.de


Top
 Profile  
Reply with quote  
 Post subject: Re: Language of Requester
PostPosted: Sat Apr 14, 2012 12:07 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1591
Location: Germany
jamirokwai,

thank you for your nice non-API example. It should be a good base for a
cross-platform multi-language requester. But for Mac-only programs the
use of API functions has a big advantage: The calculation of button width
and position is done automatically for you... :wink:

Here is my promised API example which runs with ASCII and Unicode
compilation:
Code:
EnableExplicit

#kCFStringEncodingMacRoman = 0

#kStdCFStringAlertVersionOne = 1
#kStdCFStringAlertVersionTwo = 2

; ----- Alert types
#kAlertStopAlert    = 0
#kAlertNoteAlert    = 1
#kAlertCautionAlert = 2
#kAlertPlainAlert   = 3

; ----- StandardAlert alert button numbers
#kAlertStdAlertOKButton     = 1
#kAlertStdAlertCancelButton = 2
#kAlertStdAlertOtherButton  = 3
#kAlertStdAlertHelpButton   = 4

ImportC ""
  CFStringCreateWithCharacters(CFAllocator.L, *UnicodeCharBuffer, NumChars.L)
  CreateStandardAlert(AlertType.W, ErrorTextRef.L, ExplanationTextRef.L, *AlertParam, *DialogRef)
  RunStandardAlert(AlertRef.L, EventFilterUPP.L, *ButtonPressed)
EndImport

Structure AlertStdCFStringAlertParamRec
  Version.L
  Movable.B         ; Ignored on Mac OS X: all standard alerts are movable
  HelpButton.B
  DefaultTextRef.L
  CancelTextRef.L
  OtherTextRef.L
  DefaultButton.W
  CancelButton.W
  Position.U
  OptionBits.L
  IconRef.L         ; Only if version field = kStdCFStringAlertVersionTwo
EndStructure

Procedure.L CreateCFString(String.S)
  CompilerIf #PB_Compiler_Unicode
    Protected UnicodeString.S = Space(Len(String) * 2 + 2)

    PokeS(@UnicodeString, String, Len(String), #PB_Unicode)
    ProcedureReturn CFStringCreateWithCharacters(0, @UnicodeString, Len(String))
  CompilerElse
    ProcedureReturn CFStringCreateWithCString_(0, String, #kCFStringEncodingMacRoman)
  CompilerEndIf
EndProcedure

Define AlertParam.AlertStdCFStringAlertParamRec
Define ButtonPressed.W
Define DialogRef.L

; ----- Define localized text for title, message and buttons
Define CancelButtonTextRef.L = CreateCFString("Nein")
Define DefaultButtonTextRef.L = CreateCFString("Ja")
Define ExplanationRef.L = CreateCFString("Are all buttons translated to German?")
Define OtherButtonTextRef.L = CreateCFString("Abbrechen")
Define TitleRef.L = CreateCFString("Localized Requester")

; ----- Define which buttons have to be displayed and point to localized text
AlertParam\Version = #kStdCFStringAlertVersionTwo
AlertParam\DefaultTextRef = DefaultButtonTextRef ; Comment out to display default text 'OK'
AlertParam\CancelTextRef = CancelButtonTextRef   ; Comment out to suppress cancel button
AlertParam\OtherTextRef = OtherButtonTextRef     ; Comment out to suppress other text button
AlertParam\HelpButton = #True                    ; Comment out to suppress help button

; ----- Display requester with localized text on buttons
If CreateStandardAlert(#kAlertCautionAlert, TitleRef, ExplanationRef, @AlertParam, @DialogRef) = 0
  If RunStandardAlert(DialogRef, 0, @ButtonPressed) = 0
    Select ButtonPressed
      Case #kAlertStdAlertOKButton
        Debug "Default button 'Ja' was pressed"
      Case #kAlertStdAlertCancelButton
        Debug "Cancel button 'Nein' was pressed"
      Case #kAlertStdAlertOtherButton
        Debug "Other button 'Abbrechen' was pressed"
      Case #kAlertStdAlertHelpButton
        Debug "Help button was pressed"
    EndSelect
  EndIf
EndIf

; ----- Release CFStrings
CFRelease_(CancelButtonTextRef)
CFRelease_(DefaultButtonTextRef)
CFRelease_(ExplanationRef)
CFRelease_(OtherButtonTextRef)
CFRelease_(TitleRef)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye