4 Replies Latest reply on Dec 5, 2011 8:31 AM by Marc Autret

    [JS] Find invalid language

    [Jongware] Most Valuable Participant

      (Related to InDesignSecrets Script to change the language of all text on document)

       

      I'm trying to identify, and then replace "invalid" languages -- the ones that creep in with Word document and InDesign blithely ignores because it's not in its internal list.

      Locating them is, well, convulated but straightforward:

       

      1. Gather all languages in a document

      2. Loop over this list and remove the ones that are in InDesign's internal array

       

      Next step would be to replace the result with a valid language. However, the type of an 'unsupported language' cannot be easily converted to one that feeds into findTextPreferences.appliedLanguage. When handing it over the plain string, ID complains

       

      Invalid value for set property 'appliedLanguage'. Expected String, Language, LanguageWithVendors or NothingEnum enumerator, but received "English: Australian".

       

      Yeah ... so "English: Australian" is apparently not a string. So I tried app.activeDocument.languages.item("English: Australian") -- whose isValid is true and is of type Language -- and our favorite DTP package jabbers about

       

      Invalid value for set property 'appliedLanguage'. Expected String, Language, LanguageWithVendors or NothingEnum enumerator, but received Language.

       

      It does work if I select any 'valid' language to look for, so it seems app.languagesWithVendors is fully compatible with document.languages at that point. It fails when the document language is not a valid one.

       

      I'm pretty sure this has been discussed before but cannot find what the outcome was at the time. Anyone care to jog my memory? Was it one of those "can't be resolved" issues?

        • 1. Re: [JS] Find invalid language
          John Hawkinson Level 5

          Well, you could edit the IDML...

          • 2. Re: [JS] Find invalid language
            Marc Autret Level 4

            Hi Jongware,

             

            Sorry, I have not the answer. Really boring issue!

             

            From what I can understand, the whole problem is in the way app.findTextPreferences.appliedLanguage validates input. The error message that ExtendScript returns ("Invalid value for set property 'appliedLanguage'. Expected XXX, but received XXX") is automatically and stupidly generated at runtime, but of course it does not say the actual reason for the failure. I think the actual reason is that app.findTextPreferences.appliedLanguage attempts to match the supplied value against a app.LanguagesWithVendors item. The “invalid” language you want to supply is, in fact, valid from the document perspective—in the sense that it regularly belongs to myDoc.languages, has an id, can be applied to text, etc., even though ID does not support that language—but it is not valid from the application perspective (app.LanguagesWithVendors cannot see that item).

             

            This should not be a problem, since app.findTextPreferences usually supports properties which may be only resolved within a specific document— e.g. app.findTextPreferences.appliedCharacterStyle, etc. Unfortunately, app.findTextPreferences.appliedLanguage does not seem to implement the usual specifier resolution mechanism and sounds to expect a value that the application can see in its own language collection (app.LanguagesWithVendors). This is especially frustrating as the F&R dialog box, in InDesign, perfectly displays every document-specific language and allows the user to select it!

             

            @+

            Marc

            1 person found this helpful
            • 3. Re: [JS] Find invalid language
              [Jongware] Most Valuable Participant

              Yes, I figured so much from the difference between those 'vendors' and plain 'language'. Perhaps Adobe should have made FindTextPreferences a Document option, rather than Application.

               

              I think I'm going to try to loop over textstyleranges and see how (slow) that goes.

              • 4. Re: [JS] Find invalid language
                Marc Autret Level 4

                [Jongware] wrote:

                 

                Perhaps Adobe should have made FindTextPreferences a Document option, rather than Application.

                 

                I so agree with you. Restricting FindTextPreferences to the Application scope was a serious design mistake, since the corresponding findText(), findGrep()... methods are available at any sublevel.