From 7d9f5bececa0cc010b3b9311a57ab6b9382a0f2e Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Tue, 17 Apr 2018 11:46:15 +0200 Subject: [PATCH] Add script to add a key/value in locale/en.json + put all scripts in scripts/ --- Makefile | 12 +- scripts/locale-add-key.pl | 25 +++ scripts/packaging.php | 202 ------------------ .po2json.sh => scripts/po2json.sh | 2 +- .../push-trad-to-zanata.sh | 0 .renest_json.pl => scripts/renest_json.pl | 0 6 files changed, 37 insertions(+), 204 deletions(-) create mode 100755 scripts/locale-add-key.pl delete mode 100644 scripts/packaging.php rename .po2json.sh => scripts/po2json.sh (67%) rename push-trad-to-zanata.sh => scripts/push-trad-to-zanata.sh (100%) rename .renest_json.pl => scripts/renest_json.pl (100%) diff --git a/Makefile b/Makefile index 772d705..2f4889c 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,17 @@ push-locales: locales pull-locales: zanata-cli -q -B pull --min-doc-percent 50 - ./.po2json.sh + scripts/po2json.sh stats-locales: zanata-cli -q stats + +push-trad-to-zanata: + scripts/push-trad-to-zanata.sh $(filter-out $@,$(MAKECMDGOALS)) + +add-key-locales: + scripts/locale-add-key.pl "$(subst ",\",$(filter-out $@,$(MAKECMDGOALS)))" + +# empty targets to be able to use MAKECMDGOALS as arguments to scripts +%: + @: diff --git a/scripts/locale-add-key.pl b/scripts/locale-add-key.pl new file mode 100755 index 0000000..cc1708d --- /dev/null +++ b/scripts/locale-add-key.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use JSON; + +my $json = JSON->new->utf8->space_before(0)->space_after(1)->indent(4)->canonical(1); + +my $en_file = 'locale/en.json'; +my $en; +{ + open my $fh, '<', $en_file or die; + local $/ = undef; + $en = <$fh>; + close $fh; +} + +$en = $json->decode($en); + +my ($key, $trad) = $ARGV[0] =~ m#^([^:]*):(.*)$#; +$en->{$key}->{$trad} = $trad; + +open my $fh, '>', $en_file or die; +print $fh $json->encode($en); +close $fh; diff --git a/scripts/packaging.php b/scripts/packaging.php deleted file mode 100644 index 25f8a7e..0000000 --- a/scripts/packaging.php +++ /dev/null @@ -1,202 +0,0 @@ - $file) { - if (is_int($key)) { - $key = $file; - } - - if (is_dir(ROOT . '/' . $key)) { - $result->$key = @rcopy(ROOT . '/' . $key, BUILD . '/' . $file); - } elseif (is_file(ROOT . '/' . $key)) { - $result->$key = @copy(ROOT . '/' . $key, BUILD . '/' . $file); - } - - i($result->$key, $key); - } -} - -function zip($source, $destination) { - if (extension_loaded('zip')) { - if (file_exists($source)) { - $zip = new ZipArchive(); - if ($zip->open($destination, ZIPARCHIVE::CREATE)) { - $source = realpath($source); - if (is_dir($source)) { - $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); - foreach ($files as $file) { - if (in_array(basename($file), ['.', '..'], true)) { - continue; - } - $file = realpath($file); - if ($file !== $source && is_dir($file)) { - $zip->addEmptyDir(str_replace($source . '\\', '', str_replace($source . '/', '', $file))); - } else if (is_file($file)) { - $zip->addFromString(str_replace($source . '\\', '', str_replace($source . '/', '', $file)), file_get_contents($file)); - } - } - } else if (is_file($source)) { - $zip->addFromString(basename($source), file_get_contents($source)); - } - } - return $zip->close(); - } - } - return false; -} - -ini_set('max_execution_time', 600); -ini_set('memory_limit', '1024M'); - -define('ROOT', realpath(__DIR__ . '/..')); -define('VENDOR', ROOT . '/vendor'); -define('DIST', ROOT . '/dist'); -define('BUILD', ROOT . '/build'); -define('BUILD_VENDOR', BUILD . '/vendor'); - -include ROOT . '/app/inc/constants.php'; - -$result = new stdClass(); - -echo '
';
-
-// Delete old dist>build directories
-
-if (file_exists(DIST)) {
-    $result->rmdirDist = rrmdir(DIST);
-    i($result->rmdirDist, 'Dist', ' deleted');
-}
-if (file_exists(BUILD)) {
-    $result->rmdirBuild = rrmdir(BUILD);
-    i($result->rmdirBuild, 'Build', ' deleted');
-}
-
-// Create dist>build directories
-
-$result->mkdirDist = mkdir(DIST, 755);
-i($result->mkdirDist, 'Dist', ' created');
-$result->mkdirBuild = mkdir(BUILD, 755);
-i($result->mkdirBuild, 'Build', ' created');
-
-// Copy dependencies files
-
-d('# Dependencies');
-
-$result->composer = copyDependencyToBuild('/composer');
-i($result->composer, 'composer');
-
-$result->o80 = copyDependencyToBuild('/o80/i18n/src');
-i($result->o80, 'o80-i18n');
-
-$result->smarty = copyDependencyToBuild('/smarty/smarty/libs');
-i($result->smarty, 'smarty');
-
-$result->autoload = @copy(VENDOR . '/autoload.php', BUILD_VENDOR . '/autoload.php');
-i($result->autoload, 'autoload');
-
-// Copy assets
-
-d('# Assets');
-copyFiles(['css', 'fonts', 'images', 'js'], $result);
-
-// Copy sources
-
-d('# Source directories');
-copyFiles(['admin', 'app', 'locale', 'tpl'], $result);
-
-d('# Source files');
-$files = [
-    'adminstuds.php',
-    'bandeaux.php',
-    'create_classic_poll.php',
-    'create_date_poll.php',
-    'create_poll.php',
-    'exportcsv.php',
-    'favicon.ico',
-    'htaccess.txt',
-    'index.php',
-    'INSTALL.md',
-    'LICENCE.fr.txt',
-    'LICENSE.en.txt',
-    'maintenance.php',
-    'php.ini',
-    'README.md',
-    'robots.txt',
-    'studs.php'
-];
-copyFiles($files, $result);
-
-// Zip Dist
-$output = DIST . '/framadate-' . VERSION . '-' . date('Ymd') . '.zip';
-zip(BUILD, $output);
-rrmdir(BUILD);
-
-if (isset($_GET['verbose'])) {
-    var_dump($result);
-}
-
-d('--------');
-d('Distribution file: ' . realpath($output));
-
-$generatedIn = round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 4);
-d('========');
-d('Generated in: ' . $generatedIn . ' secondes');
-echo '
'; diff --git a/.po2json.sh b/scripts/po2json.sh similarity index 67% rename from .po2json.sh rename to scripts/po2json.sh index 2ff9045..811ed71 100755 --- a/.po2json.sh +++ b/scripts/po2json.sh @@ -4,6 +4,6 @@ po2json -i po/en.po -t locale/en.json --progress none -o po/default.json for i in po/*.po do j=$(echo $i | cut -d '.' -f 1 | cut -d '/' -f 2) - po2json -i $i -t locale/en.json --progress none | ./.renest_json.pl > po/$j.json + po2json -i $i -t locale/en.json --progress none | scripts/renest_json.pl > po/$j.json mv po/$j.json locale/ done diff --git a/push-trad-to-zanata.sh b/scripts/push-trad-to-zanata.sh similarity index 100% rename from push-trad-to-zanata.sh rename to scripts/push-trad-to-zanata.sh diff --git a/.renest_json.pl b/scripts/renest_json.pl similarity index 100% rename from .renest_json.pl rename to scripts/renest_json.pl