Check Localization Keys Usage #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Localization Keys Usage | |
on: | |
workflow_dispatch: | |
inputs: | |
locale: | |
description: "Locale to check (e.g., en-US)" | |
required: true | |
default: "en-US" | |
jobs: | |
check-localization: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_ASSETS_KEY }} | |
- name: Submoudles update | |
run: git -c submodule.auto-test.update=none submodule update --init --recursive | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '14' | |
- name: Install jq for JSON processing | |
run: sudo apt-get install jq | |
- name: Extract and check localization keys | |
run: | | |
# Initialize the markdown summary with the header for the table | |
echo "## Localization Keys Usage for Locale: ${{ github.event.inputs.locale }}" >> $GITHUB_STEP_SUMMARY | |
echo "| Localization Key | Status |" >> $GITHUB_STEP_SUMMARY | |
echo "| ---------------- | ------ |" >> $GITHUB_STEP_SUMMARY | |
# Define locale from input and file path for the JSON file | |
LOCALE=${{ github.event.inputs.locale }} | |
FILE_PATH="assets/translations/$LOCALE.json" | |
# Check if the localization file exists | |
if [ ! -f "$FILE_PATH" ]; then | |
echo "Localization file $FILE_PATH does not exist." >> $GITHUB_STEP_SUMMARY | |
exit 1 | |
fi | |
# Extract keys from the specified locale JSON file and check if they are used in .dart files in lib/ | |
jq 'keys' $FILE_PATH | tr -d '[],"' | tr -s ' ' '\n' | while read -r key; do | |
if grep -r "'$key'.tr()" ./lib/**/*.dart; then | |
echo "| $key | Used |" >> $GITHUB_STEP_SUMMARY | |
else | |
echo "| $key | Unused |" >> $GITHUB_STEP_SUMMARY | |
fi | |
done |