Falk Berger
Falk Berger

Reputation: 13

How to escape single quotes in xliff translation file

I want to quote a filename with single apostrophe in a flash message in an easyadmin3/symfony7 app. It looks like it is not possible to use an apostrophe next to a replacement placeholder.

In a controller i set a flash message like this.

$this->addFlash('success', new TranslatableMessage('import.success', [
    'filename' => 'import.csv',
]));

The xliff file contains for the translation keyword the following with some tryouts to quote the filename:

<target>File {filename}-'{filename}'-&apos;{filename}&apos;-"{filename}" imported.</target>

The flash message shown on screen:

File import.csv-{filename}-{filename}-"import.csv" imported.

As you see the {filename} placeholder inside the single quote is not replaced. What is the correct way to escape the single quote in the xliff file?

Upvotes: -1

Views: 30

Answers (2)

Falk Berger
Falk Berger

Reputation: 13

To answer my own question. The correct way to use a single quote in xliff icu- files is to use the single quote two times.

<target>File ''{filename}'' imported.</target>

And to quote the recomendation from the icu documentation:

Recommendation: Use the real apostrophe (single quote) character ’ (U+2019) for human-readable text, and use the ASCII apostrophe ' (U+0027) only in program syntax, like quoting in MessageFormat. See the annotations for U+0027 Apostrophe in The Unicode Standard.

Upvotes: 0

Khribi Wessim
Khribi Wessim

Reputation: 722

Update the <target> in your XLIFF file to escape the single quote correctly. Use the XML entity for an apostrophe (&apos;) or wrap the entire string in double quotes to avoid conflicts.

Here's how you can structure your XLIFF file:

<target>File {filename} - '{filename}' - &apos;{filename}&apos; - "{filename}" imported.</target>

The key difference between your solution and the one I suggested lies in the placement and interpretation of the placeholder {filename} within the quotes.

Hope this works for you

Upvotes: 0

Related Questions