Html language tag issue

Hello UNA Team,

While creating a language module, I came across an issue with the html language tag that should be addressed as it affects the SEO. Maybe It's the result of a wrong setting from my side, i don't know.

I have created a new language module that I named 'English (US)' and which is basically a clone of the default 'English' module. I wanted to change few words and to use the US flag in the language switcher.

The issue is that the value of the html lang tag is wrong.

Whenever I switch to another language, the value of the html lang tag changes as well to reflect the new language, which is good.

e.g: from

to

The problem is 'us' is not a valid ISO Language Code to be used in the Html lang tag because 'lang' in the html tag is used to determine the 'document language' not the 'region'. The correct value, in this case, should just be "en" no matter if it's English (GB) or English (US).

So, my question is: Where is the value of in the page header pulled from? and how to change it?

In the config.php file of my newly created language module, I have the following parameter:

  'home_uri' => 'us',

In the language module install/sql/install.sql, I have the following query:

INSERT INTO `sys_localization_languages`(`Name`, `Flag`, `Title`, `Enabled`) VALUES('us', 'us', 'English (US)', '0');

All the App xml files (translation files) are named us.xml e.g:

/data/langs/bx_artificer/us.xml

And, in the us.xml files, I have the following line:

Please help.

Thanks

  • 277
  • More
Replies (11)
    • Hello

      So, my question is: Where is the value of <html lang="en"> in the page header pulled from? and how to change it?

      I rechecked the code and as I saw this value is taken from lang Name in your language file, especially in sys_localization_languages db table. But you may try to use 'en-us' as name. It should be correctly recognized and 'en' is used as 'lang' in HTML tag.

      • Hi @Anton L

        Thanks a lot for your reply. I went into the database > sys_localization_languages table, then changed the 'Name' value from 'us' to 'en-us'. It works. 'en' is used as lang in the 'HTML' tag. Thanks a lot.

        Now I have two questions:

        Question #1: With the change above, should I also need to change every instance of 'us' to 'en-us' in my new English (US) language module when creating it? or maybe, just changing the 'Name' value in the sys_localization_languages table is enough, it's the only thing that needs to be modified.

        Example:

        In language_module/install/config.php

        Should I change:

        'name' => 'xxx_us', To: 'name' => 'xxx_en-us'

        'home_uri' => 'us', To: 'home_uri' => 'en-us',

        in language_module//install/sql/install.sql:

        Should I change:

        INSERT INTO `sys_localization_languages`(`Name`, `Flag`, `Title`, `Enabled`) VALUES('us', 'us', 'English (US)', '0');

        To:

        INSERT INTO `sys_localization_languages`(`Name`, `Flag`, `Title`, `Enabled`) VALUES('en-us', 'us', 'English (US)', '0');

        in language_module//install/sql/enable.sql

        Should I change:

        UPDATE `sys_localization_languages` SET `Enabled`='1' WHERE `Name`='us';

        To:

        UPDATE `sys_localization_languages` SET `Enabled`='1' WHERE `Name`='en-us';

        in language_module//install/sql/enable.sql

        Should I change:

        UPDATE `sys_localization_languages` SET `Enabled`='0' WHERE `Name`='us';

        To:

        UPDATE `sys_localization_languages` SET `Enabled`='0' WHERE `Name`='en-us';

        in language_module//install/sql/disable.sql

        Should I change:

        UPDATE `sys_localization_languages` SET `Enabled`='0' WHERE `Name`='us';

        To:

        UPDATE `sys_localization_languages` SET `Enabled`='0' WHERE `Name`='en-us';

        Also should I rename all my app translation files within the English (US) language module (e.g.: /data/langs/bx_artificer/us.xml) from:

        us.xml

        to

        en-us.xml

        and in those xml translation file,

        Should I change:

        To:

        "en-us" flag="us" title="English (US)">

        Do I need to make those changes? Please advise.

        Question #2: For testing purposes and as I am planing to create new language modules in the near future, I changed the value of 'Name' to 'fr-fr', 'fr-ca', 'es-es' and 'es-mx' in the `sys_localization_languages` table but nothing happened. The value of 'lang' in the HTML tag remains 'en'.

        Why can't they change to "fr' or 'es' as 'en-us' does and changes to 'en'? Any idea?

        Thanks

        • Hello

          1.1. You don't need to change module's name and uri.

          1.2. You already changed Name in sys_localization_languages table, therefore you need to do the same in install.sql file.

          1.3. - 1.5. Yes, you need to use 'en-us' everywhere if you reffer to Name field from sys_localization_languages table.

          1.6. Yes, you need to rename XML file to en-us.xml because such files should use the same value which is used in Name field from sys_localization_languages table.

          1.7. It's up to you. But I recommend you to change name attribute in resources tag for consistancy.

          2. 'table but nothing happened' where? 'The value of 'lang' in the HTML tag remains 'en'.' - where did you check this HTML tag?

          • @Anton L , You are amazing! Thanks a lot for your time and your guidance. You have no idea how helpful your answer is.

            I have just realized that I was doing things wrong and that would have affected how my site language works and also my site SEO. I will have to re-do my language module and change everything from "us" to "en-us". I am on my dev site testing things, so no problem about creating a new module.

            1.1. You said that I don't need to change module's name and uri.

            'name' => 'xxx_us',

            'home_uri' => 'us',

            Question: but as I am re-creating a new language with 'en-us', do I still need to keep them unchanged ('us')?

            home_uri is used to separate language like this: mysite.com/en, mysite.com/fr, etc right?

            2. As I said, for testing purposes, I changed the value of 'Name' to 'fr-fr', 'fr-ca', 'es-es' and 'es-mx' in the `sys_localization_languages` table of my English (US) module.

            Then, I cleaned the site cache and went to check the home page source code on my browser, but nothing happened. The value of 'lang' in the HTML tag remained 'en'. It didn't change to 'fr' or 'es'.

            My Question is: Creating new language modules for fr-fr, fr-ca, es-es and es-mx using the same rules and guidelines you provided to me, will the value of 'lang' in the HTML tag change to 'fr' or 'es' automatically?

            I am really worrying about the HTML lang tag as it's an important tag for SEO and the correct/valid way of using it, is with two-letter codes only (ISO language code).

            By the way, in /inc/classes/BxDolLanguages.php, i saw some functions 'en-us => en' etc. Are those functions the ones controlling the change from 'en-us' to 'en' in the HTML lang tag automatically? (just asking). Will it be necessary to write new functions to automatically change from 'fr-fr => fr' or fr-ca => fr' or 'es-es =>es' or es-mx =>es' or 'pt-pt =>pt' or 'pt-br => pt' etc?

            Thanks

            • Hi @Anton L . Please, any feedback to my reply above? I would need to sort out everything in my language file in order to go live. Thanks for your precious time.

              • Hello

                Question: but as I am re-creating a new language with 'en-us', do I still need to keep them unchanged ('us')?

                If you plan to recreate the lang file module then I suggest to change name and URI. You may use something like below:

                'name' => 'en_us',

                'home_uri' => 'en-us',

                home_uri is used to separate language like this: mysite.com/en, mysite.com/fr, etc right?

                In case of "Lang File" module type the home_uri isn't used (for now).

                Then, I cleaned the site cache and went to check the home page source code on my browser, but nothing happened. The value of 'lang' in the HTML tag remained 'en'. It didn't change to 'fr' or 'es'.

                Language will change only if you (as user) select some new language in lang switcher.

                It doesn't matter how many languages admin installs on his site.

                By the way, in /inc/classes/BxDolLanguages.php, i saw some functions 'en-us => en' etc. Are those functions the ones controlling the change from 'en-us' to 'en' in the HTML lang tag automatically? (just asking). Will it be necessary to write new functions to automatically change from 'fr-fr => fr' or fr-ca => fr' or 'es-es =>es' or es-mx =>es' or 'pt-pt =>pt' or 'pt-br => pt' etc?

                Yes, this function is used to determine the exact lang code. I think you don't need to create any new functions here.

                • @Anton L , Thanks for your reply. i have followed your instructions and recreated the English (US) module (en-su) along with another test language module (es-es).

                  I replaced everything 'us' with 'en-us'. Same with the other test module where I used 'es-es'.

                  Unfortunately, both new language modules don't work. It seems like a bug in UNA. Please investigate.

                  Those language modules get installed normally, they show up in polyglot App when editing a language key, I can even select one of them as a default site language, they even show in the language switcher in frontend but they just don't work in the user side.

                  What happens is: whenever I select one of them from the language switcher, the URL in the browser address bar changes to mysite.com/lang=en-us or mysite.com/lang=es-es, then nothing happens. The site language doesn't change. Instead, it falls back to the default english (en) module packed with UNA, showing the gb/uk flag in the footer and the name "English" remains selected (in bold) in the language switcher. It doesn't select (doesn't format in bold) the name of the new language I choose in the language switcher, and it doesn't change the flag in the page footer too.

                  Also when i go to view the source code of my home page after switching to a new language (e.g: es-es), the 'lang' value in HTML tag falls back to 'en' like this : , instead of .

                  But with my old English (US) module using 'us'(before I changed it to 'en-us'), everything works perfectly. When I select the new language from the language switcher, the website url changes to mysite.com/lang=us and the website language changes as well. The language name in the language switcher get selected (in bold), the US flag shows in the page footer and the 'lang' value in HTML tag changes to 'us', although 'us' is not a valide ISO language code. Therefore, it shouldn't be used in the html lang tag. It will affect the SEO. That's why I want to do things correctly and use valide ISO language codes in the HTML lang tag. e.g: 'en', 'es', 'fr' etc.

                  There might be a bug in the language system of UNA. It doesn't support two letter language codes with two letter country/region codes (e.g: 'en-us', 'es-es', 'es-mx','fr-fr', 'fr-ca', etc). UNA seems to work with language modules with two letter language only (e.g: 'en', 'es', 'fr' etc). The evidence being my old language module with 'us' working perfectly.

                  I am suspecting that the problem is coming from the functions found in inc/classes/BxDolLanguages.php

                  Please consider investigating this issue. (I am running UNA 13.1.0-Stable)

                  Thanks

                  • Hi @Anton L Any idea on how to fix this issue that sounds more likely as bug in the UNA language system? Thanks.

                    • Hello. Send me a copy of your English (US) module via email. It will save some time to create my own. I'll install it and investigate the issue.

                      • Hi Anton, sounds good! I will be sending it to you for further investigations. Thanks a lot.

                        • Update: All the problems reported in this post have been fixed.

                          Issue #1: Languages with country cannot be used (Fixed):

                          https://github.com/unacms/una/issues/4651

                          Issue #2: HTML lang tag value (Fixed):

                          https://github.com/unacms/una/commit/9cb5d6bb40d08df81aaf37661cec8f9214864cb9

                          Thanks a lot to @Anton L who investigated those problems and provided for the solution. Thanks to UNA Team for the great work you guys are doing.

                          Login or Join to comment.