Help with Japanese Kanji in file name.
-
I have a plugin that appears to fail when accessing a Drive\Path\FileName that has a folder written in Japanese. Ruby Console message reads:
"Error: #<Errno::ENOENT: No such file or directory - C:\Documents and Settings\corbella\デスクトップ\test_v2000.dxf> C:/Program Files (x86)/Google/Google SketchUp 8/Plugins/dxf_In_v2.0.rb:228:in
initialize'
.
.
.The plugin code at 228 is:
aFile=File.open(chosen_file, "r")`where chosen_file is the result of:
chosen_file=UI.openpanel("Select DXF File","", "*.Dxf")
Any ideas? If it matters at all, I am using NotePad++ to write, and save the code.
-
No way around that. Ruby 1.8 under Windows doesn't handle unicode characters in files. You're stuck with requiring the users to only use ASCII characters.
http://forums.sketchucation.com/viewtopic.php?f=180&t=20657 -
OK, Thanks:(
-
If I error trap the problem part of the code, and a future version of Ruby permits Japanese characters, will the code as written be OK?
. . begin aFile=File.open(chosen_file, "r") rescue #put error message here return # exit the program end .
.
-
Yes.
-
OK, Thanks.
-
Daniel Berger's win32-api libraries have some character conversion methods that may help. But your users will have to have his libs installed on their Windows machines.
The specific lib file is named unicode.rb, and is part of the windows-pr library (which I believe also requires the win32-api library.)
They are available as gems, (choose the highest version) from:
http://rubygems.org/search?page=1&query=win32-&utf8=%E2%9C%93Or source from his Github pages:
windows-pr
https://github.com/djberg96/windows-prwin32-api
https://github.com/djberg96/win32-api -
Thanks Dan, But I rather not mess with his machine.
-
Ruby was written in Japan by guys who use Kanji.
From the "Pick-Axe" book:
http://phrogz.net/ProgrammingRuby/rubyworld.html#rubyanditsworld@unknownuser said:
Command-Line Options
-K kcode
Specifies the code set to be used. This option is useful mainly when Ruby is used for Japanese-language processing. kcode may be one of: e, E for EUC; s, S for SJIS; u, U for UTF-8; or a, A, n, N for ASCII.http://phrogz.net/ProgrammingRuby/language.html#therubylanguage
@unknownuser said:
Source Layout
Ruby programs are written in 7-bit ASCII. (Ruby also has extensive support for Kanji, using the EUC, SJIS, or UTF-8 coding system. If a code set other than 7-bit ASCII is used, the KCODE option must be set appropriately, as shown in the section on command-line options.)
At the command line, the setting is accessed via the global $KCODE
$KCODE
UTF8
(This is set by Sketchup just after it loads Ruby.)$KCODE='S'
SJIS
$KCODE='E'
EUC
$KCODE='U'
UTF8
Don't know if changing it "on-the-fly" will help.. but it may be worth a shot. (Change it back to UTF8 after processing the pathstring.)
-
Sorry Dan, Guess this is over my head, but thanks anyway.
Advertisement