Skip to main content
April 23, 2009
Answered

Change Language of Document

  • April 23, 2009
  • 2 replies
  • 1538 views

Hi Chaps,

Back again with another question for you all. . . .

Couple of weeks ago, I found this script by a clever dude, which changes the language of the paragraph/character styles.

I'm wondering if this can either be tweeked or a simple find and replace to allow all text boxes, stories, etc., (that do not have a paragraph/charachter style) to be assigned a language throughout the document.

// changeLanguageOfStyles_xl.js
myDoc=app.documents[0]; var theResult = myDisplayDialog(); myLanguage= theResult[0];

// Paragraph Styles
if (theResult[1] == true)
{
    myStyles=myDoc.paragraphStyles;
    for (oneStyle=1;oneStyle<myStyles.length;oneStyle++)
    {
        myStyles[oneStyle].appliedLanguage=myLanguage;
    }
}

// Character Styles
if (theResult[2] == true)
{
    myStyles=myDoc.characterStyles;
    for (oneStyle=1;oneStyle<myStyles.length;oneStyle++)
    {
        myStyles[oneStyle].appliedLanguage=myLanguage;
    }
}

function myDisplayDialog()
{
    var theLanguages = app.languagesWithVendors.everyItem().name;

    var myDialog = app.dialogs.add({name:"Change the language of the Paragraph Styles"});
    with(myDialog.dialogColumns.add()){
        with(dialogRows.add()){
            with(dialogColumns.add()){
                staticTexts.add({staticLabel:"Language:", minWidth:120});
            }
            with(dialogColumns.add()){
                var myLanguagesDropdown = dropdowns.add({stringList:theLanguages, selectedIndex:1});
            }
        }
        with(dialogRows.add())
        {
            with(dialogColumns.add())
            {
                staticTexts.add({staticLabel:"Apply to:", minWidth:120});
                with(dialogColumns.add())
                {
                    var myParacheckbox = checkboxControls.add({staticLabel:"Paragraph Styles", checkedState:true});
                    var myCharcheckbox = checkboxControls.add({staticLabel:"Character Styles", checkedState:false});
                }
            }
        }

    }
    var theResult = myDialog.show();
    if(theResult == true){
        var theLan = theLanguages[myLanguagesDropdown.selectedIndex]
        var theParaSt = myParacheckbox.checkedState;
        var theCharSt = myCharcheckbox.checkedState;
        myDialog.destroy();
    }
    else{
        myDialog.destroy();
        exit();
    }
    return [theLan, theParaSt, theCharSt];
}

Any ideas?

Cheers,

Mookie

This topic has been closed for replies.
Correct answer Jongware

This simple one-liner oughta do the trick.

app.activeDocument.stories.everyItem().paragraphs.everyItem().appliedLanguage = "French";

No fancy dialogs...

2 replies

Participant
May 20, 2018

Thank you but a few more questions if you don't mine

1.where do I have to write this code?

2. I need to work the  documents in 3 languages, translations, movie scripts, and so...  My question is, Do I need to change the language every time? or there is a way to just open all the documents in their languages and correct their orthographe from there?

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
April 23, 2009

This simple one-liner oughta do the trick.

app.activeDocument.stories.everyItem().paragraphs.everyItem().appliedLanguage = "French";

No fancy dialogs...

April 24, 2009

Sweeeeeet!