Skip to content

Commit

Permalink
Merge pull request #398 from w3c/strings-crosscheck
Browse files Browse the repository at this point in the history
First reconciliation of UX guidelines IDs
  • Loading branch information
gregoriopellegrino authored Sep 20, 2024
2 parents 9ed924c + 5438e2e commit 86e6eda
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 98 deletions.
20 changes: 20 additions & 0 deletions UX-Guide-Metadata/bin/extract-ids-from-principles.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<strings>
<xsl:apply-templates select="//*[@data-localization-id]"/>
</strings>
</xsl:template>

<xsl:template match="//*[@data-localization-id]">
<string>
<id><xsl:value-of select="@data-localization-id"/></id>
<mode><xsl:value-of select="@data-localization-mode"/></mode>
<value><xsl:value-of select="normalize-space(.)"/></value>
</string>
</xsl:template>

</xsl:stylesheet>
2 changes: 1 addition & 1 deletion UX-Guide-Metadata/bin/extract-ids-from-techniques.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<xsl:template match="xhtml:code[@id]">
<string>
<id><xsl:value-of select="@id"/></id>
<value><xsl:value-of select="substring(., 2, string-length(.) - 2)"/></value>
<value><xsl:value-of select="normalize-space(substring(., 2, string-length(.) - 2))"/></value>
</string>
</xsl:template>

Expand Down
34 changes: 20 additions & 14 deletions UX-Guide-Metadata/bin/strings-crosscheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,44 @@ basedir=$(dirname "$basedir")
tmpdir=$(mktemp -d)

# input files
principles="$basedir/../draft/principles/index.html"
xslt_principles="$basedir/extract-ids-from-principles.xsl"
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"
xslt_techniques="$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"
xsltproc "$xslt_principles" "$principles" > "$output_dir/principles-strings.xml"
xsltproc "$xslt_techniques" "$epub_techniques" > "$output_dir/epub-metadata-strings.xml"
xsltproc "$xslt_techniques" "$onix_techniques" > "$output_dir/onix-metadata-strings.xml"

# converts XML files to CSV
java -jar "$basedir/libs/xml2csv-1.1.jar" "$output_dir/principles-strings.xml" > "$output_dir/principles-strings.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"
# 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/principles-strings.csv" "$output_dir/principles-strings.xlsx"
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"
# ssconvert "$output_dir/canonical-json-strings.csv" "$output_dir/canonical-json-strings.xlsx"

# cleanup
rm -f "$output_dir/principles-strings.csv"
rm -f "$output_dir/epub-metadata-strings.csv"
rm -f "$output_dir/onix-metadata-strings.csv"
rm -f "$output_dir/canonical-json-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.
Loading

0 comments on commit 86e6eda

Please sign in to comment.