Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-80393

Ensure Javascript requests that require current language have access to it

    XMLWordPrintable

Details

    • MOODLE_403_STABLE
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-80393-401
    • MDL-80393-402
    • MDL-80393-403
    • Hide
      1. Log in as admin
      2. Navigate to Language > Language packs in site administration
      3. Install "Portuguese - Brazil (pt_br)"
      4. Navigate to Language > Language customisation in site administration
      5. Select new Portuguese/Brazil language pack and open for editing
        • Show strings of these components: langconfig.php
        • String identifier: iso6391
      6. Set Local customisation to "pt" and save/confirm changes [*]
      7. From user menu, switch to "pt_br" language
      8. Open browser developer console
      9. Purge caches (press Limpar todos os caches)
      10. Press Painel to navigate to Dashboard
      11. Confirm there is no "Invalid parameter value detected" error on screen
      12. Open browser Network console
      13. Filter for requests containing "get_string"
      14. Examine the request arguments, confirm that the "lang" argument is "pt_br" - it'll look like the following:

        <WWWROOT>/lib/ajax/service-nologin.php?info=core_get_string&cachekey=1702403613&args=%5B%7B%22index%22%3A0%2C%22methodname%22%3A%22core_get_string%22%2C%22args%22%3A%7B%22stringid%22%3A%22moreevents%22%2C%22stringparams%22%3A%5B%5D%2C%22component%22%3A%22calendar%22%2C%22lang%22%3A%22pt_br%22%7D%7D%5D
        

      15. Filter for requests containing "core_output_load_template_with_dependencies"
      16. Examine the request arguments, confirm that the "lang" argument is "pt_br" - it'll look like the following:

        <WWWROOT>/lib/ajax/service-nologin.php?info=core_output_load_template_with_dependencies&cachekey=1702398744&args=[{%22index%22%3A0%2C%22methodname%22%3A%22core_output_load_template_with_dependencies%22%2C%22args%22%3A{%22component%22%3A%22calendar%22%2C%22template%22%3A%22modal_event_form%22%2C%22themename%22%3A%22boost%22%2C%22lang%22%3A%22pt_br%22}}]
        

      17. Open browser Javascript console
      18. Execute the following:

        require('core/user_date').get([{timestamp: 1672581600, format: '%d %B %Y' }]).then(window.console.log)
        

      19. Open browser Storage console
      20. View Session Storage for page
      21. Examine the presence of "*/core_user_date/pt_br/*" key

      [*] This is required because AMOS has already been fixed, so we need to recreate the original conditions that cause this error for sites that don't have up-to-date language packs and/or language packs with misconfigured ISO code

      Show
      Log in as admin Navigate to Language > Language packs in site administration Install "Portuguese - Brazil (pt_br)" Navigate to Language > Language customisation in site administration Select new Portuguese/Brazil language pack and open for editing Show strings of these components: langconfig.php String identifier: iso6391 Set Local customisation to "pt" and save/confirm changes [*] From user menu, switch to "pt_br" language Open browser developer console Purge caches (press Limpar todos os caches ) Press Painel to navigate to Dashboard Confirm there is no "Invalid parameter value detected" error on screen Open browser Network console Filter for requests containing "get_string" Examine the request arguments, confirm that the "lang" argument is "pt_br" - it'll look like the following: <WWWROOT>/lib/ajax/service-nologin.php?info=core_get_string&cachekey=1702403613&args=%5B%7B%22index%22%3A0%2C%22methodname%22%3A%22core_get_string%22%2C%22args%22%3A%7B%22stringid%22%3A%22moreevents%22%2C%22stringparams%22%3A%5B%5D%2C%22component%22%3A%22calendar%22%2C%22lang%22%3A%22pt_br%22%7D%7D%5D Filter for requests containing "core_output_load_template_with_dependencies" Examine the request arguments, confirm that the "lang" argument is "pt_br" - it'll look like the following: <WWWROOT>/lib/ajax/service-nologin.php?info=core_output_load_template_with_dependencies&cachekey=1702398744&args=[{%22index%22%3A0%2C%22methodname%22%3A%22core_output_load_template_with_dependencies%22%2C%22args%22%3A{%22component%22%3A%22calendar%22%2C%22template%22%3A%22modal_event_form%22%2C%22themename%22%3A%22boost%22%2C%22lang%22%3A%22pt_br%22}}] Open browser Javascript console Execute the following: require('core/user_date').get([{timestamp: 1672581600, format: '%d %B %Y' }]).then(window.console.log) Open browser Storage console View Session Storage for page Examine the presence of "*/core_user_date/pt_br/*" key [*] This is required because AMOS has already been fixed, so we need to recreate the original conditions that cause this error for sites that don't have up-to-date language packs and/or language packs with misconfigured ISO code

    Description

      After the last upgrade that I did yesterday (4.3.1 / 20231211), I got an error with every user that has pt_br (Portuguese of Brazil) as his language. 

      It was only fixed when I installed pt (Portuguese of Portugal) language pack. It was an Ajax or JavaScript error.

      Addendum

      This is as a result of MDL-80185, which now uses the ISO 639-1 code of the current language pack in order to meet accessibility criteria for the current page (see that issue for context)

      However, we also need a means to get the Moodle language code inside Javascript as described by joãopedro in that same issue. See also this forum thread

      We should update the langconfig for the "Portuguese - Brazil" language pack too, because it currently uses the value "en" which is wrong, it should be "pt-br": https://lang.moodle.org/local/amos/view.php?t=1702387094&v=l&l=pt_br&c=langconfig&s&d=iso6391
       

      Example error

      Invalid external api parameter: the value is "nb", the server was expecting "lang" type Error code: invalidparameter
       * line 367 of /lib/externallib.php: invalid_parameter_exception thrown
       * line 241 of /lib/externallib.php: call to external_api::validate_parameters()
       * line 81 of /lib/ajax/service.php: call to external_api::call_external_function()
       * line 33 of /lib/ajax/service-nologin.php: call to require_once()
      


      Update 20 Dec 2023: The pt_br lang string iso6391 in core_langconfig has been updated in AMOS, also for a number of other languages. Sites using these language packs will find the bug resolved with a language pack update.

      However, some languages, such as zh_cn and sr_lt also require code changes to resolve the bug. In other words, sites using these languages need to upgrade to 4.1.8, 4.2.5 or 4.3.2 to resolve the bug.

      Attachments

        Issue Links

          Activity

            People

              pholden Paul Holden
              marcelo.schmitt Marcelo
              Pedro Jordao Pedro Jordao
              Jun Pataleta Jun Pataleta
              Kim Jared Lucas Kim Jared Lucas
              Votes:
              11 Vote for this issue
              Watchers:
              27 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 6 hours, 15 minutes
                  6h 15m

                  Clockify

                    Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.