Subject: | Add ability to return the ms_locale (MSID) for a passed language. |
Hi,
I've been looking unsuccessfully for a way get an MS Locale for a
language so I've created this patch for your module to do what I'm after.
I hope you can find time to include this in the next version of your module.
Thanks,
Bernie.
*** Locale.pm.orig 2004-01-12 14:56:08.000000000 +1100
--- Locale.pm 2006-11-17 11:42:57.000000000 +1100
***************
*** 2,8 ****
package Win32::Locale;
# Time-stamp: "2004-01-11 18:56:06 AST"
use strict;
! use vars qw($VERSION %MSLocale2LangTag);
$VERSION = '0.04';
%MSLocale2LangTag = (
--- 2,8 ----
package Win32::Locale;
# Time-stamp: "2004-01-11 18:56:06 AST"
use strict;
! use vars qw($VERSION %MSLocale2LangTag %LangTag2MSLocale);
$VERSION = '0.04';
%MSLocale2LangTag = (
***************
*** 174,201 ****
0x043d => 'yi' , # <JII> <Yiddish> <Yiddish> # formetly ji
0x0435 => 'zu' , # <ZUL> <Zulu> <Zulu>
);
#-----------------------------------------------------------------------------
sub get_ms_locale {
! my $locale;
! return unless defined do {
! # see if there's a W32 registry on this machine, and if so, look in it
! local $SIG{"__DIE__"} = "";
! eval '
! use Win32::TieRegistry ();
! my $i18n = Win32::TieRegistry->new(
! "HKEY_CURRENT_USER/Control Panel/International",
! { Delimiter => "/" }
! );
! #print "no key!" unless $i18n;
! $locale = $i18n->GetValue("Locale") if $i18n;
! undef $i18n;
! ';
! #print "<$@>\n" if $@;
! $locale;
! };
! return unless $locale =~ m/^[0-9a-fA-F]+$/s;
! return hex($locale);
}
sub get_language {
--- 174,215 ----
0x043d => 'yi' , # <JII> <Yiddish> <Yiddish> # formetly ji
0x0435 => 'zu' , # <ZUL> <Zulu> <Zulu>
);
+
+ # Now do a reverse mapping
+ foreach my $key ( keys %MSLocale2LangTag) {
+ $LangTag2MSLocale{$MSLocale2LangTag{$key}} = $key;
+ }
+
#-----------------------------------------------------------------------------
sub get_ms_locale {
! my $language = shift;
! if ($language) {
! $language =~ tr/_/-/;
! my $msid = $LangTag2MSLocale{$language};
! return unless $msid;
! return $msid;
! } else {
! my $locale;
! return unless defined do {
! # see if there's a W32 registry on this machine, and if so, look
in it
! local $SIG{"__DIE__"} = "";
! eval '
! use Win32::TieRegistry ();
! my $i18n = Win32::TieRegistry->new(
! "HKEY_CURRENT_USER/Control Panel/International",
! { Delimiter => "/" }
! );
! #print "no key!" unless $i18n;
! $locale = $i18n->GetValue("Locale") if $i18n;
! undef $i18n;
! ';
! #print "<$@>\n" if $@;
! $locale;
! };
! return unless $locale =~ m/^[0-9a-fA-F]+$/s;
! return hex($locale);
! }
}
sub get_language {
***************
*** 214,219 ****
--- 228,234 ----
$lang =~ tr/-/_/;
return $lang;
}
+
#-----------------------------------------------------------------------------
# If we're just executed...
***************
*** 295,301 ****
=item Win32::Locale::get_ms_locale()
! Returns the MS locale ID code for the currently selected MSWindows
locale. For example, returns the number 1033 for "US
English". (You may know the number 1033 better as 0x00000409,
as these numbers are usually given in hex in MS documents).
--- 310,316 ----
=item Win32::Locale::get_ms_locale()
! Returns the MS locale ID code for the passed or currently selected
MSWindows
locale. For example, returns the number 1033 for "US
English". (You may know the number 1033 better as 0x00000409,
as these numbers are usually given in hex in MS documents).