Skip to main content
Aratype
Known Participant
October 21, 2022
Question

Change language in the text after characters set

  • October 21, 2022
  • 1 reply
  • 275 views

In InDesign ME version, Is it possible to switch automatically to English language as soon as I introduce a latine character?

 

Actually, I am working on an Arabic text that comprise English words... I noticed that language still "Arabic" when I write an English letter or word.

 

This is an issue because LTR specifications are not all the time activated, I have to do that manually...

This topic has been closed for replies.

1 reply

Loic.Aigon
Legend
October 22, 2022

hi @Aratype 

 

Here is a proposal but without a ME version at hand, I can't warranty it's bullet-proof. However the idea is to search for latin characters with the F/C engine and apply modification to found texts : 

 

 

//main routine
//To be run in a open document
function main(){
    
    var doc = app.documents, n = doc.length, result = 0;

    //Exit if no documents open
    if(0 == n) return;

    //otherwise process doc
    doc = doc[0];

    //Calling secondarty routine
    result = applyRTL(doc).length;

    //Display result
    alert(result>0? result+" texts modified!" : "Nothing to change in the doc");
}

//Secondary routine
//Search latin characters, modify aspect
function applyRTL(kDoc){

    //---- VARS ----//
    var 
    //storing F/C GREP prefs to restore them afterwards
    fgp = app.findGrepPreferences.properties,
    cgp = app.changeGrepPreferences.properties,
    changed = [];

    //Resetting F/C GREP prefs to avoid messes
    app.findGrepPreferences = app.changeGrepPreferences = null;

    //Looking for latin characters
    //based on https://en.wikipedia.org/wiki/List_of_Unicode_characters#Basic_Latin
    app.findGrepPreferences.findWhat = "([\\x{0020}-\\x{002F}]|[\\x{0030}-\\x{0039}]|[\\x{003A}-\\x{0040}]|[\\x{0041}-\\x{005A}]|[\\x{005B}-\\x{0060}]|[\\x{0061}-\\x{007A}]|[\\x{007B}-\\x{007E}])+";

    //Setting change prefs
    app.changeGrepPreferences.characterDirection = CharacterDirectionOptions.LEFT_TO_RIGHT_DIRECTION;

    //The color settings is a temporary convenience to "spot" where text changed
    app.changeGrepPreferences.fillColor = getColor(kDoc);

    //Applying changes and get possible occurrences
    changed = kDoc.changeGrep();

    //restoring prefs
    app.findGrepPreferences.properties = fgp;
    app.changeGrepPreferences.properties = cgp;

    //returning results
    return changed;
}


//An utility function to return a dummy color
function getColor(kDoc){
    var clr = kDoc.swatches.itemByName("modified");
    if(!clr.isValid){
        clr = kDoc.colors.add({
            space:ColorSpace.CMYK,
            colorValue:[0,60,60,0],
            name:"modified"
        })
    }
    return clr;
}

//Running the script so it can be easily canceled by the user
var u;
app.doScript("main()",u,u,UndoModes.ENTIRE_SCRIPT,"Modify latin paragraphs")

 

 

HTH or at least give you a direction to start from.

BEFORE:

 

AFTER:

 

 

Loic

Peter Spier
Community Expert
Community Expert
October 22, 2022

Seems like it might make sense to add this as a GREP style to the paragraph styles.