0

I'm new in Symfony 3 and I hope you can help me.

I want to use the translation component in my project, I followed this steps " https://symfony.com/doc/3.4/translation.html#configuration " but when I clear the cache with the CLI, I have this error and the translations don't work:

>php bin/console cache:clear

// Clearing the cache for the dev environment with debug true


In XliffFileLoader.php line 56:

  Unable to load "C:\wamp64\www\MyWebSite/translations\messages.en_US.xlf": [ERROR 64] XML declaration allowed only at the start of the document (in n/a - line 2, column 6)


In XmlUtils.php line 62:

  [ERROR 64] XML declaration allowed only at the start of the document (in n/a - line 2, column 6)

These are my files:

  • app/config/config.yml

    parameters:
        locale: en
    
    framework:
        #esi: ~
        translator: { fallbacks: ['%locale%'] }
    
  • translations\messages.fr_FR.xlf

    <!-- messages.fr.xlf -->
    <?xml version="1.0"?>
    <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
        <file source-language="en" datatype="plaintext" original="file.ext">
            <body>
                <trans-unit id="symfony_is_great">
                    <source>Symfony is great</source>
                    <target>J'aime Symfony</target>
                </trans-unit>
            </body>
        </file>
    </xliff>
    
  • I use the tanslation in Twig file

    {% trans %} Symfony is great { endtrans %}
    

I hope you can help me !!

1 Answers1

1

The XML parser is shouting at you because the document declaration needs to be on the first line. So switch these two lines and that error should disappear:

<!-- messages.fr.xlf -->
<?xml version="1.0"?>

The translation may not be working because you have spaces around your string in the template, and not in the xml file:

<source>Symfony is great</source>
{% trans %} Symfony is great { endtrans %}
Maerlyn
  • 33,687
  • 18
  • 94
  • 85
  • Thanks for your help... the translation now work when I began the translation file with `` as you said and I rename it `messages.fr.xlf` instead of `messages.fr_FR.xlf` – Abdelmajid Hafidi Apr 22 '18 at 12:29