Skip to content

Commit

Permalink
Add script to generate JSON files
Browse files Browse the repository at this point in the history
Borrowed from WooCommerce Admin plugin.
  • Loading branch information
renatho committed May 29, 2020
1 parent 550d7a0 commit 715324a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bin/make-i18n-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# Check for required version
WPCLI_VERSION=`wp cli version | cut -f2 -d' '`
if [ ${WPCLI_VERSION:0:1} -lt "2" -o ${WPCLI_VERSION:0:1} -eq "2" -a ${WPCLI_VERSION:2:1} -lt "1" ]; then
echo WP-CLI version 2.1.0 or greater is required to make JSON translation files
exit
fi

# Substitute JS source references with build references
# For new rules, duplicate the line `-e ...`
for T in `find lang -name "*.po"`
do
sed \
-e 's/ assets\/onboarding[^:]*:/ assets\/dist\/onboarding\/index.js:/gp' \
$T | uniq > $T-build
rm $T
mv $T-build $T
done

# Make the JSON files
wp i18n make-json lang --no-purge
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"i18n:js": "npx babel --config-file ./babel.makepot.js -o ./lang/tmp-babel.log assets --ignore \"**/*.test.js\",\"./assets/dist\",\"./assets/vendor\"",
"i18n:php": "wp i18n make-pot --merge=lang/tmp-sensei-lms-js.pot --skip-js --headers='{\"Last-Translator\":null,\"Language-Team\":null}' . lang/sensei-lms.pot",
"i18n:build": "npm run i18n:clean && npm run i18n:js && npm run i18n:php && node ./bin/replace-pot-jsx-js && npm run i18n:clean",
"i18n:json": "./bin/make-i18n-json.sh",
"format-js": "wp-scripts format-js",
"lint-css": "wp-scripts lint-style **/*.scss",
"lint-css:fix": "npm run lint-css -- --fix",
Expand Down

0 comments on commit 715324a

Please sign in to comment.