3

In my site I have 2 languages, norwegian and english. I'm developing a new component using a component creator, but I'm facing a problem with the translation: The english language files are updated with new lines, while I manually update the norwegian translation.

In previous versions of Joomla it was quite easy to spot missing strings, as the translation constant would always be displayed. However, starting from joomla 3.2 ( http://docs.joomla.org/Specification_of_language_files ) english translation is always used as fallback if the correct language string is not found. So now, to manually find the missing string, I have to search the english translation file for the displayed value, and for each hit in this search, check if the translation constant exists in the norwegian language file.

Hopefully there is there a better way to locate missing translation strings, can anyone help?

3

I have a couple of fealty (linux) scripts to ease the pain of keeping language files updated:

To extract tags from a component:

#!/bin/bash

find .../TEMP/com_mycomponent -name "*.php" | xargs grep -o 'COM_MYCOMPONENT_[A-Z0-9\_]\+' | cut -d':' -f2 | sort -u > tags
find .../TEMP/com_mycomponent -name "*.xml" | xargs grep -o 'COM_MYCOMPONENT_[A-Z0-9\_]\+' | cut -d':' -f2 | sort -u >> tags

To check for duplicates, missing tags or content differences:

    // Duplicated check

$ini_file = file_get_contents("es-ES.com_mycomponent.ini");
$ini_lines = explode("\n", $ini_file);
$duplicated = array();

foreach ($ini_lines as $line)
{
    $parts = explode('=', $line);

    if (count($parts) != 2)
    {
        continue;
    }

    $k = $parts[0];
    $v = $parts[1];

    if (array_key_exists($k, $duplicated))
    {
        echo 'DUPLICATED: ' . $k . '=' . $duplicated[$k] . "\n";
        echo 'DUPLICATED: ' . $k . '=' . $v . "\n";
    }
    else
    {
        $duplicated[$k] = $v;
    }
}

// Parse without sections
$ini_array1 = parse_ini_file("en-GB.com_mycomponent.ini");
$ini_array2 = parse_ini_file("es-ES.com_mycomponent.ini");

$ini_array1k = array_keys($ini_array1);
$ini_array2k = array_keys($ini_array2);

$results = array_diff($ini_array1k, $ini_array2k);

foreach ($results as $result)
{
    echo $result . "=\"" . $ini_array1[$result] . "\"\n";
}

if (count($results) == 0)
{
    foreach ($ini_array1k as $key)
    {
        $cpo1 = substr_count($ini_array1[$key], '%');
        $cpo2 = substr_count($ini_array2[$key], '%');

        $cpe1  = substr_count($ini_array1[$key], '$');
        $cpe2  = substr_count($ini_array2[$key], '$');

        $cpbo1  = substr_count($ini_array1[$key], '{');
        $cpbo2  = substr_count($ini_array2[$key], '{');

        $cpbc1  = substr_count($ini_array1[$key], '}');
        $cpbc2  = substr_count($ini_array2[$key], '}');

        $cpme1  = substr_count($ini_array1[$key], '<');
        $cpme2  = substr_count($ini_array2[$key], '<');

        $cpma1  = substr_count($ini_array1[$key], '>');
        $cpma2  = substr_count($ini_array2[$key], '>');

        $cpqqq1  = substr_count($ini_array1[$key], 'QQQ');
        $cpqqq2  = substr_count($ini_array2[$key], 'QQQ');

        if (($cpo1 != $cpo2) || ($cpe1 != $cpe2) || ($cpbo1 != $cpbo2) || ($cpbc1 != $cpbc2) || ($cpma1 != $cpma2) || ($cpme1 != $cpme2) || ($cpqqq1 != $cpqqq2))
        {
            echo 'ERROR: ' . $key . "=\"" . $ini_array1[$key] . "\"\n";
            echo 'ERROR: ' . $key . "=\"" . $ini_array2[$key] . "\"\n\n";
        }
    }
}
  • Just out of curiosity, what are the benefits of creating a ... directory? – Farahmand Aug 15 '14 at 20:18
  • Sorrym what? these scripts only detect common inconsistencies. – Anibal Aug 16 '14 at 18:20
  • As you know, we can make a ... directory and I thought it's your development directory! So ... in your script stands for whatever directory. – Farahmand Aug 17 '14 at 7:07
  • Yes, I've just removed the local path. – Anibal Aug 17 '14 at 13:41
1

I can't think of any "joomla way" to do this. This looks mostly of how you would organize your development process.

So, since during the development, newer and newer language strings may be available, I would focus on completing the English language xml, and when done, I would copy it (duplicate) to create the relatives for the other languages and translate them on the xml.

Short of update:

For the incomplete language files and to find what is missing, instead of writing a script, you could copy - paste them in an excel, and sort them alphabetically or in any other order you can find it convenient for comparison. Then you can easily spot what CONSTANTS are missing from the other languages files.

  • Well, this is not how I'm working now. The component is already used in use in a more or less agile development process. I understand that it is possible to do it like you are saying, but it will be to cumbersome, and I'd rather write a script to make the comparison myself. – jonasfh Aug 15 '14 at 12:22
  • just extended a bit my reply – FFrewin Aug 15 '14 at 13:36
  • Yes, that's an idea, might be the easiest way. Thanks. – jonasfh Aug 15 '14 at 13:38
1

You may want to have a look at com_localise. It's an extension meant to translate Joomla core and extensions within Joomla itself. You can get it at the repo: https://github.com/joomla-projects/com_localise

It's currently reworked hard, but from my understanding it should work quite well.

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.