From ecac9ccc94fa9402968bd07bcaf989e588709912 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Thu, 18 Apr 2019 15:15:14 +0200 Subject: [PATCH] Remove all scripts for json-based i18n --- Makefile | 14 --------- scripts/.htaccess | 2 -- scripts/check-translations.py | 53 ---------------------------------- scripts/locale-add-key.pl | 25 ---------------- scripts/locales.sh | 9 ------ scripts/po2json.sh | 15 ---------- scripts/push-trad-to-zanata.sh | 11 ------- scripts/renest_json.pl | 40 ------------------------- 8 files changed, 169 deletions(-) delete mode 100644 scripts/.htaccess delete mode 100755 scripts/check-translations.py delete mode 100755 scripts/locale-add-key.pl delete mode 100755 scripts/locales.sh delete mode 100755 scripts/po2json.sh delete mode 100755 scripts/push-trad-to-zanata.sh delete mode 100755 scripts/renest_json.pl diff --git a/Makefile b/Makefile index df98fac..8ed772d 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,8 @@ -locales: - scripts/locales.sh - push-locales: locales zanata-cli -q -B push --errors --project-version `git branch | grep \* | cut -d ' ' -f2-` pull-locales: zanata-cli -q -B pull --min-doc-percent 50 --project-version `git branch | grep \* | cut -d ' ' -f2-` - scripts/po2json.sh stats-locales: zanata-cli -q stats --project-version `git branch | grep \* | cut -d ' ' -f2-` - -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/.htaccess b/scripts/.htaccess deleted file mode 100644 index d30cea2..0000000 --- a/scripts/.htaccess +++ /dev/null @@ -1,2 +0,0 @@ -allow from 127.0.0.1 -deny from all \ No newline at end of file diff --git a/scripts/check-translations.py b/scripts/check-translations.py deleted file mode 100755 index b50e56b..0000000 --- a/scripts/check-translations.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python - -import json -import glob - -def get_all_keys(jsons_dict): - all_keys = set() - - for json_dict in jsons_dict.values(): - all_keys |= flatten_keys(json_dict) - - return all_keys - -def flatten_keys(json_dict): - all_keys = set() - - for key in json_dict.keys(): - el = json_dict[key] - if isinstance(el, dict): - flatten = flatten_keys(el) - for flat_key in flatten: - all_keys.add("%s.%s" % (key, flat_key)) - else: - all_keys.add(key) - - return all_keys - -def check_files_share_same_keys(all_keys, jsons): - exit_code = 0 - - for locale in jsons.keys(): - difference = all_keys - flatten_keys(jsons[locale]) - if bool(difference): - print("%s has missing translation keys:" % (locale)) - for el in difference: - print(" - %s" % (el)) - exit_code = 1 - - return exit_code - -def main(): - locales_dir = "locale/*.json" - - jsons = {} - for json_file in glob.iglob(locales_dir): - with open(json_file) as f: - jsons[json_file] = json.load(f) - - all_keys = get_all_keys(jsons) - - return check_files_share_same_keys(all_keys, jsons) - -main() diff --git a/scripts/locale-add-key.pl b/scripts/locale-add-key.pl deleted file mode 100755 index cc1708d..0000000 --- a/scripts/locale-add-key.pl +++ /dev/null @@ -1,25 +0,0 @@ -#!/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/locales.sh b/scripts/locales.sh deleted file mode 100755 index a263d59..0000000 --- a/scripts/locales.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -python -m json.tool < locale/en.json >/dev/null 2>&1 -if [[ $? == 0 ]]; -then - json2po -P -i locale/en.json -t locale/en.json -o po/framadate.pot --duplicates merge -else - echo "Can't convert json files to po, the json file is incorrect" - exit 1 -fi diff --git a/scripts/po2json.sh b/scripts/po2json.sh deleted file mode 100755 index c319b9e..0000000 --- a/scripts/po2json.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -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) - - # When there is a comma in a key, Zanata replaces it by a newline. And po2json doesn't like this. - # Edit the po file, to restore split key names on a single line again. - vim -E -c "while search('^\\(#: \\..*\\)\\(\\n\\_^#: \\([^.].*\\)\\)\\+') | s/\n#: /,/ | endwhile" -c 'x' -- $i - - # Convert the po file to json - po2json -i $i -t po/default.json --progress none | scripts/renest_json.pl > po/$j.json - mv po/$j.json locale/ -done diff --git a/scripts/push-trad-to-zanata.sh b/scripts/push-trad-to-zanata.sh deleted file mode 100755 index 6c14107..0000000 --- a/scripts/push-trad-to-zanata.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -FILE=$1 -if [[ ! -e locale/$FILE.json ]] -then - echo "locale/$FILE.json does not exist. Exiting." - exit 1 -else - LOCALE=$(echo $FILE | sed -e "s@_@-@g") - json2po -i locale/$FILE.json -t locale/en.json -o po/$FILE.po - zanata-cli -q -B push --push-type trans -l $LOCALE --project-version $(git branch | grep \* | cut -d ' ' -f2-) -fi diff --git a/scripts/renest_json.pl b/scripts/renest_json.pl deleted file mode 100755 index 2c72278..0000000 --- a/scripts/renest_json.pl +++ /dev/null @@ -1,40 +0,0 @@ -#!/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 = 'po/default.json'; -my $en; -{ - open my $fh, '<', $en_file or die; - local $/ = undef; - $en = <$fh>; - close $fh; -} - -$en = $json->decode($en); - -my $new_json = {}; -my $old_json = ''; - -while (defined(my $line = )) { - $old_json .= $line; -} - -$old_json = $json->decode($old_json); -for my $key (keys %{$old_json}) { - my $index = index($key, '.'); - my $real_key = substr($key, 0, $index++); - my $trad_key = substr($key, $index); - - if ($old_json->{$key}) { - $new_json->{$real_key}->{$trad_key} = $old_json->{$key}; - } else { - $new_json->{$real_key}->{$trad_key} = $en->{$key}; - } -} - -print $json->encode($new_json);