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

How to detect document languages used more than one

New Here ,
Nov 15, 2010 Nov 15, 2010

Copy link to clipboard

Copied

Hi Guys,

Need a script/JS code which can alert if document contains language other than my selected languages.

For example.

if my selected language is "English: USA" but document also contain English:UK and French.

How can I find my languages other than my slected languages.

Thanks,

Tan

TOPICS
Scripting

Views

1.5K

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
People's Champ ,
Nov 16, 2010 Nov 16, 2010

Copy link to clipboard

Copied

I guess you have to loop through all the text frames to count for any languages used. If greater than 0, you have a different language.


If you want to revert the textFrames back to a specific language, here is a script that does that :

http://www.scriptopedia.org/index.php?q=switchlanguage

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
New Here ,
Nov 16, 2010 Nov 16, 2010

Copy link to clipboard

Copied

Thanks for your time.

Actually I am a beginner in scripting. That is why I am asking for js code.

Is anybody has script or js code? Please share with me.

Thanks a lot for all your valuable time.

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
People's Champ ,
Nov 16, 2010 Nov 16, 2010

Copy link to clipboard

Copied

var doc=app.activeDocument;

var englishUK = is_Used(doc, "Anglais : Royaume-Uni");
var englishUSA = is_Used(doc, "Anglais : Etats-Unis");
var frenchFR = is_Used(doc, "Français");

alert("English UK : "+englishUK +"\r" +
        "English USA : "+englishUSA +"\r" +
        "French : "+frenchFR);

function is_Used(doc, aLanguage /*  language as string */){
    var used = false;
    app.findGrepPreferences.appliedLanguage = aLanguage
    app.findGrepPreferences.findWhat = ".";
    if(doc.findGrep().length>0){ return true; }
    return false;
}

Where it's bold, you have to set your locale strings, mine are french.

Loic

www.loicaigon.com

www.loicaigon.com/blog

www.scriptopedia.org

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 ,
Nov 16, 2010 Nov 16, 2010

Copy link to clipboard

Copied

Here is the slow-but-sure way:

langList = [];

for (s=0; s<app.activeDocument.stories.length; s++)
{
tr = app.activeDocument.stories.textStyleRanges;
for (t=0; t<tr.length; t++)
{
  if (!inArray (langList, tr.appliedLanguage.name))
   langList.push (tr.appliedLanguage.name);
}
}

alert ("Number of languages: "+langList.length+"\r(And they are: "+langList.join(", ")+")");

function inArray (arr, item)
{
var check;
for (check=0; check<arr.length; check++)
  if (arr[check] == item)
   return true;
return false;
}

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
New Here ,
Nov 18, 2010 Nov 18, 2010

Copy link to clipboard

Copied

Hi Jong,

Thanks for your reply. Your code is working but shows all the languages used in the Document.

However, I need a code which can find languages other than my Selected Language. See my script code below. In this script I create a Drop down list where I can choose my Language and a checkbox "Find Languages other than above selected Language". I need a code which show me the Languages other than my selected Languages. I mean I want only one Language in my Document if there are more languages applied in my document than my script show me all the languages other than my selected languages.

Also could you please check my two check boxes 1) Find double Spaces and 2) Find Unused Paragraph Styles is not running in this script. When I run this script on ESTK it gives error "Cannot handle the request because a modal dialog or alert is active."

But it is working fine If I run these codes as a single. Please check.

Thanks in advance for your effort on this.

Tan

See my script code below. Its messy but working.

var myDialog = new Window('dialog',"MyTool");

buildWindow();

myDialog.show();

