Get Localized Strings From Windows System DLLs

Share your advanced PureBasic knowledge/code with the community.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Get Localized Strings From Windows System DLLs

Post by gnozal »

May be useful to build simple custom requesters (like MessageRequester).

Code: Select all

;
; Get Localized Strings From Windows System DLLs
;
;{ some valid uIDs ...
; USER32
#LocalString_Error = 2
#LocalString_OK = 800
#LocalString_Cancel = 801
#LocalString_Abort = 802
#LocalString_Retry = 803
#LocalString_Ignore = 804
#LocalString_Yes = 805
#LocalString_No = 806
#LocalString_Close = 807
#LocalString_Help = 808
#LocalString_TryAgain = 809
#LocalString_Continue = 810
#LocalString_Minimize = 900
#LocalString_Maximize = 901
#LocalString_RestoreUp = 902
#LocalString_RestoreDown = 903
; COMDLG32
#LocalString_Save = 369
#LocalString_Open = 370
#LocalString_Print = 371
#LocalString_SaveAs = 385
; SHELL32
#LocalString_File = 4130
#LocalString_Folder = 4131
#LocalString_Move = 4144
#LocalString_Copy = 4145
#LocalString_Delete = 4146
#LocalString_Rename = 4147
;}
Procedure.s GetLocaleString(uID) ; Get Localized Strings ['' if invalid uID]
  ;
  Protected LocaleString.s, hInstance, *Buffer, WinLibrary.s
  ;
  If uID >= #LocalString_File
    WinLibrary = "shell32"
  ElseIf uID >= #LocalString_Save And uID <= #LocalString_SaveAs
    WinLibrary = "comdlg32"
  Else
    WinLibrary = "user32"
  EndIf
  ;
  hInstance = LoadLibraryEx_(WinLibrary, 0, #LOAD_LIBRARY_AS_DATAFILE)
  If hInstance
    ;
    *Buffer = AllocateMemory(256)
    If *Buffer
      ;
      If LoadString_(hInstance, uID, *Buffer, 255)
        LocaleString = PeekS(*Buffer)
        LocaleString = RemoveString(LocaleString, "&")
      EndIf
      FreeMemory(*Buffer)
      ;
    EndIf
    ;
    FreeLibrary_(hInstance)
    ;
  EndIf
  ;
  ProcedureReturn LocaleString
  ;
EndProcedure

Debug GetLocaleString(#LocalString_Yes) ; -> Yes / Oui / Ja / ...
Debug GetLocaleString(#LocalString_Print) ; -> Print / Imprimer ...
Could you test if it works on Vista / Se7en ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Get Localized Strings From Windows System DLLs

Post by srod »

Works fine on Vista x86 Gnozal.

Could indeed be useful - thanks.

You're not still using that NT rubbish are you? :wink:
I may look like a mule, but I'm not a complete ass.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: Get Localized Strings From Windows System DLLs

Post by gnozal »

srod wrote:You're not still using that NT rubbish are you? :wink:
Nope ...

XP :lol:
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Get Localized Strings From Windows System DLLs

Post by srod »

gnozal wrote:
srod wrote:You're not still using that NT rubbish are you? :wink:
Nope ...

XP :lol:
Ah, progress! :)
I may look like a mule, but I'm not a complete ass.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Get Localized Strings From Windows System DLLs

Post by Little John »

Thank you, gnozal!

Regards, Little John
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Re: Get Localized Strings From Windows System DLLs

Post by einander »

Thanks gnozal.
Works fine on seven x86 and x64.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Get Localized Strings From Windows System DLLs

Post by Little John »

Hi gnozal,

do you think it's possible also to get the localized names of weekdays and months in a similar way? That would be useful as well.
On my system (German Windows XP Pro SP3 32bit), complete and abbreviated localized names of weekdays and months are contained in the file "C:\Windows\System32\ole2nls.dll".

Regards, Little John
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get Localized Strings From Windows System DLLs

Post by Kwai chang caine »

Thanks for sharing, GNOZAL works good 8)
ImageThe happiness is a road...
Not a destination
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: Get Localized Strings From Windows System DLLs

Post by gnozal »

Little John wrote:do you think it's possible also to get the localized names of weekdays and months in a similar way? That would be useful as well.
On my system (German Windows XP Pro SP3 32bit), complete and abbreviated localized names of weekdays and months are contained in the file "C:\Windows\System32\ole2nls.dll".
LoadLibraryEx_() fails probably because "ole2nls.dll" is a NE executable (16 bits).

But you could use GetLocaleInfo_() :

Code: Select all

;
; Get Localized Day Or Month Name
;
Procedure.s LocalizedDayName(DayOfWeek)
  Protected DayName.s
  DayName = Space(80)
  GetLocaleInfo_(#LOCALE_USER_DEFAULT, #LOCALE_SDAYNAME1 + DayOfWeek - 1, @DayName, 80) ; LOCALE_SABBREVDAYNAME1 -> short name
  ProcedureReturn DayName
EndProcedure
Procedure.s LocalizedMonthName(MonthOfYear)
  Protected MonthName.s
  MonthName = Space(80)
  GetLocaleInfo_(#LOCALE_USER_DEFAULT, #LOCALE_SMONTHNAME1 + MonthOfYear - 1, @MonthName, 80) ; LOCALE_SABBREVMONTHNAME1 -> short name
  ProcedureReturn MonthName
EndProcedure

For i = 1 To 7
  Debug LocalizedDayName(i)
Next
Debug "--------"
For i = 1 To 12
  Debug LocalizedMonthName(i)
Next
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Get Localized Strings From Windows System DLLs

Post by Little John »

GREAT!!!
Thank you very much, Gnozal!
Post Reply