Skip to main content
bastieneichenberger
Inspiring
August 22, 2013
Question

link item space return string in language

  • August 22, 2013
  • 2 replies
  • 1179 views

Hi all,

I'm trying to write a function who return true if the link image in indesign is in bitmap (black and white) color space.

My function works but only if the indesign language is in english.

I explain, the image.space property return "black and white" in english and "noir et blanc" in french.

How I can do to use this function with other indesign versions?

#target indesign

var doc = app.activeDocument;

var array_all_links = doc.links;

for(var i = 0; i<array_all_links.length; i++){

    is_image_bitmap (array_all_links );

}

function is_image_bitmap(link_item){

    var image = link_item.parent;

    if (image.constructor.name == "Image") {

        if(image.space == "Black and White"){ // this line doesn't work in french because the return value is noir et blanc…

            alert("ok");

        }

    }

}

This topic has been closed for replies.

2 replies

Peter Kahrel
Community Expert
Community Expert
August 23, 2013

Try using the language-neutral formulation of the string. Something like this:

if(image.space == "$ID/Black and White")

Peter

bastieneichenberger
Inspiring
August 23, 2013

Hi,

Thanks you for your answer! It's look quite good but I read the documentation and I didn't find a solution.

I find this code who look safe but doesn't work by me:

#target indesign

// copy paste from doc

var myString = app.translateKeyString("$ID/NotesMenu.ConvertToNote");

alert(myString);

var black_and_white_str = app.translateKeyString("$ID/Black and White");

alert (black_and_white_str); // must return Noir et blanc in french etc.

bastieneichenberger
Inspiring
August 24, 2013

Hi all,

I found a solution. If it can be usefull I explain my logic in the code below:

#target indesign

var doc = app.activeDocument;

var array_all_links = doc.links;

for(var i = 0; i<array_all_links.length; i++){

    alert(is_image_bitmap (array_all_links) );

}

// this function return true if an link content Black and White image

function is_image_bitmap(link_item){

    var is_bitmap = false;

    var image = link_item.parent;

    // this function work with every language, if you make your test with "Black and White" it doesn't work with other language

    var black_and_white_key = app.translateKeyString("$ID/#Links_Black and White");

    if (image.constructor.name == "Image") {

        if(image.space == black_and_white_key){

            is_bitmap = true;

        }

    }

    return is_bitmap

}

// to find the right Key string of an item

// app.findKeyStrings(name);

Jump_Over
Legend
August 23, 2013

Hi,

exam image.space.length, say > 10, maybe...

Jarek

bastieneichenberger
Inspiring
August 23, 2013

Hi,

Thanks your for your reply… Why not! But I would like to find a safer way to do this

function is_image_bitmap(link_item){

    var is_bitmap = false;

    var image = link_item.parent;

    if (image.constructor.name == "Image") {

        if(image.space == "Noir et blanc" || image.space.length > 10){

            is_bitmap = true;

        }

    }

    return is_bitmap

}

Jump_Over
Legend
August 23, 2013

Hi,

What about imageTypeName localized names? Are they differ so much as well?

app.selection[0].images[0].imageTypeName.slice(0,6) == "Bitmap";

Jarek