-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into fix/keyboard-command
- Loading branch information
Showing
219 changed files
with
6,926 additions
and
4,514 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Check Translation Changes | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "src/i18n/locales/en/translation.json" | ||
types: | ||
- opened | ||
- synchronize | ||
|
||
jobs: | ||
check_source_translation_file: | ||
name: Check source translation file for changes | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 # Fetch the base commit as well | ||
|
||
- uses: actions/setup-node@v3 | ||
|
||
- name: Check source translation file for 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" |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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, parentPath = "") { | ||
for (const key in obj1) { | ||
if (obj1.hasOwnProperty(key)) { | ||
if (typeof obj1[key] === "object" && typeof obj2[key] === "object") { | ||
compareObjects( | ||
obj1[key], | ||
obj2[key], | ||
parentPath ? `${parentPath}.${key}` : key | ||
); | ||
} else if (obj1[key] !== obj2[key] && obj2[key] !== undefined) { | ||
const title = `Translation source ${parentPath}.${key} has changed`; | ||
const message = `Consider running \`node scripts/remove-outdated-translations.js ${parentPath}.${key}\` to reset existing translations.`; | ||
console.log( | ||
`::warning file=src/i18n/locales/en/translation.json,line=1,title=${title}::${message}` | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
compareObjects(previousData, currentData); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const fs = require("fs"); | ||
const glob = require("glob"); | ||
const path = require("path"); | ||
|
||
const keyToUpdate = process.argv[2]; // Get the key to update from command line argument | ||
|
||
if (!keyToUpdate) { | ||
console.error("Please provide the key to update as a command line argument."); | ||
process.exit(1); | ||
} | ||
|
||
function deleteKey(obj, nestedKey) { | ||
const keys = nestedKey.split("."); | ||
let currentObj = obj; | ||
let foundAndUpdated = false; | ||
|
||
for (let i = 0; i < keys.length; i++) { | ||
const key = keys[i]; | ||
|
||
if (i === keys.length - 1 && currentObj.hasOwnProperty(key)) { | ||
delete currentObj[key]; | ||
foundAndUpdated = true; | ||
} else if ( | ||
currentObj.hasOwnProperty(key) && | ||
typeof currentObj[key] === "object" | ||
) { | ||
currentObj = currentObj[key]; | ||
} else { | ||
// Key doesn't exist, break out of loop | ||
break; | ||
} | ||
} | ||
|
||
return foundAndUpdated; | ||
} | ||
|
||
const startDirectory = path.join(__dirname, "..", "src", "i18n", "locales"); | ||
|
||
// Use glob to find files matching the pattern | ||
const filesPattern = path.join(startDirectory, "**", "translation.json"); | ||
glob(filesPattern, (err, files) => { | ||
if (err) { | ||
console.error("Error while searching for files:", err); | ||
process.exit(1); | ||
} | ||
|
||
files.forEach((filePath) => { | ||
const isEnglishFile = filePath.includes(path.sep + "en" + path.sep); // Assuming 'en' is the English folder | ||
if (isEnglishFile) return; | ||
|
||
try { | ||
const data = fs.readFileSync(filePath, "utf8"); | ||
const jsonData = JSON.parse(data); | ||
|
||
const language = filePath | ||
.split(path.sep + "locales" + path.sep)[1] | ||
.split(path.sep)[0]; | ||
|
||
if (deleteKey(jsonData, keyToUpdate)) { | ||
fs.writeFileSync(filePath, JSON.stringify(jsonData, null, 2)); | ||
console.log(`✅ ${language}`); | ||
} | ||
} catch (error) { | ||
console.error(`Error processing ${filePath}: ${error}`); | ||
} | ||
}); | ||
}); |
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
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
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
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
Oops, something went wrong.