From e8f974ec65831d95024395ff67e76fc8f719a62d Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Sat, 9 Jan 2016 01:19:53 -0600 Subject: [PATCH] add translation helper script --- themes/antergos/.tx/combine_translations.js | 98 +++++++++++++++++++++ themes/antergos/js/Makefile.am | 2 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 themes/antergos/.tx/combine_translations.js diff --git a/themes/antergos/.tx/combine_translations.js b/themes/antergos/.tx/combine_translations.js new file mode 100644 index 0000000..4496361 --- /dev/null +++ b/themes/antergos/.tx/combine_translations.js @@ -0,0 +1,98 @@ +/* + * + * Copyright © 2015-2016 Antergos + * + * combine_translations.js + * + * This file is part of lightdm-webkit-theme-antergos + * + * lightdm-webkit-theme-antergos is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, + * or any later version. + * + * lightdm-webkit-theme-antergos is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * The following additional terms are in effect as per Section 7 of this license: + * + * The preservation of all legal notices and author attributions in + * the material or in the Appropriate Legal Notices displayed + * by works containing it is required. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +var fs = require( "fs" ), + path = require( 'path' ), + i18n_dir = process.argv[1] + 'i18n/', + translation_files = fs.readdirSync( i18n_dir ), + output = i18n_dir + 'translations.json', + translations = {}; + + +function sortObj( obj, order ) { + "use strict"; + + var key, + tempArry = [], + i, + tempObj = {}; + + for ( key in obj ) { + tempArry.push( key ); + } + + tempArry.sort( + function( a, b ) { + return a.toLowerCase().localeCompare( b.toLowerCase() ); + } + ); + + if ( order === 'desc' ) { + for ( i = tempArry.length - 1; i >= 0; i -- ) { + tempObj[ tempArry[ i ] ] = obj[ tempArry[ i ] ]; + } + } else { + for ( i = 0; i < tempArry.length; i ++ ) { + tempObj[ tempArry[ i ] ] = obj[ tempArry[ i ] ]; + } + } + + return tempObj; +} + + +for ( var file of translation_files ) { + var abs_path = i18n_dir + file, + lang = file.replace( '.json', '' ); + + if ( 'translations.json' === file ) { + console.log( 'found' ); + continue; + } + + translations[ lang ] = JSON.parse( fs.readFileSync( abs_path, 'utf8' ) ); +} + +translations = sortObj( translations ); + +fs.writeFile( output, JSON.stringify( translations ), function( error ) { + if ( error ) { + console.error( "write error: " + error.message ); + } else { + console.log( "Successful Write to " + output ); + } +} ); +fs.writeFile( i18n_dir + 'js/translations.js', 'window.ant_translations = ' + JSON.stringify( translations ), function( error ) { + if ( error ) { + console.error( "write error: " + error.message ); + } else { + console.log( "Successful Write to " + output ); + } +} ); + +console.log( 'Done!' ); diff --git a/themes/antergos/js/Makefile.am b/themes/antergos/js/Makefile.am index e0e8d75..58c1fa0 100644 --- a/themes/antergos/js/Makefile.am +++ b/themes/antergos/js/Makefile.am @@ -3,7 +3,7 @@ javascript_DATA = \ greeter.js \ greeter-compiled.js \ greeter-compiled.js.map \ - greeting_translations.js \ + translations.js \ mock.js EXTRA_DIST = $(javascript_DATA)