[JS] Variable text constructor
Copy link to clipboard
Copied
Hello,
I can not do it on replacing these two variables, the result is not good and there, I'm stuck.
Thanks for your help
Bonjour,
je ne parviens pas à faire le remplacement sur ces deux variables, le résulta n'est pas bon et là, je suis bloqué.
Merci pour votre aide
var paragraph0 ="Chépitre 01.indd";
var paragraph = app.activeDocument.name; //name file indesign is Chépitre 01.indd.
alert(paragraph0.replace (/é/g, 'e') +'—' + paragraph.replace (/é/g, 'e'));
result : "Chepitre 01.indd — Chépitre 01.indd" -> not good

Copy link to clipboard
Copied
I've tested the code you've posted and it works as you expect. Result is: Chepitre 01.indd—Chepitre 01.indd
Maybe you'll need to add more details so we can reproduce your problem.
Copy link to clipboard
Copied
I agree with Luca Bisin. I saved a document as "Chépitre 01.indd" and ran your script. This was the result:
What version of InDesign do you have? This was CC 2015.2 (latest CC version).
Perhaps there might be another ASCII / UTF8 representation of the letter "é" in the filename, than the letter é that we are testing with.
Andreas
Copy link to clipboard
Copied
I second that.
Copy link to clipboard
Copied
I work on mac (10.7.5) with InDesign CS6 (8.1), I just tested it on another machine, I have no problem (!!! ?????).
Is it possible to reach saturation or other problem?
I return on another machine tomorrow.
thank you to all of you
Je travail sur mac (10.7.5) avec indesign CS6 (8.1), je viens de tester sur une autre machine, je n'ai plus le problème (!!!?????).
Est-il possible d'arriver à saturation ou autre problème ?
Je retour sur l'autre machine demain.
Merci à vous tous
Copy link to clipboard
Copied
Where do your document come from. Was it created and saved at your office ?
It looks like it was created on some other machine using a different encoding. Guessing that Chépitre would stand orginally for Châpitre. So the possible â to é translation would betray a change of encoding leading to characters mismatch.
One thing to try would be to do a idml loop to see if once reconstructed you would still face the issue.
FWIW
loic
Copy link to clipboard
Copied
Hi Liphou,
I can see the same as you with InDesign CS6 v8.1.0 on Mac OSX 10.7.5.
I copied the contents of your first string to the "Save As" editing field of an unsaved InDesign document and saved the file with this name.
Then I ran the following code on the open document:
var string1 = "Chépitre.indd";
var string2 = app.documents[0].name;
$.writeln(string1.length); // 13
$.writeln(string2.length); // 14
I think, that's the proof that é in string2 is composed of two components: e + ´
So let's check this a bit in more depth:
var string1 = "Chépitre.indd";
var string2 = app.documents[0].name;
$.writeln("string1.length" +"\t"+ string1.length);
// string1.length 13
$.writeln("string2.length" +"\t"+ string2.length); //EDITED
// string2.length 14 //EDITED
$.writeln("string1:");
for(var n=2;n<4;n++){
$.writeln(string1.slice(n,n+1) +"\t"+ string1.charCodeAt(n));
};
/*
string1:
é 233
p 112
*/
$.writeln("string2:");
for(var n=2;n<4;n++){
$.writeln(string2.slice(n,n+1) +"\t"+string2.charCodeAt(n));
};
/*
string2:
e 101
́ 769
*/
That's it…
Uwe
Copy link to clipboard
Copied
Btw. I'm on a German OSX with a German version of InDesign CS6.
Uwe
Copy link to clipboard
Copied
Tested a bit more. On my German Mac OSX 10.7.5.
var string = "Chépitre.indd";
1. If I copy/paste the string over to the ESTK and then on to the Save As dialog to save an InDesign document, I get this: e + ´
2. If I rename an InDesign document in the Finder to the contents of the string using the keyboard any typing an ´ followed by an e, I also get this as app.documents[0].name : e + ´
3. If I copy/paste the string from the ESTK directly to the file name in the Finder to rename the InDesign document, I get: é with app.documents[0].name
4. If I copy/paste the string to an TextEdit file set to "Pure Text" with Encoding UTF8 and then copy/paste to the InDesign file in the Finder, I will get : é with app.documents[0].name
Uwe
Copy link to clipboard
Copied
Laubender thank you for your answer,
I used your code and I had no difference
so I copied the contents of my first string and "save as" the documents, I crashed the other file, I raise the code and I have the problem again.
Ok, two things but why ???
The file is located on a "Google Drive" ... the problem may be due to the transfer.
I had a problem at work but at home ... to meditate
Thank you.
Merci Laubender pour ta réponse,
j'ai utilisé ton code et je n'avais plus de différence,
j'ai donc copié le contenu de ma première chaîne et « enregistrer sous » le documents, j'ai ecrasé l'autre fichier, je relance le code et j'ai de nouveau le problème.
Ok, deux éléments mais pourquoi ???
Le fichier se trouve sur un "google Drive" ... le problème est peut être du au transfert.
J'avais le problème au travail mais plus chez moi ... à méditer
merci
Copy link to clipboard
Copied
Hi Liphou,
in this regard see the following post by Martin Fischer at www.hilfdirselbst.ch in German.
He is using a table of replacements for Umlauts, because he had the same problems.
See his String.prototype.cleanUmlaut function.
Textdatei Importoption Zeichensatz Unicode - Adobe InDesign - HilfDirSelbst.ch - Forum
In this post (back in 2008) he stated that he had no problems with combinations of áàéèóòúù, but years later he or someone else (including me) stumbled upon these and expanded his function. I recall a function that is placing images according to a list of file names that had the problems you encounter now.
See also from the same website from 2012:
Encodingdifferenzen zwischen Filesystem und javascript prompt
(differences of encoding between fle system and the javascript prompt)
Johannes Puff
And also this one on hilfdirselbst from 2006:
http://www.hilfdirselbst.ch/foren/_P267653.html?search_string=Diaresis#267653
Uwe
Copy link to clipboard
Copied
Good evening and thank you Laubender for all these documentations.
To summarize,
so I copied the contents of my first string and "save as" the documents, I crashed the other file, I raise the code and I have the problem again.
I close the document, I open it again and resumes code ... no problem ...
thank you to all of you
// ----------------------
Bonsoir et merci Laubender, pour toutes ces documentations.
Pour résumer,
j'ai donc copié le contenu de ma première chaîne et « enregistrer sous » le documents, j'ai ecrasé l'autre fichier, je relance le code et j'ai de nouveau le problème.
je ferme ce document, je l'ouvre à nouveau et relance le code ... plus de problème ...
Merci à vous tous

