Automating Missing Translation Checks with GitHub Actions

In the previous blog post, we explored a Node.js script that helps identify missing translations in JSX files. Now, let's take the next step and automate this process using GitHub Actions. By doing so, you can ensure that every pull request is checked for missing translations, providing a seamless and efficient way to maintain your application's internationalization.

Setting Up GitHub Actions

  1. Create the Workflow YAML File

    In your project repository, create a new directory named .github/workflows if it doesn't exist. Inside this directory, create a file named translation-check.yml with the following content:

name: Translation Check

on:
    pull_request:
      branches: [ "main" ]
    
jobs:
  translation-check:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Repository
      uses: actions/checkout@v2

    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '18'

    - name: Install Dependencies
      run: npm install

    - name: Run Translation Check
      run: |
        result=$(node ./checkMissingTranslations.cjs)
        echo "$result"
        if [ "$result" != "" ]; then
          echo "Found missing translations. Failing the job."
          exit 1
        fi

Ensure you replace path/to/your/script.cjs with the actual path to your Node.js script.

  1. Commit and Push

    Commit the changes to your repository and push them to GitHub:

    git add .github/workflows/translation-check.yml
    git commit -m "Add GitHub Actions workflow for translation check"
    git push
    
  2. Verify Workflow Execution

    Once you push the changes, GitHub Actions will automatically run the workflow on every pull request. Navigate to the "Actions" tab in your GitHub repository to check the status and logs of the workflow runs.

Conclusion

By integrating GitHub Actions into your project, you've automated the process of checking for missing translations in every pull request. This ensures that your internationalization remains robust and up-to-date without manual intervention. Customize the workflow further based on your project's needs and expand its capabilities as your requirements evolve.

Automating tasks like translation checks not only saves time but also enhances the overall development workflow, contributing to a more efficient and error-free software development process. Explore other possibilities with GitHub Actions to streamline various aspects of your development lifecycle.