Skip to main content
Dmitriy K.
Known Participant
July 25, 2020
Answered

How to use Cyrillic in your code

  • July 25, 2020
  • 1 reply
  • 1647 views

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?

This topic has been closed for replies.
Correct answer try67

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...

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 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...

Janus Bahs Jacquet
Inspiring
October 7, 2024

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…

try67
Community Expert
Community Expert
October 7, 2024

Works fine for me, using the method described above: