They’re not supposed to, that’s not how they work. Those functions use the language defined in WordPress’ settings and get their translations from a translation file in the theme or plugin. See the Localization page of the Theme Developer Handbook for more.
If you’re using a static HTML attribute then you probably shouldn’t be using the translation functions at all, as the use of the attribute with a hard-coded value implies that the language won’t/can’t change.
I know how to use i18n in WordPress. The problem is not the file, but the fact that in a site of a specific language, I have pages in other languages. So, in those pages, the same plug-in should use another language file. The problem is that I do not know how to FORCE the language in a specific page.
-
This reply was modified 8 years, 2 months ago by
dejudicibus.
SOLVED! I added this function to functions.php
if( ! function_exists('load_specific_textdomain') ){
function load_specific_textdomain( $textdomain = 'default', $locale = null ) {
if ( null === $locale ) {
$locale = is_admin() ? get_user_locale() : get_locale();
}
// Unload previously loaded strings so we can switch translations.
unload_textdomain( $textdomain );
$return = load_textdomain( $textdomain, WP_LANG_DIR . "/$locale.mo" );
if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) {
load_textdomain( $textdomain, WP_LANG_DIR . "/ms-$locale.mo" );
return $return;
}
if ( is_admin() || wp_installing() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) {
load_textdomain( $textdomain, WP_LANG_DIR . "/admin-$locale.mo" );
}
if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) )
load_textdomain( $textdomain, WP_LANG_DIR . "/admin-network-$locale.mo" );
return $return;
}
}
then I used the following block of code:
// $lang is the language you wish to temporarily load
// $domain is the text domain
// if $lang is null, use the current locale
if ($lang != null) {
$clang = is_admin() ? get_user_locale() : get_locale();
load_specific_textdomain($domain, $lang);
}
// Place here the code containing __($string_to_be_translated, $domain)
if ($lang != null) {
load_specific_textdomain($domain, $clang);
}