6

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.

2
  • Having the same issue. Did you find a solution?
    – Nesse
    Commented Sep 21, 2018 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
    Commented Oct 24, 2018 at 14:16

2 Answers 2

4

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;
}
2
  • Would be nice if the script would parameterized ;-)
    – Alex
    Commented Jun 11, 2021 at 13:55
  • And somehow for our use case it does not give the right results for what we tried.
    – Alex
    Commented Jun 11, 2021 at 14:06
1

You could use csvkit to diff the first columns of the CSVs

In this example we compare de_DE with the theme we have to see what is not translated yet

# download existing language pack to de_DE.csv first
$ csvcut -c 1 de_DE.csv | sort > de_DE-1.csv
$ csvcut -c 1 theme-strings.csv | sort > theme-strings-1.csv
$ diff -u de_DE-1.csv theme-strings-1.csv | grep ^+ | cut -d"+" -f2 > untranslated.csv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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