Skip to content

Commit

Permalink
fix: add gh action
Browse files Browse the repository at this point in the history
  • Loading branch information
reneaaron committed Aug 31, 2023
1 parent 66066ed commit 92d41e1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/translations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Check Translation Changes

on:
pull_request:
paths:
- "src/i18n/locales/en/translation.json"
types:
- opened
- synchronize

jobs:
check_translation_changes:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 2 # Fetch the base commit as well

- uses: actions/setup-node@v3

- name: Check for Translation Changes
run: |
file_path="src/i18n/locales/en/translation.json"
branch_name=${{ github.base_ref }}
url="https://api.github.com/repos/${{ github.repository }}/contents/${file_path}?ref=${branch_name}"
BASE_CONTENT=$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $url | jq -c -r .content | base64 -d | jq -c .)
node scripts/check-changed-translations.js "$BASE_CONTENT"
29 changes: 29 additions & 0 deletions scripts/check-changed-translations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fs = require("fs");

const previousData = JSON.parse(process.argv[2]);

const currentContent = fs.readFileSync(
"src/i18n/locales/en/translation.json",
"utf8"
);

const currentData = JSON.parse(currentContent);

function compareObjects(obj1, obj2) {
for (const key in obj1) {
if (obj1.hasOwnProperty(key)) {
if (typeof obj1[key] === "object" && typeof obj2[key] === "object") {
compareObjects(obj1[key], obj2[key]);
} else if (obj1[key] !== obj2[key]) {
console.warn(`Value of key "${key}" has changed:`);
console.log(`Previous: ${obj1[key]}`);
console.log(`Current: ${obj2[key]}`);
console.log(
"::error file=src/i18n/locales/en/translation.json,line=1::TEST"
);
}
}
}
}

compareObjects(previousData, currentData);

0 comments on commit 92d41e1

Please sign in to comment.