1
+ #! /bin/bash
2
+
3
+ # Script for crosschecking the strings in techniques and canonical JSON for localization
4
+ # Requires xsltproc, java, gnumeric (http://www.gnumeric.org/) and jq (https://jqlang.github.io/jq/download/)
5
+
6
+ # function to check whether a command is available
7
+ check_command () {
8
+ if ! command -v " $1 " & > /dev/null; then
9
+ echo " Error: $1 is not installed. Please install it and try again."
10
+ exit 1
11
+ fi
12
+ }
13
+
14
+ # check for the presence of the necessary tools
15
+ check_command xsltproc
16
+ check_command java
17
+ check_command jq
18
+ check_command ssconvert
19
+
20
+ # pre-run
21
+ basedir=$( readlink -f " $0 " )
22
+ basedir=$( dirname " $basedir " )
23
+ tmpdir=$( mktemp -d)
24
+
25
+ # input files
26
+ epub_techniques=" $basedir /../draft/techniques/epub-metadata/index.html"
27
+ onix_techniques=" $basedir /../draft/techniques/onix-metadata/index.html"
28
+ xslt=" $basedir /extract-ids-from-techniques.xsl"
29
+ canonical_json=" $basedir /../draft/localizations/en-US/display_guide_vocabulary_w3c_en-US.json"
30
+ output_dir=" $basedir /../draft/localizations"
31
+
32
+ # performs XSLT transformation on XHTML files
33
+ xsltproc " $xslt " " $epub_techniques " > " $output_dir /epub-metadata-strings.xml"
34
+ xsltproc " $xslt " " $onix_techniques " > " $output_dir /onix-metadata-strings.xml"
35
+
36
+ # converts XML files to CSV
37
+ java -jar " $basedir /libs/xml2csv-1.1.jar" " $output_dir /epub-metadata-strings.xml" > " $output_dir /epub-metadata-strings.csv"
38
+ java -jar " $basedir /libs/xml2csv-1.1.jar" " $output_dir /onix-metadata-strings.xml" > " $output_dir /onix-metadata-strings.csv"
39
+
40
+ # converts JSON file to CSV
41
+ json_in_csv=$( jq -r '
42
+ to_entries[] |
43
+ select(.value | type == "object" and (has("descriptive") or has("compact"))) |
44
+ [.key, .value.descriptive // "", .value.compact // ""] |
45
+ @csv
46
+ ' " $canonical_json " )
47
+ echo ' "key","descriptive","compact"' > " $output_dir /canonical-json-strings.csv"
48
+ echo " $json_in_csv " >> " $output_dir /canonical-json-strings.csv"
49
+
50
+ # converts CSV files to Excel
51
+ ssconvert " $output_dir /epub-metadata-strings.csv" " $output_dir /epub-metadata-strings.xlsx"
52
+ ssconvert " $output_dir /onix-metadata-strings.csv" " $output_dir /onix-metadata-strings.xlsx"
53
+ ssconvert " $output_dir /canonical-json-strings.csv" " $output_dir /canonical-json-strings.xlsx"
54
+
55
+ # cleanup
56
+ rm -f " $output_dir /epub-metadata-strings.csv"
57
+ rm -f " $output_dir /onix-metadata-strings.csv"
58
+ rm -f " $output_dir /canonical-json-strings.csv"
59
+
60
+ echo " Operations completed. Need to manually update Excel file localizations/crosscheck strings epub-onix-canonical_json.xlsx"
0 commit comments