Balu Khengat
Balu Khengat

Reputation: 91

Symfony translation using csv file

I want to make translations in symfony using CsvFileLoader. I have written following code

    $file = __DIR__.'/file.csv';
    $translator = new Translator('fr', new MessageSelector());
    $translator->addLoader('csv', new CsvFileLoader());
    $translator->addResource('csv', $file, 'fr');
    $translator->setFallbackLocales(array('en'));
    $translator->trans('Hello'));

But I am not able to get the translation for given input.

Upvotes: 1

Views: 810

Answers (1)

Matteo
Matteo

Reputation: 39390

I successfully run you code with the following csv file content:

"Hello";"Bonjour"

Take care of the default configuration of the CsvFileLoader class.

If you want to override you need to call the method setCsvControl passing various argument. From the API doc:

setCsvControl(string $delimiter = ';', string $enclosure = '"', string $escape = '\\')

Sets the delimiter, enclosure, and escape character for CSV.

Hope this help

Upvotes: 1

Related Questions