Hello,
I’m having a very similar issue. I’ve tried with both mo/po files as well as this string translation.
Could it be a priority problem? What is the priority between these locations?
- /wp-content/languages/
- /wp-content/languages/plugins/
- /wp-content/languages/themes/
- /wp-content/themes/x-child/languages/
Btw, is there any drawback using the string translation, is it slower or something?
I used this code, what’s the difference in functionality?
add_filter( 'gettext', 'x_translate_text', 20, 3 );
function x_translate_text ( $translated_text, $text, $domain ) {
$translation = array (
'Brand' => 'Varumärke',
'Add to cart' => 'Köp'
);
if( isset( $translation[$text] ) ) { return $translation[$text]; }
return $translated_text;
}
I only having issues with one term which happens to be singular/plural. To account for that I found this snippet:
add_filter( 'ngettext', 'x_translate_text_plurals', 20, 3);
function x_translate_text_plurals ( $translated_text, $single, $plural ) {
$translation = array(
'%d Item' => '%d',
'%d Items' => '%d'
);
if( isset( $translation[$single] ) ) { return $translation[$single]; }
if( isset( $translation[$plural] ) ) { return $translation[$plural]; }
return $translated_text;
}
The strange thing is that I have a dev site on the same server with almost the same setup, and it get’s correctly translated even though I remove both mo/po files and string translation. Have I forgotten some location for translations? Is it a cache problem?