Frage

I have the following array in php

$arr = array ('five minutes', 'ten minutes', '15 minutes');

Also, at one point in my code, I am doing the following:

_e($arr[1]); // This is a WordPress function to display the translated output.

Now, how do I make sure that Poedit picks up the array entries for translation and eventually echo the translated output.

War es hilfreich?

Lösung

Build the array like this:

$arr = array (
    __( 'five minutes', 'your-text-domain' ),
    __( 'ten minutes', 'your-text-domain' ),
    __( '15 minutes', 'your-text-domain' )
);

Then simply echo $arr[1];.

Andere Tipps

If there is no translation, or the domain isn't loaded the original text is returned. So you can check this way:

if(__($text) != $text){
    // text can be translated
}
else{
    // text cannot translate
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top