4

Currently we have our shop only in English language and want to add an Italian one. So we have collected all phrases with bin/magento i18n:collect-phrases --magento --output="en_EN.csv".
We installed this package to get Italian translations. Obviously the package doesn't cover all our phrases. Is there already a way or package to merge the Italian translations into the English ones? Our goal is to have one file with all phrases and the Italian translation behind it if present. If there is no Italian translation it should be only displayed the Phrase.

I already tried bin/magento i18n:pack --mode=merge -d it_IT.csv en_EN but i think i don't get right what the command does. I think it only writes the translations from the (it_IT.csv) into all translation files of en_EN in all packages.

  • Having the same issue. Did you find a solution? – Nesse Sep 21 '18 at 8:54
  • Hi @Nesse sorry for the delay maybe it's still relevant for you. We wrote a small php script in order to get a csv file with all missing translations. We got all phrases in en_EN.csv and compared it with our given it_IT.csv – Daniel Oct 24 '18 at 14:16
2

In the next step I merged en_EN.csv and it_IT.csv via PHP into two new files. One containing the translated Version with EN and IT in one File and the other containing all English phrases that got no translation from the it_IT.csv file.

<?php

ini_set('max_execution_time', 0);

$translatedArray = [];            //translations done $noTranslationFoundArray = [];      //left to translate

$enENArray = BuildArray("en_EN.csv");
$itITArray = BuildArray("it_IT.csv");

foreach ($enENArray as $enEN) {
    $found = false;
    if ($enEN==false) continue;
    foreach ($itITArray as $itIT) {
        if ($enEN[0] == $itIT[0] && $enEN[2] == $itIT[2] && $enEN[3] == $itIT[3]) {
            array_push($translatedArray, $itIT);
            $found = true;
            break;
        }
    }
    if(!$found){
        array_push($noTranslationFoundArray,$enEN);
    }
}

buildCsv($translatedArray,"translatedEnIt.csv"); 
buildCsv($noTranslationFoundArray,"noTranslationFound.csv");

function buildCsv($array, $filename){
    $oFile = fopen($filename, "w");
    foreach ($array as $element){
        fputcsv($oFile, $element);
    }
    fclose($oFile);
}

function buildArray($fileName) {
    $oFile = fopen("$fileName", "r");
    $array = [];
    while (!feof($oFile)) {
        $array[] = fgetcsv($oFile, 0, ",");
    }
    fclose($oFile);
    return $array;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.