Inkscape.org
Beyond the Basics How to search and replace text in multiple lines effectively?
  1. #1
    Ooker Ooker @ooker

    Say I have an SVG file like this:

    enter image description here

    How should I edit the content of the text effectively? Clicking each of them in Inkscape is a way, but if you have many text like this it will be ineffectively. One can search and replace it in the source, but for texts that span in two or more lines, they are separated:

    <text
       xml:space="preserve"
       id="text1769"
       style="font-size:2.82222px;line-height:1.25;font-family:sans-serif;text-align:center;white-space:pre;shape-inside:url(#rect1771);display:inline"
       transform="matrix(2.5377821,0,0,2.5377821,-1.6795872,-19.146171)"><tspan
         x="2.7854152"
         y="13.211847"><tspan>A sentence spans </tspan></tspan><tspan
         x="7.1944451"
         y="16.739622"><tspan>in two lines</tspan></tspan></text>
    <text
       xml:space="preserve"
       id="text1775"
       style="font-size:2.82222px;line-height:1.25;font-family:sans-serif;text-align:center;white-space:pre;shape-inside:url(#rect1777);display:inline"
       transform="matrix(2.5377821,0,0,2.5377821,-13.399482,-7.1235831)"><tspan
         x="11.339253"
         y="19.647394"><tspan>An one liner</tspan></tspan></text>
    

    Is there a way so that texts that span across multiple lines can be easily recognized and edited as if they are just one line? My purpose is to translated this file to another language.

  2. #2
    inklinea inklinea @inklinea⛰️

    For a single image, I would say clicking and changing is the easiest way. Different languages have different size words and phrases for the same thing, and sometimes the spacing does not look correct unless done manually.

    If you had a large number of text entries to replace, then you would make a template with labeled fields before starting the project.

    So for example you could have a field called id="firstname" and then an array or JSON with alternative language options for that id. You would then use internal javascript or an external script ( possibly on a server ) to dynamically change when the language selection is changed.

    However to answer your question it can be done if the svg is loaded into an HTML file. You can then use javascript to make a collection of all text elements in the svg, then collections for sub tspans. This can be done using getElementsbyTagName or querySelector. Then dynanically make input boxes which contain the combined tspan text, then using a letter count / work break rule repopulate them over the tspans, but that would take a long time to write, and much longer than just editing by hand.

Inkscape Inkscape.org Inkscape Forum Beyond the Basics How to search and replace text in multiple lines effectively?