function buildWindow(){

myDialog.alignChildren = "left";

// Properties for myReportFolder

myDialog.preferredSize.width=300

var myReportFolder=myDialog.add('panel',undefined,"Choose folder to save report:", {borderStyle:'raised'});

myReportFolder.orientation="row"

// Properties for mySelectedFolder

// var mySelectedFolder = myReportFolder.add('group',undefined);

// Properties for mySelectedPath

var mySelectedPath = myReportFolder.add('edittext',undefined,"~/Report path");

mySelectedPath.preferredSize.width = 275;

// Properties for myBrowseFolder

var myBrowseFolder = myReportFolder.add('button',undefined,"Choose");

myBrowseFolder.onClick = function ()

{

var myfilePath=Folder.selectDialog ("Choose a Report Folder");

if(myfilePath != null)mySelectedPath.text=myfilePath.fsName;

}

var myPanel1 = myDialog.add('statictext',undefined,"Select Document Language:");

var theLanguages = app.languagesWithVendors.everyItem().name;

// Properties for myPanel1.dropDownList

var dropDownList = myDialog.add('dropdownlist',undefined,undefined,{items:theLanguages});

dropDownList.selection = 1;

// Properties for myChoice

var myChoice = myDialog.add('panel',undefined,"Select your option", {borderStyle:'raised'});

myChoice.alignChildren = "left";

// Properties for searchDoubleSpace

// Properties for searchWrongLanguage

var searchWrongLanguage = myChoice.add('checkbox',undefined,"Find Languages other than above selected Language");

searchWrongLanguage.value = false;

var searchDoubleSpace = myChoice.add('checkbox',undefined,"Find Double Spaces");

searchDoubleSpace.value = false;

var unusedParaStyle = myChoice.add('checkbox',undefined,"Find Unused Paragraph Styles");

unusedParaStyle.value = false;

var myBleed = myChoice.add('checkbox',undefined,"Check Bleed Value");

myBleed.value = false;

// Properties for myDialog.myPanel3

var myPanel4= myDialog.add('panel',undefined,undefined, {borderStyle:'raised'});

// Properties for myPanel4.closeButton

myPanel4.orientation="row"

myPanel4.closeButton = myPanel4.add('button',undefined,"Close",{name:'cancel'});//tan:add name cancel

// Properties for myPanel4.goButton

myPanel4.goButton = myPanel4.add('button',undefined,"RUN",{name:'ok'});//tan: add name ok

myPanel4.goButton.onClick = function (){

//Bleed

var myDocName=app.activeDocument.name;

var myFilePath1=mySelectedPath.text + "/" + myDocName + ".txt";

var myTextFile = new File(myFilePath1);

if ( myTextFile.exists )

{

myTextFile.remove(myTextFile);

}

flag=false;

if (myBleed.value == true){//running succesfully

myDoc=app.activeDocument.documentPreferences

if ((myDoc.documentBleedTopOffset)!=9){

write("Document TOP Bleed is not correct "+myDoc.documentBleedTopOffset);

}

if ((myDoc.documentBleedBottomOffset)!=9){

write("Document BOTTOM Bleed is not correct "+myDoc.documentBleedBottomOffset);

}

if ((myDoc.documentBleedInsideOrLeftOffset)!=9){

write("Document INSIDE/LEFT Bleed is not correct "+myDoc.documentBleedInsideOrLeftOffset);

}

if ((myDoc.documentBleedOutsideOrRightOffset)!=9){

write("Document OUTSIDE/RIGHT Bleed is not correct "+myDoc.documentBleedOutsideOrRightOffset);

}

}//close if

//Unused Paragraph style

if (unusedParaStyle.value == true){

var myDoc = app.activeDocument;

var myParStyles = myDoc.paragraphStyles;

for (j = myParStyles.length-1; j >= 2; j-- ) {

removeUnusedParaStyle(myParStyles);

}

function removeUnusedParaStyle(myPaStyle) {

app.findTextPreferences = NothingEnum.nothing;

app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.appliedParagraphStyle = myPaStyle;

var myFoundStyles = myDoc.findText();

if (myFoundStyles == 0) {

write(myPaStyle.name);

}

app.findTextPreferences = NothingEnum.nothing;

app.changeTextPreferences = NothingEnum.nothing;

}

}//close if

//Search for Double Spaces

if (searchDoubleSpace.value == true){

app.findGrepPreferences = NothingEnum.nothing;

app.changeGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.findWhat = " ";

var result = Number(app.activeDocument.findGrep().length);

if (result>=1){

write("Double space found in this document " + result);

}

}//close if

//Search for Wrong Language

if (searchWrongLanguage.value == true){

//working

langList = [];

for (s=0; s<app.activeDocument.stories.length; s++)

{

tr = app.activeDocument.stories.textStyleRanges;

for (t=0; t<tr.length; t++)

{

if (!inArray (langList, tr.appliedLanguage.name))

langList.push (tr.appliedLanguage.name);

}

}

write ("Number of languages: "+langList.length+"\r(And they are: "+langList.join(", ")+")");

function inArray (arr, items)

{

var check;

for (check=0; check<arr.length; check++)

if (arr[check] == items)

return true;

return false;

}

}//close if

else (searchWrongLanguage.value == false){

}//close else if

}//close onClick function

}//end buildWindow

//*****Browse Report Folder and Writing file

function write(text){

var myDocument=app.activeDocument;

var myFilePath1=myDocument.filePath + "/" + "myDocument_Report" + ".txt";

var myTextFile = new File(myFilePath1);

if ( myTextFile.exists )

{

myTextFile.open("e");

myTextFile.seek(0, 2);

}

else {

myTextFile.open("w");

}

myTextFile.write(text+"\r");

myTextFile.close()

myTextFile.execute()

}

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
New Here ,
Nov 23, 2010 Nov 23, 2010

Copy link to clipboard

Copied

Waiting for positive reply from you guys.

Please help me on this.

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
People's Champ ,
Nov 23, 2010 Nov 23, 2010

Copy link to clipboard

Copied

It looks like people are really trying to help you, no need to push

Keep in mind it's not an open bar here 

Loic

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
LEGEND ,
Nov 23, 2010 Nov 23, 2010

Copy link to clipboard

Copied

LATEST

You posted this question in this thread as well as two new threads. Your question was answered three times. What more do you want?

(And PLEASE do not repeat yourself...)

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