@@ -433,5 +433,62 @@ The ``$messages`` variable will have the following structure::
433433 ),
434434 );
435435
436+ Adding Notes to Translation Contents
437+ ------------------------------------
438+
439+ .. versionadded: 3.4
440+ The feature to load and dump translation notes was introduced in Symfony 3.4.
441+
442+ Sometimes translators need additional context to better decide how to translate
443+ some content. This context can be provided with notes, which are a collection of
444+ comments used to store end user readable information. The only format that
445+ supports loading and dumping notes is XLIFF version 2.0.
446+
447+ If the XLIFF 2.0 document contains ``<notes> `` nodes, they are automatically
448+ loaded/dumped when using this component inside a Symfony application:
449+
450+ .. code-block :: xml
451+
452+ <?xml version =" 1.0" encoding =" utf-8" ?>
453+ <xliff xmlns =" urn:oasis:names:tc:xliff:document:2.0" version =" 2.0"
454+ srcLang =" fr-FR" trgLang =" en-US" >
455+ <file id =" messages.en_US" >
456+ <unit id =" LCa0a2j" >
457+ <notes >
458+ <note category =" state" >new</note >
459+ <note category =" approved" >true</note >
460+ <note category =" section" priority =" 1" >user login</note >
461+ </notes >
462+ <segment >
463+ <source >original-content</source >
464+ <target >translated-content</target >
465+ </segment >
466+ </unit >
467+ </file >
468+ </xliff >
469+
470+ When using the standalone Translation component, call the ``setMetadata() ``
471+ method of the catalogue and pass the notes as arrays. This is for example the
472+ code needed to generate the previous XLIFF file::
473+
474+ use Symfony\Component\Translation\MessageCatalogue;
475+ use Symfony\Component\Translation\Dumper\XliffFileDumper;
476+
477+ $catalogue = new MessageCatalogue('en_US');
478+ $catalogue->add([
479+ 'original-content' => 'translated-content',
480+ ]);
481+ $catalogue->setMetadata('original-content', ['notes' => [
482+ ['category' => 'state', 'content' => 'new'],
483+ ['category' => 'approved', 'content' => 'true'],
484+ ['category' => 'section', 'content' => 'user login', 'priority' => '1'],
485+ ]]);
486+
487+ $dumper = new XliffFileDumper();
488+ $dumper->formatCatalogue($catalogue, 'messages', [
489+ 'default_locale' => 'fr_FR',
490+ 'xliff_version' => '2.0'
491+ ]);
492+
436493.. _`L10n` : https://en.wikipedia.org/wiki/Internationalization_and_localization
437494.. _`ISO 31-11` : https://en.wikipedia.org/wiki/Interval_(mathematics)#Notations_for_intervals
0 commit comments