Copy link to clipboard
Copied
So..
All the documents i'm working on must be set on a specific language
(eg. "German (2006 reform)"). However, sometimes during text import, mistakes happen and texts "jump" on a different language (i had english, romanian, swiss etc).
i have to build a tool (a fast one), that will find any text that has a different than "German" language applied on it, and reports on what page it appears.
Other than iterating each paragraph, each tabel and each footnote i have no idea. And since the documents usualy have 1000+ full of text, it will take quite a while.. can anyone give me a different idea?
Thanks a lot!
~ Trevor ~ wrote:
But I found the REAL bug "
for (c=0;c<langs.length;c++){"
should become"
for (c=0;c<langs.length-1;c++){"
Quite a silly mistake
The script works really quite nicely now
Now I feel really silly, the "real" bug was not a bug and
for (c=0;c<langs.length;c++){"
was correct.The -1 took off English: United States (don't know what's the difference between that and English: USA, as a Brit I never looked into it.)
the -1 did make a difference, my computer was feel
...Copy link to clipboard
Copied
A potentially destructive way, so make sure you don't accidentally save:
1. Create a new color swatch and call it 'Gut Text'.
2. Find the text with your German (2006) language applied and replace with your new swatch.
3. Search for remaining text in black.
Pro: well it's fast and should be 100% accurate.
Con: It's 'destructive' because it changes the text color. Of course you can throw away the "Gut Text" swatch and replace it with Black, but if you used any other text colors than black, it will remove these as well. Also, text in a color other than black will *not* be checked.
(You don't have to use a color swatch, you can use a couple of other text attributes. You cannot use *any* text attribute to weed out bad text -- for instance, suppose you decide to change your 'good' text to a baseline shift of 0.001pt. But then you'd have to search for "Baseline shift not 0.001pt", and InDesign cannot do that -- you'd have to search for a baseline of 0pt, and hope no-one did funny things with it.
The very best would be if you can find a pure binary text attribute -- one that is either ON or OFF -- of which you are totally sure no-one used it anywhere.)
Copy link to clipboard
Copied
[Jongware] wrote:
The very best would be if you can find a pure binary text attribute -- one that is either ON or OFF -- of which you are totally sure no-one used it anywhere.)
Got one: Character color, Overprint fill.
.. At least, for me that one would work O_o as I've never ever used this particular function myself.
Copy link to clipboard
Copied
Conditions are useful for this, and they leave colour alone. Plus you could leave the applied conditions in place because you see them only in preview mode.
Peter
Copy link to clipboard
Copied
Hah -- another rare function I live to see put to good use 😄
Copy link to clipboard
Copied
@Vamitul – if you know that all your text should be in a specific language, why don't you apply that language to all stories in the document?
Why do you have to report the instances of a not properly set language?
The following example is not perfect (it will not get tables nested in tables), but otherwise would apply a specific language to all stories, tables (not nested! in tables) and footnotes of a given document. Do not use the string I present here for "German (2006 reform)", because its dependent of my German InDesign:
var myLanguage = /***For German InDesign, only:***/"Deutsch: Rechtschreibreform 2006"; //Perhaps use: "German (2006 reform)"
//All Stories:
app.documents[0].stories.everyItem().appliedLanguage = myLanguage;
//All Tables:
app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().texts[0].appliedLanguage = myLanguage;
//All Footnotes
app.documents[0].stories.everyItem().footnotes.everyItem().texts[0].appliedLanguage = myLanguage;
//All Tables in Footnotes:
app.documents[0].stories.everyItem().footnotes.everyItem().texts[0].tables.everyItem().cells.everyItem().texts[0].appliedLanguage = myLanguage;
//CAUTION !! Not supported here:
//1. Tables nested in tables
Uwe
Copy link to clipboard
Copied
@Laubender: I can't change the documents (I'm doing "loseblattwerk") and some of the pages have already been set ant printed with the errors. I only have to report them.
@ [Jongware], Peter Kahrel: Thank you for the interesting ideas. will have a look, the problem is the attribute
"of which you are totally sure no-one used it anywhere."
These documents have been through many many hands including some people that shouldn't be allowed to even touch a computer (i got in one doc 112 pages of text indented, aligned etc using the spacebar key).
Copy link to clipboard
Copied
Try this.
Make a copy of your document and on the COPY run this script.
myDoc=app.documents[0];
var myLanguage = /***For German InDesign, only:***/"Deutsch: Rechtschreibreform 2006"; //Perhaps use: "German (2006 reform)" // this line stolen from Uwe
uc = (app.activeDocument.conditions.item("My Unique Condition That I'm Pretty Sure Does Not Come Up In The Document (23145871834gs to be extra safe)").isValid)
? app.activeDocument.conditions.item("My Unique Condition That I'm Pretty Sure Does Not Come Up In The Document (23145871834gs to be extra safe)")
: app.activeDocument.conditions.add
({name: "My Unique Condition That I'm Pretty Sure Does Not Come Up In The Document (23145871834gs to be extra safe)", indicatorColor: UIColors.YELLOW, indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT});
app.changeGrepPreferences = app.findGrepPreferences = null;
app.findGrepPreferences.appliedLanguage=
myLanguage
;app.changeGrepPreferences.appliedConditions = [uc];
finds=[];
finds=myDoc.changeGrep();
uc.visible=0;
The German text will not be visible (you can make it visible by clicking on the conditional text panel)
The text you are left with is all non-German.
You might wan't to add the the find preferences; tables, footnotes, etc.
There is a professional program Language Lamp that you might like if you do this stuff a lot.
http://www.mindsteam.com/products/languagelamp/index.html
The pro version which includes scripting and preflight is http://www.mindsteam.com/products/languagelamppro/index.html
Good luck
Trevor
Copy link to clipboard
Copied
The mindsteam version is a lot more proffesional (I have it) but this also makes your copy nice and pretty.
myDoc=app.documents[0];
langs=myDoc.languages;
con=[];
app.changeGrepPreferences = app.findGrepPreferences = null;
for (c=0;c<langs.length;c++){
app.findGrepPreferences.appliedLanguage=langs
; finds=new Array;
finds=myDoc.findGrep();
if (finds.length>0){
r=Math.floor((Math.random()*255));
g=Math.floor((Math.random()*255));
b=Math.floor((Math.random()*255));
con
= (app.activeDocument.conditions.item(langs .name).isValid) ? app.activeDocument.conditions.item(langs
.name) : app.activeDocument.conditions.add
({name: langs
.name, indicatorColor: [r,g,b], indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT}); app.changeGrepPreferences.appliedConditions = [con
]; finds=myDoc.changeGrep();
}
}
app.changeGrepPreferences = app.findGrepPreferences = null;
One can see that the : after the UK and French are Hebrew, That would be very hard to spot without this type of script
After testing on a longer document I see the script is a bit on the slow side Oh well.
I thought it might be nice to assign a constant color scheme to the language instead of a random one so if anybodies interested change the lines after if (finds.length>0){ to this
if (finds.length>0){
cc=0
for (d=0;d<langs
.name.length;d++) { cc+=langs
.name.charCodeAt(d)*235; }
r=cc % 255;
g=(5*(13*cc-7*r)) % 255;
b=(8*(9*cc-5*r-3*g) )% 255;
Message was edited by: ~ Trevor ~
Copy link to clipboard
Copied
Instead of
langs=myDoc.languages
try
langs=myDoc.languages.everyItem().getElements()
which might speed things up on long documents.
Peter
Copy link to clipboard
Copied
Hi Peter,
I'm surprised by your answer, can't see why that should make a difference.
On testing, it does seem to make a bit of a difference but it's hard to tell.
But I found the REAL bug "for (c=0;c<langs.length;c++){"
should become
for (c=0;c<langs.length-1;c++){"
Quite a silly mistake
(If one doesn't like the color of your favorite languages then experiment with the r g b formula)
Regards
Trevor
myDoc=app.documents[0];
langs=myDoc.languages.everyItem().getElements();
con=[];
for (c=0;c<langs.length-1;c++){
app.changeGrepPreferences = app.findGrepPreferences = null;
app.findGrepPreferences.appliedLanguage=langs
finds=new Array;
finds=myDoc.findGrep();
if (finds.length>0){
cc=0
for (d=0;d<langs
cc+=langs
}
r=cc % 255;
g=(5*(13*cc-7*r)) % 255;
b=(8*(9*cc-5*r-3*g) )% 255;
con
? app.activeDocument.conditions.item(langs
: app.activeDocument.conditions.add
({name: langs
app.changeGrepPreferences.appliedConditions = [con
finds=myDoc.changeGrep();
}
}
app.changeGrepPreferences = app.findGrepPreferences = null;
Copy link to clipboard
Copied
Trevor,
In your original script, every time c < langs.length
is evaluated, the collection myDoc.languages
is evaluated too. When you use langs = myDoc.languages.everyItem().getElements(), you create an array and that line is not evaluated later. So the timing difference is caused by InDesign accessing its model repeatedly (your original) or not (the everyItem() route).
Peter
Copy link to clipboard
Copied
Peter
Thanks for the explanation, very clear. Good to learn some good practices.
Trevor
Copy link to clipboard
Copied
~ Trevor ~ wrote:
But I found the REAL bug "
for (c=0;c<langs.length;c++){"
should become"
for (c=0;c<langs.length-1;c++){"
Quite a silly mistake
The script works really quite nicely now
Now I feel really silly, the "real" bug was not a bug and
for (c=0;c<langs.length;c++){"
was correct.The -1 took off English: United States (don't know what's the difference between that and English: USA, as a Brit I never looked into it.)
the -1 did make a difference, my computer was feeling moody and getting caught up with the splwow64.exe thread.
Anyway It seems to have cheered up and now come to terms with the American independence.
Copy link to clipboard
Copied
Thank you all. You guys are amazing!
I had to use the slow way of doing it, checking every page and every paragraph (tabel, footnote etc. btw. i really wish there were a easyer way of getting EVERY text in a textframe), since the script has to check for quite a few more types of errors. Next I will try to remake the entire script as a extension using Flex (i think it's about time i start learning it).
However, tervor's script will be very usefull for a few other projects.
Now, few questions for peter:
1) can you tell me a bit more about what getelements() does? Adobe's documentation is very vague about it.
2) i think i remember a "go to line" script created by you, but i can't find it. i figured that since my script already creates a report of all the problems in the document, might as well give the user the option to jump directly to the problem afterword.
Thank you again all!
ps. does anyone else have problems with the forum login?
Copy link to clipboard
Copied
@Vamitul – about "everyItem().getElements()" there are two blog posts by Marc Autret at www.indiscripts.com:
http://www.indiscripts.com/post/2010/06/on-everyitem-part-1
http://www.indiscripts.com/post/2010/07/on-everyitem-part-2
Uwe
Message was edited by: Laubender
Copy link to clipboard
Copied
> but i can't find it
That script isn't useful for your purposes (but it's here: http://www.kahrel.plus.com/indesign/goto_line.jsx just in case you want to convince yourself). All you need is a page number and/or a line number on that page. In CS5 and later, getting page numbers of found items is easy. Line numbers are messier:
myFinds = myDoc.findGrep();
for (i = 0; i < myFinds.length; i++)
{
$.write ('Found ' myFinds.contents + ' on page ' + myFinds.parentTextFrames[0].parentPage.name);
$.writeln ('at line ' + myFinds.parentTextFrames[0].insertionPoints.itemByRange(0, myFinds.index).lines.length);
}
This can be formulated more efficiently, no doubt, but you get the picture. Naturally, this makes sense only in one-frame pages such as novels -- footnotes and tables aren't catered for.
Peter
Copy link to clipboard
Copied