Skip Menu |
 

This queue is for tickets about the Win32-Locale CPAN distribution.

Report information
The Basics
Id: 11739
Status: new
Priority: 0/
Queue: Win32-Locale

People
Owner: Nobody in particular
Requestors: chris+rt [...] chrisdolan.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.04
Fixed in: (no value)



Subject: Add codepage support
Download (untitled) / with headers
text/plain 896b
Under WinXP, the Regional Settings control panel has two major options: the locale (on the Regional Options tab) and the default language (on the Advance tab). The Win32::Locale module reports the value of the former setting. The attached patch is a prototype to report the value of the latter setting. Put simply, this is the value in HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Nls/Language.Default Additionally, Windows records the language that was selected when Windows was installed in HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Nls/Language.InstallLanguage These values signify the default encoding used for all non-Unicode Windows applications, including filesystem interaction. I'd love to see Win32::Codepage become part of the Win32::Locale package, but if that doesn't seem proper, I suppose I could probably package it for CPAN myself as a separate package.
Download Codepage.pm
text/x-perl 1k
package Win32::Codepage; use warnings; use strict; use Win32::Locale; our $VERSION = '1.00'; sub _get_lang_reg_key { my $langkey; local $SIG{"__DIE__"} = ""; eval ' use Win32::TieRegistry (); $langkey = Win32::TieRegistry->new( "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Nls/Language", { Delimiter => "/" } ); '; return $langkey; } sub get_ms_install_codepage { my $key = _get_lang_reg_key() || return; my $codepage = $key->GetValue("InstallLanguage"); return unless $codepage =~ m/^[0-9a-fA-F]+$/s; return hex($codepage); } sub get_ms_codepage { my $key = _get_lang_reg_key() || return; my $codepage = $key->GetValue("Default"); return unless $codepage =~ m/^[0-9a-fA-F]+$/s; return hex($codepage); } sub get_install_codepage { my $lang = $Win32::Locale::MSLocale2LangTag{ $_[0] || get_ms_install_codepage() || '' }; return unless $lang; return $lang; } sub get_codepage { my $lang = $Win32::Locale::MSLocale2LangTag{ $_[0] || get_ms_codepage() || '' }; return unless $lang; return $lang; } 1;
From: Chris Dolan
Download (untitled) / with headers
text/plain 106b
Updated Win32::Codepage module (I overlooked the encoding, which is one of the most important parts, IMO)
Download Codepage.pm
text/x-perl 2.1k
package Win32::Codepage; use warnings; use strict; use Win32::Locale; our $VERSION = '1.00'; sub _get_codepage_reg_key { my $codekey; local $SIG{"__DIE__"} = ""; eval ' use Win32::TieRegistry (); $codekey = Win32::TieRegistry->new( "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Nls/CodePage", { Delimiter => "/" } ); '; return $codekey; } sub _get_lang_reg_key { my $langkey; local $SIG{"__DIE__"} = ""; eval ' use Win32::TieRegistry (); $langkey = Win32::TieRegistry->new( "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Nls/Language", { Delimiter => "/" } ); '; return $langkey; } sub get_encoding { # Returns an encoding name usable with Encode.pm based on the current codepage # e.g. cp1252 for iso-8859-1 (latin-1) or cp932 to Shift-JIS Japanese my $key = _get_codepage_reg_key() || return; my $codepage = $key->GetValue("ACP") || $key->GetValue("OEMCP"); return unless $codepage && $codepage =~ m/^[0-9a-fA-F]+$/s; return "cp".$codepage; } sub get_ms_install_codepage { # Returns the language id for the codepage language at install time # e.g. 0x0409 for en-us or 0x0411 for ja my $key = _get_lang_reg_key() || return; my $codepage = $key->GetValue("InstallLanguage"); return unless $codepage && $codepage =~ m/^[0-9a-fA-F]+$/s; return hex($codepage); } sub get_ms_codepage { # Returns the language id for the current codepage language # e.g. 0x0409 for en-us or 0x0411 for ja my $key = _get_lang_reg_key() || return; my $codepage = $key->GetValue("Default"); return unless $codepage && $codepage =~ m/^[0-9a-fA-F]+$/s; return hex($codepage); } sub get_install_codepage { # Returns the language name for the codepage language at install time # e.g. en-us or ja my $lang = $Win32::Locale::MSLocale2LangTag{ $_[0] || get_ms_install_codepage() || '' }; return unless $lang; return $lang; } sub get_codepage { # Returns the language name for the current codepage language # e.g. en-us or ja my $lang = $Win32::Locale::MSLocale2LangTag{ $_[0] || get_ms_codepage() || '' }; return unless $lang; return $lang; } 1;
From: cdolan [...] cpan.org
Download (untitled) / with headers
text/plain 144b
Today I uploaded my own module, Win32::Codepage, which includes a derivative of the code attached above. Please consider this request resolved.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.