Skip to content

Commit

Permalink
Merge pull request #376 from w3c/strings-crosscheck
Browse files Browse the repository at this point in the history
Script for crosschecking strings in techniques and localizations
  • Loading branch information
gregoriopellegrino authored Aug 20, 2024
2 parents 5830313 + cf01277 commit 51f7029
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ UX-Guide-Metadata/bin/_tmp/

UX-Guide-Metadata/UX-Guide-Metadata-principles.zip
Gautier.md
UX-Guide-Metadata/draft/localizations/canonical-json-strings.csv
UX-Guide-Metadata/draft/localizations/epub-metadata-strings.csv
UX-Guide-Metadata/draft/localizations/epub-metadata-strings.xml
UX-Guide-Metadata/draft/localizations/onix-metadata-strings.csv
UX-Guide-Metadata/draft/localizations/onix-metadata-strings.xml
UX-Guide-Metadata/draft/localizations/canonical-json-strings.xlsx
UX-Guide-Metadata/draft/localizations/epub-metadata-strings.xlsx
UX-Guide-Metadata/draft/localizations/onix-metadata-strings.xlsx
UX-Guide-Metadata/draft/localizations/~$canonical-json-strings.xlsx
Binary file added UX-Guide-Metadata/bin/libs/xml2csv-1.1.jar
Binary file not shown.
60 changes: 60 additions & 0 deletions UX-Guide-Metadata/bin/strings-crosscheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# Script for crosschecking the strings in techniques and canonical JSON for localization
# Requires xsltproc, java, gnumeric (http://www.gnumeric.org/) and jq (https://jqlang.github.io/jq/download/)

# function to check whether a command is available
check_command() {
if ! command -v "$1" &> /dev/null; then
echo "Error: $1 is not installed. Please install it and try again."
exit 1
fi
}

# check for the presence of the necessary tools
check_command xsltproc
check_command java
check_command jq
check_command ssconvert

# pre-run
basedir=$(readlink -f "$0")
basedir=$(dirname "$basedir")
tmpdir=$(mktemp -d)

# input files
epub_techniques="$basedir/../draft/techniques/epub-metadata/index.html"
onix_techniques="$basedir/../draft/techniques/onix-metadata/index.html"
xslt="$basedir/extract-ids-from-techniques.xsl"
canonical_json="$basedir/../draft/localizations/en-US/display_guide_vocabulary_w3c_en-US.json"
output_dir="$basedir/../draft/localizations"

# performs XSLT transformation on XHTML files
xsltproc "$xslt" "$epub_techniques" > "$output_dir/epub-metadata-strings.xml"
xsltproc "$xslt" "$onix_techniques" > "$output_dir/onix-metadata-strings.xml"

# converts XML files to CSV
java -jar "$basedir/libs/xml2csv-1.1.jar" "$output_dir/epub-metadata-strings.xml" > "$output_dir/epub-metadata-strings.csv"
java -jar "$basedir/libs/xml2csv-1.1.jar" "$output_dir/onix-metadata-strings.xml" > "$output_dir/onix-metadata-strings.csv"

# converts JSON file to CSV
json_in_csv=$(jq -r '
to_entries[] |
select(.value | type == "object" and (has("descriptive") or has("compact"))) |
[.key, .value.descriptive // "", .value.compact // ""] |
@csv
' "$canonical_json")
echo '"key","descriptive","compact"' > "$output_dir/canonical-json-strings.csv"
echo "$json_in_csv" >> "$output_dir/canonical-json-strings.csv"

# converts CSV files to Excel
ssconvert "$output_dir/epub-metadata-strings.csv" "$output_dir/epub-metadata-strings.xlsx"
ssconvert "$output_dir/onix-metadata-strings.csv" "$output_dir/onix-metadata-strings.xlsx"
ssconvert "$output_dir/canonical-json-strings.csv" "$output_dir/canonical-json-strings.xlsx"

# cleanup
rm -f "$output_dir/epub-metadata-strings.csv"
rm -f "$output_dir/onix-metadata-strings.csv"
rm -f "$output_dir/canonical-json-strings.csv"

echo "Operations completed. Need to manually update Excel file localizations/crosscheck strings epub-onix-canonical_json.xlsx"
Binary file not shown.

0 comments on commit 51f7029

Please sign in to comment.