Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: audiobookshelf/audiobookshelf-i18n-updater
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.0
Choose a base ref
...
head repository: audiobookshelf/audiobookshelf-i18n-updater
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Mar 20, 2024

  1. Update packaged build file

    nichwall committed Mar 20, 2024
    Copy the full SHA
    e41c982 View commit details

Commits on Apr 11, 2024

  1. Copy the full SHA
    90af59d View commit details

Commits on Jun 11, 2024

  1. Copy the full SHA
    c964713 View commit details
  2. Copy the full SHA
    f827a93 View commit details
Showing with 34 additions and 24 deletions.
  1. +1 −0 README.md
  2. +12 −1 copy_keys.js
  3. +20 −22 dist/index.js
  4. +1 −1 package.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ with:
## Example Integration Workflow
This workflow can be used to validate that all language files are alphabetized.
Any language file being out of order will cause the workflow to throw an error.
The workflow will also throw an error if any keys exists in a language file and do not exist in the base file.
```yaml
name: Verify all i18n files are alphabetized

13 changes: 12 additions & 1 deletion copy_keys.js
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ function saveJSONFile(filePath, data) {
}

function updateJSONFiles(baseFileName, directory) {
/*
const baseFilePath = path.join(directory, baseFileName);
const baseData = loadJSONFile(baseFilePath);
@@ -22,6 +23,7 @@ function updateJSONFiles(baseFileName, directory) {
.forEach(key => {
sortedBaseData[key] = baseData[key];
});
*/

fs.readdirSync(directory).forEach(filename => {
const filePath = path.join(directory, filename);
@@ -31,14 +33,22 @@ function updateJSONFiles(baseFileName, directory) {
// Check if keys are in alphabetical order
const keys = Object.keys(otherData);
for (let i = 1; i < keys.length; i++) {
if (keys[i].toLowerCase() < keys[i - 1].toLowerCase()) {
if (keys[i] < keys[i - 1]) {
throw new Error('Keys are not alphabetized in ' + filename);
}
}
}
/*
if (filename.endsWith('.json') && filename !== baseFileName) {
let otherData = loadJSONFile(filePath);
// Check if there are keys in another langague that are not in the base English file
for (const key in otherData) {
if (!(key in sortedBaseData)) {
throw new Error(`Key '${key}' found in '${filename}' but not in '${baseFileName}' file`);
}
}
// Copy missing fields from the base data
for (const key in sortedBaseData) {
if (!(key in otherData)) {
@@ -57,6 +67,7 @@ function updateJSONFiles(baseFileName, directory) {
saveJSONFile(filePath, sortedOtherData);
}
*/
});

}
42 changes: 20 additions & 22 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -26605,20 +26605,18 @@ function saveJSONFile(filePath, data) {
}

function updateJSONFiles(baseFileName, directory) {
/*
const baseFilePath = path.join(directory, baseFileName);
const baseData = loadJSONFile(baseFilePath);

let isSorted = true;

console.log("In updateJSONFiles");

// Sort the base data alphabetically by key (case insensitive)
const sortedBaseData = {};
Object.keys(baseData)
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
.forEach(key => {
sortedBaseData[key] = baseData[key];
});
*/

fs.readdirSync(directory).forEach(filename => {
const filePath = path.join(directory, filename);
@@ -26628,18 +26626,26 @@ function updateJSONFiles(baseFileName, directory) {
// Check if keys are in alphabetical order
const keys = Object.keys(otherData);
for (let i = 1; i < keys.length; i++) {
if (keys[i].toLowerCase() < keys[i - 1].toLowerCase()) {
isSorted = false;
break;
if (keys[i] < keys[i - 1]) {
throw new Error('Keys are not alphabetized in ' + filename);
}
}
}
/*
if (filename.endsWith('.json') && filename !== baseFileName) {
let otherData = loadJSONFile(filePath);

// Check if there are keys in another langague that are not in the base English file
for (const key in otherData) {
if (!(key in sortedBaseData)) {
throw new Error(`Key '${key}' found in '${filename}' but not in '${baseFileName}' file`);
}
}

// Copy missing fields from the base data
for (const key in sortedBaseData) {
if (!(key in otherData)) {
console.log(`Copying key '${key}' to '${filename}'`);
otherData[key] = sortedBaseData[key];
}
}
@@ -26654,27 +26660,19 @@ function updateJSONFiles(baseFileName, directory) {

saveJSONFile(filePath, sortedOtherData);
}
*/
});

if (!isSorted) {
return 1; // Keys not in alphabetical order
} else {
return 0; // All files are in alphabetical order
}
}

const directory = core.getInput('directory');

console.log("Printing the directory");
console.log(directory);

const resultCode = updateJSONFiles(`en-us.json`, directory);
console.log("Result Code: ", resultCode);

// Check if keys were not in alphabetical order
if (resultCode == 1) {
console.log("Files are not alphabetized");
core.setFailed('Keys are not alphabetized');
try {
updateJSONFiles(`en-us.json`, directory);
console.log("All files in alphabetical order");
} catch (error) {
console.error(error.message);
core.setFailed(error.message);
}

})();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "audiobookshelf-i18n-updater",
"version": "1.0.0",
"version": "1.3.0",
"description": "A GitHub action that validates the localization files are alphabetized and copies any missing keys from the English file",
"main": "index.js",
"scripts": {