Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by Otto 4 years, 3 months ago.

Assigned support staff: Otto.

Author Posts
June 2, 2017 at 7:44 pm #1290488

desireeM

Hi,

I have a blog that has default language german (de).
I want to get a string in English, but it always outputs in the current language (e.g. de, sv,... depending on page I am on)
When testing other language (e.g. get the string in swedish on the french site) it works perfectly fine.
also it works for my other blog that has default language english.

put this code in test.php & call it in browser on a translated domain (e.g. test.fr/test.php)
<?php

if ( !defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', true );
}

define( 'INIT', true );
define( 'ROOTPATH', $_SERVER['DOCUMENT_ROOT']);

require_once(ROOTPATH . '/wp-load.php' );
require_once(ROOTPATH . '/wp-config.php' );
require_once(ABSPATH . WPINC . '/post.php' );
require_once(ABSPATH . WPINC . '/formatting.php' );
require_once(ABSPATH . WPINC . '/query.php' );
require_once(ABSPATH . WPINC . '/taxonomy.php' );
require_once(ABSPATH . WPINC . '/meta.php' );
require_once(ABSPATH . WPINC . '/user.php' );
require_once(ABSPATH . WPINC . '/functions.php' );
require_once(ABSPATH . WPINC . '/l10n.php' );

do_action( 'wpml_switch_language', 'en' );

$countries_obj_en = new WC_Countries();
$countries_en = $countries_obj_en->__get( 'countries' );
$target_country_en = $countries_en['SE'];

echo $target_country_en;

It will work perfectly fine & echo "Sweden" even though you are on a french (test.fr) page.
Now if you set up a blog that does NOT have english as default language (but e.g. German) and you do the same, you will get Suède instead of Sweden.

same with other strings, country object is just a simple example

June 5, 2017 at 8:57 pm #1291718

Otto
Supporter

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Thank you for contacting the WPML support!

For being of better help, can you please provide your WPML Debug information in the debug field below? http://wpml.org/faq/provide-debug-information-faster-support/

To retrieve the translated string, in this case to English, I suggest to use this hook instead:
https://wpml.org/wpml-hook/wpml_translate_single_string/

Let me know if this points you in the right direction, please.

Kind Regards,

Otto

June 11, 2017 at 7:10 am #1295662

desireeM

Hi Otto,

unfortunately email notification didn't work so I didn't see your response until today.

Regarding your second method - it's not working and in hindsight it is obvious why:
strings are registered in english, but I need to get the string in english on a french site. So how would you pass the $original_value (= the string in english) if that is what you actually want to get.
I tried passing the french string, which just returned the french string, not the english original either.

I am quickly testing it with the latest woocommerce/wpml too.

June 12, 2017 at 1:49 pm #1296370

Otto
Supporter

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Thanks.

Let me know how it goes with the latest versions.

Meanwhile, you can also check this documentation:
https://wpml.org/wpml-hook/wpml_unfiltered_admin_string/
https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext

If this does not help, can you please elaborate a bit more on your needs so we can thinks of a workaround to achieve that.

Let me know your results, please.

Kind Regards,

Otto

The topic ‘[Closed] switch_lang not working to change to en when default language is not english’ is closed to new replies.