@by-association-only/translation-checker
v1.0.12
Published
Check Shopify theme translations match those used in local liquid files.
Readme
Translation Checker
What it does
Correctly set up, this script will prevent any files being deployed until all of the translations used in the local theme files are present on the live theme.
It runs in the terminal, and sits in front of any Shopify CLI theme comands.
- Pulls the current live en.default.json into a temp folder
- Scans local liquid files to construct an array of translation strings used in the theme
- Check that all of the strings exist in the temp en.default.json
- Print out the location of any missing strings in the terminal
Setup
- Add a config file in the root:
.bao-stores(or use existing.bao-translation-checker)
The tool will check for .bao-stores first, then fall back to .bao-translation-checker if not found.
List each store name on a separate line (the part before .myshopify.com).
Example: If your stores are:
- acmestore.myshopify.com
- acmestore-us.myshopify.com
You would enter:
acmestore
acmestore-us- Run the check at the start of your deploy script:
"scripts": {
...
"deploy": "npm run translations:check && npm run deploy:all",
"deploy:all": "npm run deploy:uk && npm run deploy:us",
"deploy:uk": "...",
"deploy:us": "...",
"shopify": "shopify",
"translations:check": "npm run shopify theme info && npx @by-association-only/translation-checker"
}Because the script exits with process.exit(1), it will prevent any further commands running if it finds any missing translations.
Issues
Please make sure you are using Shopify CLI v3.71+ and Node v18.20+ before continuing
1) No Shopify CLI
If the theme repo you're installing on does not have Shopify CLI, please run npm i @shopify/cli --save-dev
2) Error: Command failed: shopify theme pull
This means you're not logged into the CLI, or the CLI version is too old. It can be in issue on older themes that don't use the Shopify CLI, as this script cannot pass on the CLI's interactive login prompt.
To get around this, edit your package.json to include a 'shopify' command prior to running the translation checker. This will force a login prompt to be sent to your terminal. For example:
"scripts": {
...
"deploy": "yarn translations:check && unisian-tools deploy --skipPrompts",
"translations:check": "yarn run shopify theme info && npx @by-association-only/translation-checker",
"shopify": "shopify"
},If you're not authenticated, you'll now see the 'press any key to open in browser' terminal prompt from Shopify.
3) Error: Only file and data URLs are supported by the default ESM loader
Use node version 18.20.0+ to run the translation checker.
4) SyntaxError: Unexpected token } in JSON
The en.default.json file on the live theme likely contains invalid JSON.
The terminal should give you an idea where the error is:
Go into the code editor and fix the issue shown in the terminal.
If that doesn't resolve it, copy en.default.json out from the code editor and run through a JSON validator like https://jsonlint.com/ to find the issue.
