• Hi all,

    According to Google: https://support.google.com/webmasters/answer/189077

    The value of the hreflang attribute identifies the language (in ISO 639-1 format) and optionally a region (in ISO 3166-1 Alpha 2 format) of an alternate URL. (The language need not be related to the region.) For example:

    de: German language content, independent of region
    en-GB: English language content, for GB users
    de-ES: German language content, for users in Spain

    Since some languages have different types, such as Chinese Traditional and Chinese Simplified, ISO 639-1 format only describes 1 language code “zh” for both Chinese languages, but we cannot fill “zh” for both Chinese Traditional & Chinese Simplified at the same time.

    From Google answer, we should use “zh-TW” / “zh-CN” or “zh-Hant” / “zh-Hans” instead (ISO 3166-1 Alpha 2), so that I fill “zh-TW” & “zh-CN” in the fields “Language Code (ISO 639-1)”.

    It works everywhere (e.g. “Settings” page, “Pages” page), except this:
    1. go to Page
    2. Edit a page
    3. Current URL is /wp-admin/post.php?post=92&action=edit
    4. Change language from English (en) to Chinese Traditional (zh-TW)
    5. Current URL is /wp-admin/post.php?post=92&action=edit&edit_lang=zh-tw
    6. Change language from Chinese Traditional (zh-TW) to English (en)
    7. Current URL is /wp-admin/post.php?post=92&action=edit&edit_lang=en-tw
    8. You can see “edit_lang” becomes “en-tw” unexpectedly, and now current page is not really English, but still Chinese Traditional

    I found the problem can be fixed by below:

    [Edit includes/admin/class-wpm-admin-gutenberg.php and change the line]
    href = url + query.replace(/edit_lang=[a-z]{2,4}/i, ‘edit_lang=’ + lang) + document.location.hash;
    [to]
    href = url + query.replace(/edit_lang=[a-z-]{2,5}/i, ‘edit_lang=’ + lang) + document.location.hash;

    Can developer confirm above is good or not, and apply it in future update?

  • The topic ‘Language Code with hyphen problem’ is closed to new replies.