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

Scripts in Localized InDesign : locale independent default names

Participant ,
Jun 20, 2021 Jun 20, 2021

Copy link to clipboard

Copied

Hi All!

I am asking this question because I do not have enough experience with localized versions of InDesign, but at the moment my script needs to be used with such a version of InDesign.

In my script I need to use the default layer named "Layer 1". Localized versions of InDesign use different names.
When it comes to translating menu strings, one must use a localization-independent notation with the "$ID/" prefix.

The layer name is also numbered. How to do the right thing here?

 

 

app.translateKeyString("$ID/Layer 1")

 

 The same goes for the default style names....

Will it be correct to use such code? Is it possible to somehow find all the lines in independent localization?

 

TOPICS
Scripting

Views

278

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 , Jun 21, 2021 Jun 21, 2021

Ok. That will work for you, if you do not want to add a document and read out the layer name when running your script on a localized version:

app.translateKeyString("$ID/Placeholder for Level 1")

 

But you cannot guess or calculate what the name is with a German InDesign in advance, if you open a document in an English version. For that you need access to a list of localized strings, I think. If you find a way to change the locale value of an installed InDesign by scripting, let me know.

 

Thank

...

Votes

Translate

Translate
Community Expert ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

Hi vnh68,

interesting question.

 

I tried the following with my German InDesign 2021 where the "standard" layer in a new document is named "Ebene 1":

 

 

app.findKeyStrings("Ebene 1");
// Returned array contained one item that holds the string:
// "$ID/Placeholder for Level 1"

 

 

So I tried the following code to access the "standard" layer with that string:

 

var resultArray = app.findKeyStrings("Ebene 1");
// Returned array contained one item that holds the string:
// "$ID/Placeholder for Level 1"

var newDoc = app.documents.add();
var standardLayer = newDoc.layers.itemByName( resultArray[0] );
standardLayer.isValid;
// returns true

 

 

So, this question is answered.

String "$ID/Placeholder for Level 1" is the independent name for that layer.

 

If the layer was renamed perhaps and you want to add a new layer with the "standard" name you could do it like that:

 

app.documents[0].layers.add({ name : "$ID/Placeholder for Level 1"} )

 

Of course this code has to run on the localized version of InDesign.

 

What will not work the same way in this case is:

 

app.documents[0].layers.add();

 

It will add a new "standard" layer with a different name, perhaps "Ebene 2" with my German document.

 

What you cannot do without knowing the name of a "standard" layer:

Add the layer named in English when you running the script on a German InDesign.

However, now you know how to identify a standard name.

//EDIT: Wrong. See next post.

 

 

FWIW: Standard layer names are not renamed when you open a document in a different localized version of InDesign.

 

And perhaps you already guessed it now:

 

var resultArray = app.findKeyStrings("Ebene 2");
// Returned array contained one item that holds the string:
// "$ID/Placeholder for Level 2"

 

 

Regards,
Uwe Laubender

( ACP )

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 ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

Ok. That will work for you, if you do not want to add a document and read out the layer name when running your script on a localized version:

app.translateKeyString("$ID/Placeholder for Level 1")

 

But you cannot guess or calculate what the name is with a German InDesign in advance, if you open a document in an English version. For that you need access to a list of localized strings, I think. If you find a way to change the locale value of an installed InDesign by scripting, let me know.

 

Thanks,
Uwe Laubender

( ACP )

 

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 01, 2023 Jul 01, 2023

Copy link to clipboard

Copied

LATEST

Maybe this message will be irrelevant, but maybe someone will find it useful. There is a way to change the locale (the language of the user interface ) without reinstalling InDesign!
When I was looking for an answer to this question, I accidentally came across a video:  https://www.youtube.com/watch?v=IlZWNLzavR8

 

Due to the fact that many InDesign users use a localized (non-English) interface, some scripts created on the English interface may work unexpectedly.
If you re-read this thread, you will see that some default names, such as styles or layers with square brackets around the name, are translated to another language and the English name of the same instance will be invisible.
Therefore, if you distribute your script that affects default names (such as 'Layer 1' or the style names [None] or [Basic Paragraph]), then instead of using the English default names, you should use a string like this:

var nameOfLayer_1_localized = app.translateKeyString("$ID/Placeholder for Layer 1");

instead of 

var nameOfLayer = "Layer 1";

This will make the script work stable regardless of the locale of the UI. As for the locale of the script itself, it can either support several locales or remain in English without translation.

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