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

Change language in the text after characters set

Community Beginner ,
Oct 21, 2022 Oct 21, 2022

Copy link to clipboard

Copied

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...

TOPICS
Print , Scripting , Type

Views

97

Likes

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
Valorous Hero ,
Oct 22, 2022 Oct 22, 2022

Copy link to clipboard

Copied

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:

 

Capture d’écran 2022-10-22 à 21.27.43.pngAFTER:

 

Capture d’écran 2022-10-22 à 21.27.50.png

 

Loic

Likes

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 ,
Oct 22, 2022 Oct 22, 2022

Copy link to clipboard

Copied

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

Likes

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 Beginner ,
Oct 23, 2022 Oct 23, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much Loic! I will do my test and tell you!

Likes

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