0

I'm working on MacOS 12 and VS Code. When I select a file with a Japanese file name and output it to the console:

File.openDialog();
$.writeln(file.name);

the Japanese characters are lost and I get gibberish (a mix of number/characters/percentage symbols). I have added Japanese as a preferred language in Mac OS, switched to Japanese as keyboard output, changed the language of VS Code to Japanese, changed in the Settings of VS Code "Files:Encoding" from UTF-8 to Shift JIS, but nothing helped.

Could someone please help?

Thanks!

  • Numbers, characters and percent? seems the filename is URL Encoded or percent encoded. – fnostro Apr 07 '22 at 18:13
  • That's probably true, since VC Code doesn't recognise Japanese characters. The actual file name is in Japanese, though. – Another Joe Apr 08 '22 at 07:44
  • So, @fnostro thanks to your comment, I have researched more about URL encoding and found this post: https://stackoverflow.com/questions/332872/encode-url-in-javascript which perfectly help. I'll update my post accordingly - thanks for the help! – Another Joe Apr 08 '22 at 14:30

1 Answers1

0

Update: Even simpler, using file.fsName gives back Japanese characters. How could I have missed that…


This post holds the answer: Encode URL in JavaScript?

You can encode/decode the 'gibberish' with decodeURIComponent(str) and decodeURIComponent(str) respectively and in my case, it worked perfectly.

(Thanks @fnostro for the comment which helped me research in the right direction.)