diff --git a/gulp/task-build-lang.js b/gulp/task-build-lang.js index 5927aa535..7fe60ad7c 100644 --- a/gulp/task-build-lang.js +++ b/gulp/task-build-lang.js @@ -41,22 +41,24 @@ class BuildLangTask { /** * Run the task. * - * @param language Language to treat. * @param langPaths Paths to the possible language files. * @param done Function to call when done. */ - run(language, langPaths, done) { - const filename = language + '.json'; + run(langPaths, done) { const data = {}; let firstFile = null; const self = this; const paths = langPaths.map((path) => { - if (path.slice(-1) != '/') { + if (path.endsWith('.json')) { + return path; + } + + if (!path.endsWith('/')) { path = path + '/'; } - return path + language + '.json'; + return path + 'lang.json'; }); gulp.src(paths, { allowEmpty: true }) @@ -72,7 +74,7 @@ class BuildLangTask { /* This implementation is based on gulp-jsoncombine module. * https://github.com/reflog/gulp-jsoncombine */ if (firstFile) { - const joinedPath = pathLib.join(firstFile.base, language + '.json'); + const joinedPath = pathLib.join(firstFile.base, 'en.json'); const joinedFile = new File({ cwd: firstFile.cwd, @@ -138,29 +140,28 @@ class BuildLangTask { const mergedOrdered = {}; const getPrefix = (path) => { const folders = path.split(/[\/\\]/); + let filename = folders.pop(); switch (folders[0]) { case 'core': switch (folders[1]) { - case 'lang': - return 'core.'; case 'features': return `core.${folders[2]}.`; + default: + return 'core.'; } - - break; case 'addons': - return `addon.${folders.slice(1, -2).join('_')}.`; + return `addon.${folders.slice(1).join('_')}.`; case 'assets': - return `assets.${folders[1]}.`; + filename = filename.split('.').slice(0, -1).join('.'); + return `assets.${filename}.`; + default: + return `${folders[0]}.${folders[1]}.`; } - - return null; } for (let filepath in data) { const prefix = getPrefix(filepath); - if (prefix) { this.addProperties(merged, data[filepath], prefix); } diff --git a/gulpfile.js b/gulpfile.js index e8efdd7a6..ae1ef0a8c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -19,11 +19,11 @@ const gulp = require('gulp'); const paths = { lang: [ - './src/addons/**/lang/', - './src/assets/countries/', - './src/assets/mimetypes/', - './src/core/features/**/lang/', - './src/core/lang/', + './src/addons/**/', + './src/assets/countries.json', + './src/assets/mimetypes.json', + './src/core/features/**/', + './src/core/', ], }; @@ -31,7 +31,7 @@ const args = Utils.getCommandLineArguments(); // Build the language files into a single file per language. gulp.task('lang', (done) => { - new BuildLangTask().run('en', paths.lang, done); + new BuildLangTask().run(paths.lang, done); }); gulp.task('push', (done) => { @@ -41,7 +41,5 @@ gulp.task('push', (done) => { gulp.task('default', gulp.parallel('lang')); gulp.task('watch', () => { - const langsPaths = paths.lang.map(path => path + 'en.json'); - gulp.watch(langsPaths, { interval: 500 }, gulp.parallel('lang')); }); diff --git a/scripts/create_langindex.sh b/scripts/create_langindex.sh index 9a82b64e0..432419b3c 100755 --- a/scripts/create_langindex.sh +++ b/scripts/create_langindex.sh @@ -324,4 +324,4 @@ jq -S --indent 2 -s '.[0]' langindex.json > langindex_new.json mv langindex_new.json langindex.json rm langindex_old.json -print_ok 'All done!' \ No newline at end of file +print_ok 'All done!' diff --git a/scripts/lang_functions.php b/scripts/lang_functions.php index 668070a60..f09bba4df 100644 --- a/scripts/lang_functions.php +++ b/scripts/lang_functions.php @@ -358,9 +358,7 @@ function detect_lang($lang, $keys) { return false; } -function save_key($key, $value, $path) { - $filePath = $path . '/en.json'; - +function save_key($key, $value, $filePath) { $file = file_get_contents($filePath); $file = (array) json_decode($file); $value = html_entity_decode($value); @@ -390,20 +388,20 @@ function override_component_lang_files($keys, $translations) { case 'addon': switch($component) { case 'moodle': - $path .= 'lang'; + $path .= 'lang.json'; break; default: - $path .= $type.'/'.str_replace('_', '/', $component).'/lang'; + $path .= $type.'/'.str_replace('_', '/', $component).'/lang.json'; break; } break; case 'assets': - $path .= $type.'/'.$component; + $path .= $type.'/'.$component.'.json'; break; } - if (is_file($path.'/en.json')) { + if (is_file($path)) { save_key($plainid, $value, $path); } } diff --git a/src/addons/privatefiles/lang/en.json b/src/addons/privatefiles/lang.json similarity index 100% rename from src/addons/privatefiles/lang/en.json rename to src/addons/privatefiles/lang.json diff --git a/src/assets/countries/en.json b/src/assets/countries.json similarity index 100% rename from src/assets/countries/en.json rename to src/assets/countries.json diff --git a/src/assets/mimetypes/en.json b/src/assets/mimetypes.json similarity index 100% rename from src/assets/mimetypes/en.json rename to src/assets/mimetypes.json diff --git a/src/core/features/contentlinks/lang/en.json b/src/core/features/contentlinks/lang.json similarity index 100% rename from src/core/features/contentlinks/lang/en.json rename to src/core/features/contentlinks/lang.json diff --git a/src/core/features/course/lang/en.json b/src/core/features/course/lang.json similarity index 100% rename from src/core/features/course/lang/en.json rename to src/core/features/course/lang.json diff --git a/src/core/features/courses/lang/en.json b/src/core/features/courses/lang.json similarity index 100% rename from src/core/features/courses/lang/en.json rename to src/core/features/courses/lang.json diff --git a/src/core/features/editor/lang/en.json b/src/core/features/editor/lang.json similarity index 100% rename from src/core/features/editor/lang/en.json rename to src/core/features/editor/lang.json diff --git a/src/core/features/fileuploader/lang/en.json b/src/core/features/fileuploader/lang.json similarity index 100% rename from src/core/features/fileuploader/lang/en.json rename to src/core/features/fileuploader/lang.json diff --git a/src/core/features/login/lang/en.json b/src/core/features/login/lang.json similarity index 100% rename from src/core/features/login/lang/en.json rename to src/core/features/login/lang.json diff --git a/src/core/features/mainmenu/lang/en.json b/src/core/features/mainmenu/lang.json similarity index 100% rename from src/core/features/mainmenu/lang/en.json rename to src/core/features/mainmenu/lang.json diff --git a/src/core/features/settings/lang/en.json b/src/core/features/settings/lang.json similarity index 100% rename from src/core/features/settings/lang/en.json rename to src/core/features/settings/lang.json diff --git a/src/core/features/sitehome/lang/en.json b/src/core/features/sitehome/lang.json similarity index 100% rename from src/core/features/sitehome/lang/en.json rename to src/core/features/sitehome/lang.json diff --git a/src/core/features/tag/lang/en.json b/src/core/features/tag/lang.json similarity index 100% rename from src/core/features/tag/lang/en.json rename to src/core/features/tag/lang.json diff --git a/src/core/features/user/lang/en.json b/src/core/features/user/lang.json similarity index 100% rename from src/core/features/user/lang/en.json rename to src/core/features/user/lang.json diff --git a/src/core/lang/en.json b/src/core/lang.json similarity index 100% rename from src/core/lang/en.json rename to src/core/lang.json