Merge pull request #2648 from crazyserver/MOBILE-3665
MOBILE-3665 lang: Move en.json to lang.json on parent directory
This commit is contained in:
		
						commit
						d9a4280e45
					
				| @ -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); | ||||
|             } | ||||
|  | ||||
							
								
								
									
										14
									
								
								gulpfile.js
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								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')); | ||||
| }); | ||||
|  | ||||
| @ -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!' | ||||
| print_ok 'All done!' | ||||
|  | ||||
| @ -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); | ||||
|         } | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user