This thread is resolved. Here is a description of the problem and solution.

Problem: Client want the site to optimize for English Speakers (browser language), Google in English, no matter if they are in US, UK, AU, etc. The same for Dutch. No matter if they are in Netherlands, or elsewhere.

Solution: WPML downloads automatically .mo WordPress translations files any time you add a new language. For this, it needs to match the Language tags with the ones provided by WordPress.

When you download the dutch wordpress, inside wp-content/languages you will find the default admin language files. You can copy them to your own wordpress and rename them to skip the regional code and then change the language tag in WPML > Languages or change the output of the hreflang tags with code.

Relevant Documentation:

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 11 replies, has 4 voices.

Last updated by Cristina 2 years, 6 months ago.

Assigned support staff: Cristina.

Author Posts
October 20, 2017 at 10:54 am #1406960

Sergio

Hello,

I want the site to optimize for English Speakers (browser language), Google in English, no matter if they are in US, UK, AU, etc.
The same for Dutch. No matter if they are in Netherlands, or elsewhere.

For this reason in wp-admin/?page=sitepress-multilingual-cms%2Fmenu%2Flanguages.php&trop=1 I replaced:
en_US to en, and en-us to en
and nl_NL to nl, and nl-nl to nl

See screenshot locale1.

But now I am receiving an error. See screenshot locale2.

What does it mean this error? How to solve it?
I have similar settings in other blogs, and I don't receive such error. Is it theme specific?

October 20, 2017 at 5:50 pm #1407413

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Hello there,

Welcome to WPML support forum.

Since WPML 3.6, it downloads automatically .mo WordPress translations files any time you add a new language. For this, it needs to match the Language tags with the ones provided by WordPress. If you use some custom tags, WPML is not able to do it for you, so, you need to go directly to WordPress repository and download them.
https://make.wordpress.org/polyglots/teams/

Does it solve your question?

Best regards,
Andrés

October 23, 2017 at 12:35 pm #1408647

Cristina

Hallo Sergio,

I have taken over this ticket and read your problem.

Additionally to my colleagues' reply I would like to inform you in this content about another issue:

In case you use WPML to output hreflang tags (set in WPML > Languages), the hreflang tags use what is contained in the field of the language tag.

But if the default locale includes a country code that is different from the language tag (as it is when you use just de without de_DE), the hreflang appends a region code to the language tag.

So if you use the WPML output, you would get the problem in the sourcecode of your pages.

There are two options now:

- You can use the language files and language tag as you like and just ignore the warning in WPML. This is just a warning that WPML is not being able to download the .mo files from the WordPress repository, as Andrés explained. If it was an error that could make a problem it would be marked in red.

In that case, to avoid getting an problems with the hreflang-tags issued by WPML, I would suggest to not use the hreflang tags from us and use the options of a seo plugin for that.

- The other option goes in this direction:

If you just want to change the german hreflang tag, please use this code in your functions.php file for your theme or child theme. This will replace the regional code we add to the hreflang tags with just the language tag. You may have to change the code for two languages, as this is made for one case.

function custom_lang_code($hreflang_items){
    $code_to_remove = 'en-US';
    $code_to_add = 'en';
       
    if (array_key_exists($code_to_remove, $hreflang_items)) {
        $hreflang_items[$code_to_add] = $hreflang_items[$code_to_remove];
        unset($hreflang_items[$code_to_remove]);
    }
 
    return $hreflang_items;
    }
add_filter('wpml_hreflangs', 'custom_lang_code', 10, 1);

I would recommend you to use the first solution.

Kind regards,
Cristina

October 23, 2017 at 12:47 pm #1408671

Sergio

Hello, thank you. So the first solution would be to just use nl without nl-NL and nl_NL.
And just ignore/dismiss this warning?

October 23, 2017 at 1:55 pm #1408785

Cristina

Hi Sergio,

the first solution is to use "nl" if you like, upload the language file and don't use the WPML hreflang tags but put your own ones.

If you use nl without nl-NL, the warning will still be there, but you can upload the dutch wordpress file for the admin text manually and ignore the warning. WPML will use the existing matching file for the wordpress backend then instead of downloading it from WordPress.

If you also want to optimize the site to not show hreflang tags like nl_NL but to show them like nl in the source code of the pages, you should not use the WPML tags for this, because this will convert nl to nl-NL unless you modify the code with the snippet.

Kind regards,
Cristina

October 23, 2017 at 2:04 pm #1408800

Sergio

Hmmm, I still can't understand.
upload the language file: what language file to upload? In that list I was given by Andres, there is no "nl".

Second question: "If you also want to optimize the site to not show hreflang tags like nl_NL but to show them like nl in the source code of the pages, you should not use the WPML tags for this, because this will convert nl to nl-NL unless you modify the code with the snippet."
What conversion? In wp-admin/?page=sitepress-multilingual-cms%2Fmenu%2Flanguages.php&trop=1 I see:

-code=nl
-default locale = nl
-language tag=nl

And in the source code of the homepage I see:

<link rel="alternate" hreflang="nl" href="<em><u>hidden link</u></em>" />
<link rel="alternate" hreflang="en" href="<em><u>hidden link</u></em>" />

And in the header of the Dutch site I see:

<!DOCTYPE html>
<html lang="nl" prefix="og: <em><u>hidden link</u></em>" class="">

So everything looks like to be good... I don't see any conversion....

October 23, 2017 at 2:44 pm #1408890

Cristina

Hello Sergio,

sorry for the confusion.

I am happy this works fine. The tags seem to be updated and I did not see this.

The files Andrés mentioned are the official translations that can be downloaded going to the corresponding locale, hidden link

When you download the dutch wordpress, inside wp-content/languages you will find the default admin language files. You can copy them to your own wordpress and rename them to nl.

Kind regards,

Cristina

October 23, 2017 at 2:55 pm #1408911

Sergio

Ok thanks. But if I want to keep the wp-admin in English, then I have to make no changes, right?

October 23, 2017 at 3:09 pm #1408923

Cristina

Hello Sergio,

right.
Anyway, the wp-admin when using WPML is set in your user profile. So if you set in your profile the admin language to english, you have the english backend.

Kind regards,
Cristina

October 23, 2017 at 3:17 pm #1408930

Sergio

Excellent, thank you

November 20, 2017 at 1:45 pm #1435866

robinS-3

@CristinaVidal

the custom code "custom_lang_code" works fine. I create a foreach to cleanup multiple languages like this:

add_filter('wpml_hreflangs', 'custom_lang_code', 10, 1);
function custom_lang_code($hreflang_items){
    
    $my_array = array(
        'en_US' => 'en', // default language => x-default
        'de_DE' => 'fr',
        'fr_FR' => 'fr'
    );

    foreach ($my_array as $k => $v) {
        if (array_key_exists($k, $hreflang_items)) {
            $hreflang_items[$v] = $hreflang_items[$k];
            unset($hreflang_items[$k]);
        }
        return $hreflang_items;
    }

}

But how can I also change lang tag of the HTML tag?

<html class="" <strong>lang="de-DE"</strong> prefix="og: <em><u>hidden link</u></em> fb: <em><u>hidden link</u></em> og: <em><u>hidden link</u></em>">

Regards
Marc

November 20, 2017 at 4:59 pm #1436154

Cristina

Hello Marc,

thanks for replying on this thread, but this issue is already close. Regarding your reference, please have a look at this thread that may contain a solution for your issue.
https://wpml.org/de/forums/topic/im-seitenheader-umbenennen/#post-1395864

In case that does not help, please open a separate thread, otherwise I can't handle your problem correctly.

Kind regards,
Cristina