I am using t() with context to translate strings for a multilingual site. I would need a user to translate all language strings, but she/he does not need to know Drupal, just will feel an Excel. The problem is that I must provide the original string, the context, and the URL where it appears, and I do not know how to extract them from the database, as the string is stored as a BLOB. I am using this trick of function but still do not get the URL. Any help will be appreciated.

In the function I am copying and pasting all t() ocurrences that I have added in modules, template.php, etc.

function My_Module_list_translations(){
    $translation[] = t2('All', array(), array('context' => 'listado_sabias'));  
    $translation[] = t2('Write one or more words', array(), array('context' => 'formulario_noticias'));
    $translation[] = t2('CATALOGUE', array(), array('context' => 'menu-personalizado'));

    echo "<table border='1'>";
    foreach($traduccion as $value){
        echo '<tr><td>' . $value["contexto"] . '</td><td>' .  $value["es"]  . '</td><td>' .  $value["en"]  . '</td></tr>';
    } // foreach
    echo "</table>";
} // function

function t2($string, $empty, $context){
    $array_dev["contexto"] = $context["context"];
    $array_dev["es"] =  t($string, array(), array('context' => $context["context"] , 'langcode' => 'es'        ));
    $array_dev["en"] =  t($string, array(), array('context' => $context["context"] , 'langcode' => 'en' 
    return $array_dev;
} // function

I would recommend looking at the String Overrides Advanced module it allows your Users to search for strings to translate into other languages using a friendly table, which it looks like you're trying to make yourself.

You're providing context here but the context you provide is not really the purpose of context. Context should describe the context of the string or word to help in the translation (not simply the place on the website the string shows up -- which is largely meaningless). An example of a context is: https://api.drupal.org/comment/44448#comment-44448

which shows "Order" is a verb and not to be confused with a Noun for "drupal Commerce Order".

Note: I speak and write English and Spanish, when you write PHP code your php code should be in 1 language and not a mix of languages to be clear to developer(s) what you're code says. You shouldn't need to be bilingual to work on a piece of code. It makes your code needlessly complicated.

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.