• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to use Cyrillic in your code

Participant ,
Jul 25, 2020 Jul 25, 2020

Copy link to clipboard

Copied

Is it possible to use Cyrillic characters in the Javascript code, for example:

app.addMenuItem({ cName: "test", cUser: "test", cParent: "Help", nPos: -1, 
		cExec: "test()", cEnable: "event.rc = (event.target != null);"}); 
function test() {
app.alert("Привет!", 3);
}

Instead of Cyrillic characters, the function "app.alert" displays a set of characters corresponding to the CP1361 encoding (according to the online encoder).
Does anyone have any experience with this issue?

TOPICS
How to , Windows

Views

690

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 26, 2020 Jul 26, 2020

It works when you run it from the console, but it doesn't work when you place the code in a text file, no matter the encoding (as far as I could see, at least). The way around it is to use the Unicode escape codes. For example, the first letter ("П") in your text can be displayed like this:

app.alert("\u041f", 3);

So you just need to convert your string to Unicode characters and then you'll be able to display it. Not ideal, but it works...

Votes

Translate

Translate
Community Expert ,
Jul 26, 2020 Jul 26, 2020

Copy link to clipboard

Copied

It works when you run it from the console, but it doesn't work when you place the code in a text file, no matter the encoding (as far as I could see, at least). The way around it is to use the Unicode escape codes. For example, the first letter ("П") in your text can be displayed like this:

app.alert("\u041f", 3);

So you just need to convert your string to Unicode characters and then you'll be able to display it. Not ideal, but it works...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 26, 2020 Jul 26, 2020

Copy link to clipboard

Copied

Works! Again, thank you. Incredibly, I would never have thought of this decision!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 07, 2024 Oct 07, 2024

Copy link to clipboard

Copied

Even Unicode escape codes don’t seem to work in the actual menu item name itself. For example, if I want to add a menu item named Funny ‘Item’ here (with curly single quotes), no matter which text encoding the JS file has, and regardless of whether I use Unicode escape codes, it always ends up garbled.

 

In a UTF-8 file with Unicode escape codes, it ends up as Funny ÔItemÕ here. This – bizarrely – corresponds to what I get if I save the JS file as ISO-8859-1 and don’t use Unicode escape codes, through whatever black magic Acrobat uses to arrive at that particular result…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2024 Oct 07, 2024

Copy link to clipboard

Copied

Works fine for me, using the method described above:

 

try67_0-1728320926954.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 07, 2024 Oct 07, 2024

Copy link to clipboard

Copied

Huh, now that is odd!

 

And you’re just using the Unicode escape code inside the string as a regular character? Like so:

 

 

app.addMenuItem({
  cName: "Funny \u2018Item\u2019 here",
  cParent: "File",
  cExec: "blah();"
});

 

 

Which encoding is your JS file? Perhaps it’s a Mac thing..?

 

Edit: I’m actually creating a submenu and then adding the item inside that submenu, but I don’t see why that should make any difference to the encoding…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2024 Oct 07, 2024

Copy link to clipboard

Copied

I think I see what's your issue there. cName is the parameter the defines the internal name of the menu item. If you only specify it then it's also used as the label, but it's possible it only accepts ANSI characters, not Unicode ones. I specified the cUser parameter with this string, and then it worked. My .js file is encoded as UTF-8, by the way.

This is the code I used:

 


var newItemName = new String("Funny \u2018Item\u2019");
app.addMenuItem({ cName: "Test", cUser: newItemName, cParent: "Edit", nPos: -1,
cExec: "void(0)", cEnable: "event.rc = true;"});

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

LATEST

Aha – that was it! I didn’t realise cName just sets the internal name and hadn’t found the cUser property (honestly, what kind of misleading name is cUser for a property that sets a label?). Creating a String object and using that in the cUser property did the trick and worked like a charm.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines