Copy link to clipboard
Copied
Hello everyone,
I'm facing a persistent issue with a JavaScript I'm writing for InDesign. I'm trying to duplicate a paragraph style and apply the "Dutch: 2005 spelling reform" language to it.
The issue is that I keep getting different errors, and none of the standard methods seem to work.
What I'm trying to do :
Duplicate an existing paragraph style called "journal_actu_item_1_FR".
Rename the new style to "journal_actu_item_1_NL".
Apply the "Dutch: 2005 spelling reform" language to this new style.
Errors I have encountered so far :
When using app.languages.itemByID(96) : "Object does not support the property or method 'languages'."
When using doc.languages.itemByID(96) : "Incorrect value for the property set 'appliedLanguage'. Expected LanguageWithVendors, Language or String, but received nothing."
When using a language name like "Dutch: 2005 spelling reform" or "Néerlandais réforme 2005" : The language is not applied, and the style remains in French (the default language).
This is particularly tricky because app.languages.item("Dutch") works, but this is the wrong version of the language.
Could anyone share a robust and compatible method to apply the language with ID 96 to a paragraph style? Any help would be greatly appreciated.
Thank you!
Hi @HEAJHP , appliedLanguage is a property of the paragraphStyle (not the app or doc, which you are trying to set). A document could contain multiple languages, so appliedLanguage can also be a property of a character, word, paragraph, paragraphStyle, etc.
https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#ParagraphStyle_2.html
https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#ParagraphStyle_2.html
Hi @HEAJHP, I can confirm that there is definitely a bug with the app.LanguagesWithVendors.itemByName method: it does not return a valid language when you ask for "Dutch: 2005 Reform".
Fortunately it is simple to work around—loop through all the languages and you will find one named "Dutch: 2005 Reform".
Here is example code:
/**
* @file Make Dutch Style.js
*
* Duplicates the source style and applies Dutch language to it.
*
* @author m1b
* @version 2025-09-05
* @discussion https://com
...
Copy link to clipboard
Copied
Hi @HEAJHP , appliedLanguage is a property of the paragraphStyle (not the app or doc, which you are trying to set). A document could contain multiple languages, so appliedLanguage can also be a property of a character, word, paragraph, paragraphStyle, etc.
https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#ParagraphStyle_2.html
https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#ParagraphStyle_2.html
Copy link to clipboard
Copied
Thank you for your help!
Copy link to clipboard
Copied
Hi @HEAJHP, I can confirm that there is definitely a bug with the app.LanguagesWithVendors.itemByName method: it does not return a valid language when you ask for "Dutch: 2005 Reform".
Fortunately it is simple to work around—loop through all the languages and you will find one named "Dutch: 2005 Reform".
Here is example code:
/**
* @file Make Dutch Style.js
*
* Duplicates the source style and applies Dutch language to it.
*
* @author m1b
* @version 2025-09-05
* @discussion https://community.adobe.com/t5/indesign-discussions/javascript-amp-colon-appliedlanguage-error-with-dutch-spelling-reform-id-96-in-indesign/m-p/15489771
*/
function main() {
var sourceParagraphStyleName = 'journal_actu_item_1_FR';
var targetLanguageUntranslatedName = 'nl_NL_2005';
var targetLanguageCode = 'NL';
var doc = app.activeDocument;
var sourceStyle = getThing(doc.allParagraphStyles, 'name', sourceParagraphStyleName);
if (!sourceStyle)
return alert('Paragraph style "' + sourceParagraphStyleName + '" is not valid.');
var targetLanguage = getThing(app.languagesWithVendors, 'untranslatedName', targetLanguageUntranslatedName);
if (!targetLanguage)
return alert('Language "' + targetLanguageUntranslatedName + '" is not valid.');
var matchTrailingCountryCode = /_[A-Z]{2}$/;
var destinationStyle = sourceStyle.duplicate();
var newName = matchTrailingCountryCode.test(sourceStyle.name)
? sourceStyle.name.replace(matchTrailingCountryCode, '_' + targetLanguageCode)
: sourceStyle.name + '_' + targetLanguageCode;
destinationStyle.properties = {
name: newName,
appliedLanguage: targetLanguage,
};
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Make Dutch Style');
/**
* Returns a thing with matching property.
* If `key` is undefined, evaluate the object itself.
* @author m1b
* @version 2024-04-21
* @param {Array|Collection} things - the things to look through.
* @param {String} [key] - the property name (default: undefined).
* @param {*} value - the value to match.
* @returns {*?} - the thing, if found.
*/
function getThing(things, key, value) {
for (var i = 0; i < things.length; i++)
if ((undefined == key ? things[i] : things[i][key]) == value)
return things[i];
};
Edit 2025-09-05: for getting the language, I changed the lookup property from "name" to "untranslatedName" in accordance with the great information supplied by @Laubender. I hope this will work on any language version of Indesign.
P.S. anyone looking for the "untranslatedName" of a particular language? Run this code to get a list:
(function () {
var everyLanguage = app.languagesWithVendors.everyItem();
var names = everyLanguage.name;
var untranslatedNames = everyLanguage.untranslatedName;
var printout = 'Language Name / Untranslated';
for (var i = 1; i < names.length; i++)
printout += '\n' + names[i] + ' / ' + untranslatedNames[i];
alert (printout);
})();
Copy link to clipboard
Copied
Scripting problem solved! A huge thank you !
Copy link to clipboard
Copied
That numeric ID is unfortunate, it can change across app versions and documents.
For example I just tried a new document
app.activeDocument.languages.itemByID(96).properties.toSource()
({name:"Italian", singleQuotes:"‘’", doubleQuotes:"“”", icuLocaleName:"it_IT", untranslatedName:"Italian", hyphenationVendor:"Hunspell", spellingVendor:"Hunspell", id:96, label:"", parent:resolve("/document[@id=1]"), index:32})
I don't know why the object model for appliedLanguage claims Language as also supported type.
Maybe if the current application version does not support the language?
Export an example text frame with your language applied as snippet.
Open the snippet in a text editor.
See the applied language as attribute
<CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]" AppliedLanguage="$ID/nl_NL_2005">
<Content>Dutch</Content>
</CharacterStyleRange>
Proof on the text selection, it previously had a different language:
app.selection[0].appliedLanguage = "$ID/nl_NL_2005"
$ID/nl_NL_2005
app.selection[0].appliedLanguage
[object LanguageWithVendors]
app.selection[0].appliedLanguage.toSpecifier()
/language-with-vendors[@id=96]
resolve('/language-with-vendors[@id=96]')
[object LanguageWithVendors]
resolve('/language-with-vendors[@id=96]').name
Dutch: 2005 Reform
Copy link to clipboard
Copied
I have lodged a bug. Please vote on it if you can.
Copy link to clipboard
Copied
I always derive lasting satisfaction from upvoting somebody else's localization bug report.
Copy link to clipboard
Copied
@m1b said: "Fortunately it is simple to work around—loop through all the languages and you will find one named "Dutch: 2005 Reform"."
Well, only with an English localized InDesign version, I guess.
With my German version of InDesign you may find nothing, because the German string for the name is "Niederländisch: 2005 Rechtschreibreform".
To get the version of the string that works for every InDesign version you could ask the applied paragraph style after the value for property untranslatedName:
var appliedParaStyle = app.selection[0].appliedParagraphStyle;
alert( appliedParaStyle.appliedLanguage.untranslatedName );
If the paragraph style is using "Dutch: 2005 spelling reform" the alert will return:
"nl_NL_2005"
A snippet's XML will translate this value to:
"$ID/nl_NL_2005"
So, in the end the string that will work in every locale could be:
"$ID/" + untranslatedName
For example, if you want to add a new paragraph style with Dutch: 2005 spelling reform you could use the string directly like in the code below that worked in my German InDesign:
var newParaStyle = app.documents[0].paragraphStyles.add
(
{
name : "newParaStyle" +"_"+ Date.now() ,
appliedLanguage : "$ID/nl_NL_2005"
}
);
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Thanks, that is excellent info @Laubender! I have incorporated your insight into my example above and I hope it will now work on any language version of indesign.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now