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

Missing translation due to H5P language file line ending format

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.9.6, 3.10.3, 3.11, 4.0
    • Fix Version/s: 3.9.7, 3.10.4
    • Component/s: H5P
    • Labels:
    • Testing Instructions:
      Hide

      Setup

      1. Login as Admin
      2. Navigate to Site Administration > H5P > Manage H5P Content Types
      3. Upload the attached accordion.h5p file to the "H5P content type" field
      4. Click the "Upload H5P content types" button

       

      Test 1: LF format

      1. Log in as admin.
      2. On Moodle, ensure that the default language is set to English (en).
      3. Open the file h5p/h5plib/v124/joubel/editor/language/en.js
      4. Change the "end of line sequence" to LF and save the file. On VS Code or Notepad++, you can easily change this from the status bar, located at the bottom.
      5. On Moodle, purge Language strings and Javascript caches.
      6. Now access the Content bank and add a H5P Accordion content.
      7. Confirm that all strings are correctly displayed. You should not see any "missing translation" messages.

       

      Test 2: CRLF format

      1. Log in as admin.
      2. On Moodle, ensure that the default language is set to English (en).
      3. Open the file h5p/h5plib/v124/joubel/editor/language/en.js
      4. Change the "end of line sequence" to CRLF and save the file. On VS Code or Notepad++, you can easily change this from the status bar, located at the bottom.
      5. On Moodle, purge Language strings and Javascript caches.
      6. Now access the Content bank and add a H5P Accordion content.
      7. Confirm that all strings are correctly displayed. You should not see any "missing translation" messages.
      Show
      Setup Login as Admin Navigate to Site Administration > H5P > Manage H5P Content Types Upload the attached  accordion.h5p  file to the "H5P content type" field Click the "Upload H5P content types" button   Test 1: LF format Log in as admin. On Moodle, ensure that the default language is set to English (en). Open the file h5p/h5plib/v124/joubel/editor/language/en.js Change the "end of line sequence" to  LF  and save the file. On VS Code or Notepad++, you can easily change this from the status bar, located at the bottom. On Moodle, purge Language strings and Javascript caches. Now access the Content bank and add a H5P Accordion content. Confirm  that all strings are correctly displayed. You should not see any "missing translation" messages.   Test 2: CRLF format Log in as admin. On Moodle, ensure that the default language is set to English (en). Open the file h5p/h5plib/v124/joubel/editor/language/en.js Change the "end of line sequence" to  CRLF  and save the file. On VS Code or Notepad++, you can easily change this from the status bar, located at the bottom. On Moodle, purge Language strings and Javascript caches. Now access the Content bank and add a H5P Accordion content. Confirm  that all strings are correctly displayed. You should not see any "missing translation" messages.
    • Affected Branches:
      MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE
    • Fixed Branches:
      MOODLE_310_STABLE, MOODLE_39_STABLE
    • Pull from Repository:
    • Pull 3.9 Branch:
      MDL-71343-m39
    • Pull 3.10 Branch:
      MDL-71343-m310
    • Pull 3.11 Branch:
      MDL-71343-m311
    • Pull Master Branch:
      MDL-71343-master

      Description

      We were getting "missing translation" errors for several language strings when adding/editing H5P content in the content bank.

      We could reproduce this issue in Moodle versions: 3.9, 3.10 and master.

      Others have reported it as well here: https://moodle.org/mod/forum/discuss.php?d=406288

       

      We tried uninstalling/reinstalling language packs, purging all caches, uninstalling/reinstalling H5P contenttypes/libraries, upgrading Moodle versions, but the issue would still persist.

      Upon further investigation, we found that the issue was caused by the different line ending format in the language files (en.js for example) in:

      h5p/h5plib/v124/joubel/editor/language

      Line endings in Unix is LF, in Mac is CR and in Windows is CRLF.

      The following line in function parse_js_array(string $jscontent) in h5p/classes/helper.php

      $jsarray = preg_split('/,\n\s+/', substr($jscontent, 0, -1));
      

      is considering LF (\n) only when parsing the language file. If the line endings are in another format, then the language strings are not correctly parsed and you get the missing translation error.

      Replacing the files in h5p/h5plib/v124/joubel/editor/language and purging cache correctly parses the H5P lang strings.

      I think the code fix would be to consider all line ending formats when parsing the file.

      The following change in function parse_js_array(string $jscontent) in h5p/classes/helper.php fixes the issue.

      $jsarray = preg_split('/,[\r\n]\s+/'substr($jscontent, 0, -1));
      

       

      Steps to reproduce this bug
      Log in as admin.
      On Moodle, the default language is set to English (en).
      Open the file h5p/h5plib/v124/joubel/editor/language/en.js
      Change the "end of line sequence" to CRLF and save the file. On VS Code or Notepad++, you can easily change this from the status bar, located at the bottom.
      On Moodle, purge Language strings and Javascript caches.
      Now access the Content bank and add any H5P interactive content.
      You will see several "missing translation" messages.

        Attachments

        1. 0001-MDL-71343-h5p-Add-unit-test-for-helper-parse_js_arra.patch
          2 kB
        2. accordion.h5p
          530 kB
        3. MDL-71343 CRLF1.png
          MDL-71343 CRLF1.png
          71 kB
        4. MDL-71343 CRLF2.png
          MDL-71343 CRLF2.png
          32 kB
        5. MDL-71343 LF1.png
          MDL-71343 LF1.png
          82 kB
        6. MDL-71343 LF2.png
          MDL-71343 LF2.png
          25 kB
        7. MDL-71343-patch.zip
          3 kB
        8. moodle_h5p_contentbank.png
          moodle_h5p_contentbank.png
          141 kB

          Activity

            People

            Assignee:
            rjnl Rajneel Totaram
            Reporter:
            rjnl Rajneel Totaram
            Peer reviewer:
            Amaia Anabitarte Amaia Anabitarte
            Integrator:
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Tester:
            Simey Lameze Simey Lameze
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              10/May/21

                Time Tracking

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