hi,all:
I have a problem, I don’t know how to find out what is the current
local encoding by ruby script, My script must can be run on windows or
linux platform.
who can tell me how to do, thanks very much.
liwenqiu
Best regards
On 10/22/07, venture Lee [email protected] wrote:
hi,all:
I have a problem, I don’t know how to find out what is the current
local encoding by ruby script, My script must can be run on windows or
linux platform.
who can tell me how to do, thanks very much.
There’s no cross-platform way of telling this. LC_LANG will tell you
some things (not always truthfully or usefully, since it can change)
on Linux. I’m not sure that there’s an easy way to get what you want
from Ruby on Windows, as Ruby scripts run under the console (ruby.exe)
might return different values than Ruby scripts run without a console
(rubyw.exe), and you’d need a Win32API call.
You’re probably better of reformulating what you want.
-austin
if use wxruby can solve my problem, example:
require ‘wx’
puts Wx::Locale.get_system_encoding_name
this code will output ‘cp936’ on my windows and output ‘UTF8’ on my
linux.
but it need wxruby, i want to know how to implement same function
without
wxruby, thanks.
On 10/22/07, venture Lee [email protected] wrote:
if use wxruby can solve my problem, example:
require ‘wx’
puts Wx::Locale.get_system_encoding_name
this code will output ‘cp936’ on my windows and output ‘UTF8’ on my linux.
but it need wxruby, i want to know how to implement same function without
wxruby, thanks.
Look at the implementation of wxruby, then. That’ll have the C
functions you need to call.
-austin
On 10/22/07, venture Lee [email protected] wrote:
i not a c/c++ programer
That may be. There’s no inbuilt Ruby way to get what you want.
-austin
Austin Z. wrote:
On 10/22/07, venture Lee [email protected] wrote:
i not a c/c++ programer
That may be. There’s no inbuilt Ruby way to get what you want.
No, but there’s windows-pr.
require ‘windows/national’
include Windows::National
buf = 0.chr * 32
GetLocaleInfo(
LOCALE_SYSTEM_DEFAULT,
LOCALE_IDEFAULTCODEPAGE,
buf,
buf.length
)
cp = buf.strip.to_i
Results on my system
p cp # => 437, literal code page
p CODE_PAGE[cp] # => “OEM = United States”
Regards,
Dan
PS - Those curious about the “OEM” thing can read
http://blogs.msdn.com/oldnewthing/archive/2005/08/29/457483.aspx
Daniel B. wrote:
GetLocaleInfo(
LOCALE_SYSTEM_DEFAULT,
…
PS - Those curious about the “OEM” thing can read
http://blogs.msdn.com/oldnewthing/archive/2005/08/29/457483.aspx
Note also that “system default” is the language in which the system
was installed. Modern Windows OS’ can have multiple languages installed,
and you should probably ask for the user’s preferred language if you
want to talk to users.
Clifford H…
Hi,
At Wed, 24 Oct 2007 09:47:38 +0900,
Daniel B. wrote in [ruby-talk:275530]:
p cp # => 437, literal code page
p CODE_PAGE[cp] # => “OEM = United States”
Don’t you know how to tell MIME encoding name from a codepage?
CodePageName in CPINFOEXA seems to have it sometimes, but not
always.