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

Unicode Number conversion

Enthusiast ,
Jan 11, 2025 Jan 11, 2025

Copy link to clipboard

Copied

Hi,

I have a list of sentences with numbers at the start. Generally unicode values of numbers should be from 30-39, however, since the matter is in arabic and I need the numerls in 30 - 39 unicode values, I need to convert it from arabic system to english system.

 

i.e \x{6f0} to \x{30} for number 0

\x{6f1} to \x{31} for number 1 .... and so on.

 

As there are more than 10000 numbers it will take forever. How can I do this in InDesign ?

Thanks

TOPICS
How to , Scripting

Views

407

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 , Jan 12, 2025 Jan 12, 2025

If you want to target all numbers, simply remove the ^ in the second line. But if you want to convert only paragraph-initial numbers you need the following:

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '^[\\x{06F0}-\\x{06F9}]+';
d = app.documents[0].findGrep();
for (i = d.length-1; i >= 0; i--) {
  s = d[i].contents;
  for (j = s.length-1; j >= 0; j--) {
    d[i].characters[j].contents = String (s.charCodeAt(j) - 1776);
  }
}

 

Votes

Translate

Translate
Community Expert ,
Jan 11, 2025 Jan 11, 2025

Copy link to clipboard

Copied

A simple script can do this - but would be easier if you post an example screenshot.

 

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
Enthusiast ,
Jan 11, 2025 Jan 11, 2025

Copy link to clipboard

Copied

@Robert at ID-Tasker  and @Eugene Tyson I am attaching sample file.

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 ,
Jan 11, 2025 Jan 11, 2025

Copy link to clipboard

Copied

You might be able to do it with a script - but I don't have ME version of InDesign installed to test - perhaps if you share a sample file or selection of text or something.

I could download the ME version and test it with a custom script if you like. 

 

Should be doable. 

 

You might not need a custom script

There's a find change script already with InDesign that allows you to add GREP search find and replace 

It might work.

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 ,
Jan 11, 2025 Jan 11, 2025

Copy link to clipboard

Copied

@Eugene Tyson

 

You don't need ME version.

 

@Bedazzled532 

 

F&C run 10x times - for every digit - should work.

 

Or do you need to re-calculate values? 

 

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 ,
Jan 11, 2025 Jan 11, 2025

Copy link to clipboard

Copied

 

quote

@Eugene Tyson

 

You don't need ME version.

 

@Bedazzled532 

 

F&C run 10x times - for every digit - should work.

 

Or do you need to re-calculate values? 

 


By @Robert at ID-Tasker

 

Yeh i was thinking that on both of those things

But hey - rather work in the same version the OP is to make sure it's ok.

 

And I was thinking find change for 10 things too 0-9 should do it.

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 ,
Jan 11, 2025 Jan 11, 2025

Copy link to clipboard

Copied

@Eugene Tyson

 

There is a registry trick - on Windows - to have ME functionality in the EN version - without the need to install ME version - everything is already there - just hidden / unavailable. 

 

https://community.adobe.com/t5/indesign-discussions/japanese-language-handling-in-an-english-languag...

 

Can be done on a Mac, too. 

 

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 ,
Jan 11, 2025 Jan 11, 2025

Copy link to clipboard

Copied

The 10-times-find-and-replace works fine, of course, but it's not too difficult to convert found Arabic-Indic digits to, uhm, Arabic:

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '^[\\x{06F0}-\\x{06F9}]';
d = app.documents[0].findGrep();
for (i = d.length-1; i >= 0; i--) {
  d[i].contents = String (d[i].contents.charCodeAt() - 1776);
}

You find an Arabic-Indic digit and replace it with its decimal value minus 1776. (The decimal value of the Arabic-Indic 0 is 1776.)

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
Enthusiast ,
Jan 11, 2025 Jan 11, 2025

Copy link to clipboard

Copied

@Peter Kahrel Thanks for this wonderful code, however, the code works on single digits only. For two or more digits, it is not working. It just takes one digit from 2 or 3 digits number and converts and leaves the rest.

 

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 ,
Jan 12, 2025 Jan 12, 2025

Copy link to clipboard

Copied

If you want to target all numbers, simply remove the ^ in the second line. But if you want to convert only paragraph-initial numbers you need the following:

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '^[\\x{06F0}-\\x{06F9}]+';
d = app.documents[0].findGrep();
for (i = d.length-1; i >= 0; i--) {
  s = d[i].contents;
  for (j = s.length-1; j >= 0; j--) {
    d[i].characters[j].contents = String (s.charCodeAt(j) - 1776);
  }
}

 

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
Enthusiast ,
Jan 12, 2025 Jan 12, 2025

Copy link to clipboard

Copied

@Peter Kahrel Thank you so much. It worked like a charm. I just wanted to convert the paragraph-initial numbers only so just ran the code. No modification was required.

Just one question. Can the same thing be done reverse? e. If i get English numbers and I want to convert to Arabic numbers? Same code will help?

Thanks once again.

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 ,
Jan 12, 2025 Jan 12, 2025

Copy link to clipboard

Copied

I think Peter is a magician - much better than the way I was thinking of it

 

If you want to reverse it I think this will work

I just added an alert to say it was done

 

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '^[\\x{0030}-\\x{0039}]+';
var matches = app.documents[0].findGrep();
for (var i = matches.length - 1; i >= 0; i--) {
    var text = matches[i].contents;
    for (var j = text.length - 1; j >= 0; j--) {
        matches[i].characters[j].contents = String.fromCharCode(text.charCodeAt(j) + 1776);
    }
}
app.findGrepPreferences = null;
alert("English numbers have been converted to Arabic-Indic numbers.");

 

 

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
Enthusiast ,
Jan 12, 2025 Jan 12, 2025

Copy link to clipboard

Copied

@Eugene Tyson Thanks. Ofcourse @Peter Kahrel is a magician. We are in process of thinking, and he comes up with the solution in no time. He has saved me lot of time and efforts. What ever little scripting I have learned is from his code and there are two more persons @rob day  @m1b . They are serving Adobe community with their 2000%.

Thanks a ton to all of you there.

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 ,
Jan 12, 2025 Jan 12, 2025

Copy link to clipboard

Copied

To reverse it, use this one:

 

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '^[\\d]+';
d = app.documents[0].findGrep();
for (i = d.length-1; i >= 0; i--) {
  s = d[i].contents;
  for (j = s.length-1; j >= 0; j--) {
    d[i].characters[j].contents = String.fromCharCode (s.charCodeAt(j)+1728);
  }
}

[Edit: Eugene beat me to it!]

 

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
Enthusiast ,
Jan 12, 2025 Jan 12, 2025

Copy link to clipboard

Copied

@Peter Kahrel Thanks. @Eugene Tyson What did I say in my last post, "we are in process of thinking and he comes with with a solution" and see he came with the solution.

🙂   Thanks once again.

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 ,
Jan 12, 2025 Jan 12, 2025

Copy link to clipboard

Copied

I was thinking it would be just change the - to a + but you've used a different offset of 1728 which is interesting. 

 

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 ,
Jan 12, 2025 Jan 12, 2025

Copy link to clipboard

Copied

LATEST

@Eugene Tyson Your code doesn't convert to Arabic-Indic digits, the result is some Syriac letters (1 > U+0721). The offset should be 1728 to get the desired result:

1 = decimal 49
06F1 = decimal 1777
Difference is 1728

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