Skip to main content
Participating Frequently
May 31, 2022
Question

Paragraph.appliedLanguage seems to differ from the actual applied language

  • May 31, 2022
  • 4 replies
  • 2094 views

Recently I wrote a script to deal with typographic interpunction glyphs. At some point I got confused:

I've set the doubleQuotes property of one particular language (Deutsch: 2006 Rechtschreibreform) once in the app without any open document (language.id == 61)

app.languagesWithVendors.itemByID(61).doubleQuotes
→ „“

Then I opened a document and applied different glyphs for this (»«). When I now type quotes into the first paragraph, they are replaced by these glyphs.

The glyph setting in the document results in a new language id of 66:

document.languages.everyItem().id
→ 66
document.languages.itemByID(66).doubleQuotes
→ »«

So far, everything is as expected. But when I inspect the language properties of the first paragraph, I get the setting from the app itself, although this does obviously not apply when typing.

document.textFrames.firstItem().paragraphs.firstItem().appliedLanguage.id
→ 61
document.textFrames.firstItem().paragraphs.firstItem().appliedLanguage.doubleQuotes
→ „“
This topic has been closed for replies.

4 replies

Brainiac
June 10, 2022

Just a note, also to myself, property untranslatedName of language and languageWithVendors was added to the DOM with InDesign 2015 version 11.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Participating Frequently
June 8, 2022

After several answers with interesting hints, the basic question remains open: When I do configuration for a language in a document, such as setting doubleQuotes, this language can be found in the document object's list of languages and has another id than that in the application object's list.

But when I access text inside the document – regardless what I inspect, paragraph, words, character, textStyleRange – I always get the language properties as set in the app, not in the document.

I still believe this to be a software bug.

Brainiac
June 10, 2022

" I always get the language properties as set in the app, not in the document. I still believe this to be a software bug."

 

Could also be a questionable design decision. If it is a bug, it is very old and I do not think, it will be fixed soon.

 

Nevertheless you could do a bug report at InDesign UserVoice.

As a result of this discussion the obvious workaround is to get the value of the appliedLanguage.untranslatedName of a textStyleRange and feed it as argument to doc.languages.itemByName() so you can see the right value for e.g. doubleQuotes or singleQuotes.

 

 

 

var doc = app.documents[0];
var textStyleRanges =
doc.stories.everyItem().textStyleRanges.everyItem().getElements();

for( var n=0; n<textStyleRanges.length; n++ )
{
	var untranslatedName = 
	textStyleRanges[n].appliedLanguage.untranslatedName;
	var doubleQuotes = 
	doc.languages.itemByName( untranslatedName ).doubleQuotes;
	
	$.writeln( n +"\t"+ untranslatedName +"\t"+ doubleQuotes );
};

 

 

 

Thanks to Rob Day who pointed at property untranslatedName.

The code above is working without issues in my German version of InDesign 2022 on Windows 10.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Brainiac
June 10, 2022

Hi Uwe, I don‘t do enough language work to understand why there are two different collections, but the app’s LanguagesWithVendors is a collection of LanguageWithVendors objects, while the document’s Languages is a collection of Language objects. The Language and LanguageWithVendors objects don’t have matching properties, so it’s not surprising that they return different ids.

 

LanguageWithVendors has dictionaryPaths, hyphenationVendorList, spellingVendorList, and thesaurusVendor properties, which the Language object does not have


Hi Rob,

well, hyphenationVendor or spellingVendor is also available for language.

dictionaryPaths is not a document specific property so it makes sense to bind it with languageWithVendors in application.

 

To get a specific hyphenationVendor for a text style range of a document it works very well like this:

 

var doc = app.documents[0];
var textStyleRanges =
doc.stories.everyItem().textStyleRanges.everyItem().getElements();

for( var n=0; n<textStyleRanges.length; n++ )
{
	var untranslatedName = 
	textStyleRanges[n].appliedLanguage.untranslatedName;
	var hyphenationVendor = 
	doc.languages.itemByName( untranslatedName ).hyphenationVendor;
	
	$.writeln( n +"\t"+ untranslatedName +"\t"+ hyphenationVendor );
};

/*
	
0	de_DE_2006	Duden
1	English: UK	Hunspell
2	de_DE_2006	Duden
	
*/

 

So I get what I want in case…

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Brainiac
June 2, 2022

When you output an array in some environments, they will get converted to string with a routine that omits the square brackets. With a single item you also get no comma, giving the perception of an integer.

Besides, the applied language is a character attribute. The largest text entity to examine would be textStyleRun rather than paragraph (I think that only looks at the first character). You can also see the effect at the character attributes panel - when the entire paragraph is selected you might see a mixed indicator.

Also don't rely on those IDs, they are allocated consecutively first come first serve in the initial startup process (for application preferences), or when a document is created. The next version of InDesign might behave differently. This has also recently caused some problems where an IDML generator was not prepared for shifting numbers.

I'd have to look for details, but I think there are also some differences between language and language with vendor, e.g. for languages where multiple vendors provide hyphenation etc. dictionary.

Participating Frequently
June 2, 2022

Thanks so far. What is your adivce to look for the language property of text. Inspect textStyleRange? I had looked into the paragraph, because the language is set in the paragraph style. But you are right, this is also in the character style and thus a character property.

Adobe Expert
June 1, 2022

This I don't understand:

>  The glyph setting in the document results in a new language id of 66:

Changing the quotes to different characters shouldn't add any languages.

And this, too, is unclear to me:

document.languages.everyItem().id
→ 66

When I do this, an array is returned that contains the IDs of all installed languages (60, in my case).

What do the following statements return at your end? 

app.languageWithVendors.length
app.documents[0].languageWithVendors.length

 P.

Participating Frequently
June 1, 2022

When I change the glyph setting in the language, while a document is opened, then I find that this affected language is saved in the document's list of languages (document.languages) and has another id (66) than the original language, that I find in app.languageWithVendors, has (61).