Skip to main content
_wckdTall_
Inspiring
March 3, 2025
Answered

Text Encoding changing from Japanese to gibberish

  • March 3, 2025
  • 2 replies
  • 1525 views

I have a script I'm running that changes localized type in swatches from Japanese to Gibberish. It works ok on when run by itself, but when run within other functions it's breaking. Is there an overall encoding for files that I should be using? Or a way to convert the string back so that it reads properly?
Example White:
ホワイト
Converts to:
ホワイト
When used as key in the alert, so I'm guessing it's not finding the swatch either.

        var swConvert = {
            "CMYK レッド": "CMYK Red",
            "CMYK イエロー": "CMYK Yellow",
            "CMYK グリーン": "CMYK Green",
            "CMYK シアン": "CMYK Cyan",
            "CMYK ブルー": "CMYK Blue",
            "CMYK マゼンタ": "CMYK Magenta",
            "ホワイト、ブラック": "White, Black",
            "オレンジ、イエロー": "Orange, Yellow",
            "色あせた空": "Fading Sky",
            "スーパーソフトブラックビネット": "Super Soft Black Vignette",
            "木の葉": "Foliage",
            "ポンパドール": "Pompadour",
            "ホワイト": "White",
            "ブラック": "Black",
            "[レジストレーション]": "[Registration]"
        }
        for (key in swConvert) {
            alert(key+" - "+swConvert[key]);
            try { aD.swatches[key].name = swConvert[key]; } catch (e) {};
        }

 

Correct answer _wckdTall_

Thanks @m1b !
At a global script level, $.appEncoding = 'UTF-8'; did not work. Placed directly inside the function, it fixes it!

I'm using Visual Studio Code, and tried to resave my JSX, but there is no option for encoding there. Is there a header I should have include on my file instead?

2 replies

Community Expert
March 5, 2025

I'm a bit confused by the Japanese in the script list. The Katagana characters: "ホワイト" are a sort of phonetic version of the English word White. Hiragana would be used to phonetically sound out Japanese words. The actual Japanese word for White is Shiro. Google's translate app shows a Kanji glyph: 白 (or the adjective Shiroi 白い).

m1b
Community Expert
Community Expert
March 5, 2025

@Bobby Henderson I think this reflects the Japanese tendency to use katakana for borrowed or technical terms in modern contexts like software. I'm no expert, but use of the English phonetic spelling here might convey a sense of context where "shiro" might actually *feel* out of place? That last is just a speculation. Actually, we can ask an expert if not too busy: @sttk3 am I on the right track?

- Mark

Legend
March 6, 2025

Yes, it is the right thinking. Since we will frequently refer to English resources in the context of software, it is easier to cross-convert the meaning of words if we use katakana for the sounds.

 

If we were to use a Japanese word, it would be difficult to understand the meaning unless kanji is used for the parts of the word where kanji can be used, such as “白”.

 

Expressions like “shiro” are called “roma-ji” notation. Some people, especially old people, use this notation for variable names, etc., but it is generally regarded as a bad practice.

 

In addition, concepts used mainly in Japanese are defined in “roma-ji”. For example, “mojikumi” and “kinsoku” in Illustrator fall into this category.

m1b
Community Expert
Community Expert
March 5, 2025

Hi @_wckdTall_ aside from ensuring the script file is encoded as UTF-8 (given that I can save and open it and the Japanese characters are fine I assume this is adequate), you can also add this to the start of your script and see if it helps:

$.appEncoding = 'UTF-8';

- Mark

_wckdTall_
_wckdTall_AuthorCorrect answer
Inspiring
March 5, 2025

Thanks @m1b !
At a global script level, $.appEncoding = 'UTF-8'; did not work. Placed directly inside the function, it fixes it!

I'm using Visual Studio Code, and tried to resave my JSX, but there is no option for encoding there. Is there a header I should have include on my file instead?

m1b
Community Expert
Community Expert
March 5, 2025

@_wckdTall_  That's interesting. Actually when I look at my code I do always use it inside a function, but I'm surprised it can't be set anywhere.

 

About VSCode, you just need to set the encoding on the file—easiest way is to click the bottom right corner where it shows the current encoding, and choose "Save with encoding" in the command bar at the top.

 

I'm pretty sure there was a case where I had to save a .csv file as "UTF-8 With Bom" for something, maybe to link to Indesign file? BOM is a few characters at the start of the file I think. I doubt you need to use it here, but I thought I'd mention it. 

- Mark