change language

Just starting out? Need help? Post your questions and find answers here.
effis
User
User
Posts: 42
Joined: Thu May 27, 2010 11:22 am

change language

Post by effis »

on windows, i have to press shift+alt to change language

is there an api to get the current language, and to set (or switch to) another language?

thanks
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: change language

Post by nco2k »

Code: Select all

Debug "User Language:"
Select GetUserDefaultLangID_() & $03FF
  Case #LANG_ENGLISH
    Debug "#LANG_ENGLISH"
  Default
    Debug "?"
EndSelect
Debug ""
Debug "Keyboard Layout:"
Select GetKeyboardLayout_(0) & $03FF
  Case #LANG_ENGLISH
    Debug "#LANG_ENGLISH"
  Default
    Debug "?"
EndSelect
http://msdn.microsoft.com/en-us/library ... S.85).aspx
effis wrote:and to set (or switch to) another language?
i hope not. :)

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
effis
User
User
Posts: 42
Joined: Thu May 27, 2010 11:22 am

Re: change language

Post by effis »

User Language:
?

Keyboard Layout:
#LANG_ENGLISH
it return the same value before and after shift+alt

r u sure it isnt possible to switch?
gabriel
Enthusiast
Enthusiast
Posts: 137
Joined: Sat Aug 01, 2009 4:49 pm
Location: Beirut, Lebanon

Re: change language

Post by gabriel »

Try this:

Code: Select all

hkl1=LoadKeyboardLayout_("00000401",#KLF_REORDER)
hkl2=LoadKeyboardLayout_("0000040C",#KLF_REORDER)

OpenWindow(1,200,100,500,300,"test 1",#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget |#PB_Window_ScreenCentered)
TextGadget(0,20,20,70,20,"language1=")
StringGadget(1,100,20,150,20,"")
TextGadget(2,20,50,70,20,"language2=")
StringGadget(3,100,50,150,20,"")

Repeat
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows
  WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
  GadgetID = EventGadget() ; Is it a gadget event?
  EventType = EventType() ; The event type
      
  Select EventType()
      Case #PB_EventType_Focus
        If GadgetID=1
          ActivateKeyboardLayout_(hkl1,#KLF_REORDER)
        ElseIf GadgetID=3
          ActivateKeyboardLayout_(hkl2,#KLF_REORDER)
        EndIf          
      EndSelect
Until event=#PB_Event_CloseWindow
End

HTH.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: change language

Post by Trond »

Shift+Alt does not switch any language. It switches the keyboard layout.
effis
User
User
Posts: 42
Joined: Thu May 27, 2010 11:22 am

Re: change language

Post by effis »

yeah, i think its this, but only two questions
i runned your exemple and now i've got the arabic language on my computer, how can i delete it (it don't appear in the control panel)
i saw un api : UnloadKeyboardLayout_ but i didnt understand what to put in it, i've tried : UnloadKeyboardLayout_(hkl1) and UnloadKeyboardLayout_("00000401") but its not working

and also, thats good for switching laguage input, but how can i get the current language? let's say i want to display in french if the input language is french, russian if its russian, and english if english

and finnaly, where did you find the language list?


thanks a lot
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: change language

Post by nco2k »

effis wrote:it return the same value before and after shift+alt
because the keyboard layout switch doesnt affect the whole system, but just a thread. ofc nothing will change if you debug the code within the ide like that.

look:

Code: Select all

If OpenWindow(0, 0, 0, 205, 30, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(0, 5, 5, 140, 20, "")
  ButtonGadget(1, 150, 5, 50, 20, "Click")
  SetActiveGadget(0)
  
  Repeat
    
    Select WaitWindowEvent()
      
      Case #PB_Event_Gadget
        If EventGadget() = 1
          
          Debug "User Language:"
          Select GetUserDefaultLangID_() & $03FF
            Case #LANG_ENGLISH
              Debug "#LANG_ENGLISH"
            Case #LANG_GERMAN
              Debug "#LANG_GERMAN"
            Case #LANG_FRENCH
              Debug "#LANG_FRENCH"
            Default
              Debug "?"
          EndSelect
          
          Debug ""
          
          Debug "Keyboard Layout:"
          Select GetKeyboardLayout_(0) & $03FF
            Case #LANG_ENGLISH
              Debug "#LANG_ENGLISH"
            Case #LANG_GERMAN
              Debug "#LANG_GERMAN"
            Case #LANG_FRENCH
              Debug "#LANG_FRENCH"
            Default
              Debug "?"
          EndSelect
          
          Debug ""
          
        EndIf
      
      Case #PB_Event_CloseWindow
        Break
        
    EndSelect
    
  ForEver
  
EndIf : End
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
effis
User
User
Posts: 42
Joined: Thu May 27, 2010 11:22 am

Re: change language

Post by effis »

thanks gabriel
i made this code

Code: Select all

num=4

Dim lan.s(num,3)
lan(1,1)="0000040c":lan(1,2)="french"
lan(2,1)="0000040d":lan(2,2)="hebrew"
lan(3,1)="00000409":lan(3,2)="english"
lan(4,1)="00000408":lan(4,2)="?"

For k=1 To num
  lan(k,3)=Str(LoadKeyboardLayout_(lan(k,1),#KLF_REORDER))
Next

OpenWindow(1,200,100,500,300,"Language Test",#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget |#PB_Window_ScreenCentered)

For k=1 To num
  TextGadget(#PB_Any,20,30*k+2,70,20,lan(k,2))
  StringGadget(k,100,30*k,150,20,"")
Next

SetActiveGadget(1)

Repeat
  Event = WaitWindowEvent()
  GadgetID = EventGadget()
  EventType = EventType()
  Select EventType()
    Case #PB_EventType_Focus
      If GadgetID>0 And GadgetID<num+1
        ActivateKeyboardLayout_(Val(lan(GadgetID,3)),#KLF_REORDER)
      EndIf
  EndSelect
Until event=#PB_Event_CloseWindow

For k=1 To num
  UnloadKeyboardLayout_(Val(lan(k,3)))
Next

End
is it correct?

and thanks nco2k, i think your code is very good
gabriel
Enthusiast
Enthusiast
Posts: 137
Joined: Sat Aug 01, 2009 4:49 pm
Location: Beirut, Lebanon

Re: change language

Post by gabriel »

looks fine!

Good continuation
Post Reply