Remove all scripts for json-based i18n
This commit is contained in:
parent
3a6317c25a
commit
ecac9ccc94
14
Makefile
14
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
|
||||
%:
|
||||
@:
|
||||
|
@ -1,2 +0,0 @@
|
||||
allow from 127.0.0.1
|
||||
deny from all
|
@ -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()
|
@ -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;
|
@ -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
|
@ -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
|
@ -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
|
@ -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 = <STDIN>)) {
|
||||
$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);
|
Loading…
Reference in New Issue
Block a user