-
Bug
-
Resolution: Fixed
-
Minor
-
3.9.6, 3.10.3, 3.11, 4.0
-
MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE
-
MOODLE_310_STABLE, MOODLE_39_STABLE
-
MDL-71343-master -
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.