Code : Tout sélectionner
Enumeration
#LANG_NEUTRAL
#LANG_ARABIC
#LANG_BULGARIAN
#LANG_CATALAN
#LANG_CHINESE
#LANG_CZECH
#LANG_DANISH
#LANG_GERMAN
#LANG_GREEK
#LANG_ENGLISH
#LANG_SPANISH
#LANG_FINNISH
#LANG_FRENCH
#LANG_HEBREW
#LANG_HUNGARIAN
#LANG_ICELANDIC
#LANG_ITALIAN
#LANG_JAPANESE
#LANG_KOREAN
#LANG_DUTCH
#LANG_NORWEGIAN
#LANG_POLISH
#LANG_PORTUGUESE
#LANG_ROMANIAN = 24
#LANG_RUSSIAN
#LANG_CROATIAN
#LANG_SERBIAN = 26
#LANG_SLOVAK
#LANG_ALBANIAN
#LANG_SWEDISH
#LANG_THAI
#LANG_TURKISH
#LANG_URDU
#LANG_INDONESIAN
#LANG_UKRAINIAN
#LANG_BELARUSIAN
#LANG_SLOVENIAN
#LANG_ESTONIAN
#LANG_LATVIAN
#LANG_LITHUANIAN
#LANG_FARSI = 41
#LANG_VIETNAMESE
#LANG_ARMENIAN
#LANG_AZERI
#LANG_BASQUE
#LANG_MACEDONIAN = 47
#LANG_AFRIKAANS = 54
#LANG_GEORGIAN
#LANG_FAEROESE
#LANG_HINDI
#LANG_MALAY = 62
#LANG_KAZAK
#LANG_SWAHILI = 65
#LANG_UZBEK = 67
#LANG_TATAR
#LANG_BENGALI
#LANG_PUNJABI
#LANG_GUJARATI
#LANG_ORIYA
#LANG_TAMIL
#LANG_TELUGU
#LANG_KANNADA
#LANG_MALAYALAM
#LANG_ASSAMESE
#LANG_MARATHI
#LANG_SANSKRIT
#LANG_KONKANI = 87
#LANG_MANIPURI
#LANG_SINDHI
#LANG_KASHMIRI
#LANG_NEPALI
EndEnumeration
#LOCALE_SISO639LANGNAME = $59
Structure Longs
l.l[0]
EndStructure
Structure DLGTEMPLATEEX Extends DLGTEMPLATE
menu.w
class.w
title.l
EndStructure
Structure LangRequesterParams
Title.s
Text.s
IconID.l
Pattern.s
EndStructure
Procedure.s GetLangName(Locale.l)
Protected LangName.s, Temp.s, Length.l
Length = GetLocaleInfo_(Locale, #LOCALE_SNATIVELANGNAME, #Null, #Null)
If Length > 0
Temp = Space(Length - 1)
GetLocaleInfo_(Locale, #LOCALE_SNATIVELANGNAME, Temp, Length)
LangName = UCase( Left (Temp, 1) )
LangName + LCase( Right(Temp, Length - 2) )
EndIf
ProcedureReturn LangName
EndProcedure
Procedure.s GetLangCode(Locale.l)
Protected LangCode.s, Length.l
Length = GetLocaleInfo_(Locale, #LOCALE_SISO639LANGNAME, #Null, #Null)
If Length > 0
LangCode = Space(Length - 1)
GetLocaleInfo_(Locale, #LOCALE_SISO639LANGNAME, LangCode, Length)
EndIf
ProcedureReturn LangCode
EndProcedure
Procedure.l GetLangLocale(LangCode.s)
Protected Locale.l, Done.l
If Len(LangCode) = 2
While Locale < #LANG_NEPALI And Done = #False
Locale + 1
If LangCode = GetLangCode(Locale)
Done = #True
EndIf
Wend
EndIf
If Done = #False
Locale = #Null
EndIf
ProcedureReturn Locale
EndProcedure
Procedure.l IsLangSupported(Locale.l)
ProcedureReturn (GetLangLocale( GetLangCode(Locale) ) = Locale) Or #False
EndProcedure
Procedure.l LangRequesterCallback(WindowID.l, Message.l, wParam.l, lParam.l)
Protected *params.LangRequesterParams
Protected Title.s, Text.s, IconID.l, Pattern.s
Protected Temp.l, x.l, y.l, cx.l, cy.l, Locale.l, Location.s
Protected SH.SHFileInfo, rc.RECT
Static Image, Label, ComboLangs, ButtonOK, ButtonCancel, nLangs, *Langs.Longs
Select Message
Case #WM_INITDIALOG
*params = lParam
Title = *params\Title
Text = *params\Text
IconID = *params\IconID
Pattern = *params\Pattern
MoveWindow_(WindowID, 0, 0, 297, 125, #False)
GetClientRect_(WindowID, rc)
cx = (2 * 297) - (rc\right - rc\left)
cy = (2 * 125) - (rc\bottom - rc\top)
x = (GetSystemMetrics_(#SM_CXSCREEN) - cx) / 2
y = (GetSystemMetrics_(#SM_CYSCREEN) - cy) / 2
MoveWindow_(WindowID, x, y, cx, cy, #False)
If Title = #NULL$
Title = "Language configuration"
EndIf
If Text = #NULL$
Text = "Please select a language."
EndIf
If IconID = #Null
Location = Space($500)
GetModuleFileName_(#Null, Location, $500)
SHGetFileInfo_(Location, 0, SH, SizeOf(SHFileInfo), #SHGFI_ICON|#SHGFI_LARGEICON)
IconID = SH\hIcon
EndIf
SetWindowText_(WindowID, Title)
CreateGadgetList(WindowID)
Image = ImageGadget(#PB_Any, 8, 8, 32, 32, IconID)
Label = TextGadget(#PB_Any, 53, 8, 235, 32, Text)
ComboLangs = ComboBoxGadget(#PB_Any, 53, 56, 235, 100)
ButtonOk = ButtonGadget(#PB_Any, 133, 93, 75, 23, "OK", #PB_Button_Default)
ButtonCancel = ButtonGadget(#PB_Any, 214, 93, 75, 23, "Cancel")
Temp = CountString(Pattern, "|") + 1
For x = 1 To Temp
Locale = GetLangLocale( StringField(Pattern, x, "|") )
If Locale
AddGadgetItem(ComboLangs, #PB_Default, GetLangName(Locale))
nLangs + 1
EndIf
Next x
If nLangs > 0
*Langs = AllocateMemory(SizeOf(Long) * nLangs)
nLangs = 0
SetGadgetState(ComboLangs, 0)
For x = 1 To Temp
Locale = GetLangLocale( StringField(Pattern, x, "|") )
If Locale
If Locale = GetUserDefaultLangID_() & $FF
SetGadgetState(ComboLangs, nLangs)
EndIf
*Langs\l[nLangs] = Locale
nLangs + 1
EndIf
Next x
ActivateGadget(ComboLangs)
Else
EndDialog_(WindowID, #LANG_NEUTRAL)
EndIf
Case #WM_COMMAND
If lParam = #Null Or lParam = GadgetID(ButtonCancel) Or lParam = GadgetID(ButtonOK)
If lParam = GadgetID(ButtonOK)
x = GetGadgetState(ComboLangs)
Locale = *Langs\l[x]
Else
Locale = #LANG_NEUTRAL
EndIf
FreeMemory(*Langs)
EndDialog_(WindowID, Locale)
EndIf
EndSelect
ProcedureReturn #Null
EndProcedure
Procedure.l LangRequester(Title.s, Message.s, IconID.l, Pattern.s)
Protected Template.DLGTEMPLATEEX, Params.LangRequesterParams
Template\style = #WS_SYSMENU|#WS_CAPTION|#DS_CENTER|#DS_MODALFRAME
Template\cx = 303
Template\cy = 150
Params\Title = Title
Params\Text = Message
Params\IconID = IconID
Params\Pattern = Pattern
Lang = DialogBoxIndirectParam_(#Null, Template, WindowID(), @LangRequesterCallback(), Params)
ProcedureReturn Lang
EndProcedure