Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
1ca1ce3
Review: Initial translations for Japanese and Spanish
viv-cheung Apr 28, 2025
76c520f
update package
viv-cheung Apr 28, 2025
de226ad
update package
viv-cheung Apr 28, 2025
cba13f7
update package
viv-cheung Apr 28, 2025
044426b
detect branch
viv-cheung Apr 28, 2025
e275128
update node version
viv-cheung Apr 28, 2025
da46e96
edit docs
viv-cheung Apr 28, 2025
ab2ad96
testing actions
viv-cheung Apr 29, 2025
81b2608
update configuration import
viv-cheung Apr 29, 2025
041b929
update configuration import
viv-cheung Apr 29, 2025
15d376e
update configuration import
viv-cheung Apr 29, 2025
bddccb5
update
viv-cheung Apr 29, 2025
453b098
update package json
viv-cheung Apr 29, 2025
00f783b
update file name
viv-cheung Apr 29, 2025
ca774d7
chore(i18n): update translations [en]
github-actions[bot] Apr 29, 2025
8489be1
test
viv-cheung Apr 29, 2025
b539113
Merge branch 'custom-github-action' of github.com:viv-cheung/sequence…
viv-cheung Apr 29, 2025
7b9f264
update permissions
viv-cheung Apr 29, 2025
21d0ecf
update permissions
viv-cheung Apr 29, 2025
925d310
update permissions
viv-cheung Apr 29, 2025
6666fc8
test translations
viv-cheung Apr 29, 2025
4f009bd
chore(i18n): update translations [en]
github-actions[bot] Apr 29, 2025
4c1525e
update github action workflow
viv-cheung Apr 30, 2025
9fe6eef
Test edit
PhABC May 1, 2025
101566d
Only translate essentials
PhABC May 1, 2025
843765a
edit essentials
PhABC May 1, 2025
58b2f15
edit essentials
PhABC May 1, 2025
f05ef58
chore(i18n): update translations [en]
github-actions[bot] May 1, 2025
beb93cf
edit essentials
PhABC May 1, 2025
cc37a25
Merge branch 'custom-github-action' of https://github.com/viv-cheung/…
PhABC May 1, 2025
f62fa83
edit essentials
PhABC May 1, 2025
8b4480f
chore(i18n): update translations [en]
github-actions[bot] May 1, 2025
4a9f9e0
test frenglish
viv-cheung May 2, 2025
62bb0a7
chore(i18n): update translations [en]
github-actions[bot] May 2, 2025
5bb6a1a
update github action
viv-cheung May 2, 2025
1c285fe
Merge branch 'custom-github-action' of github.com:viv-cheung/sequence…
viv-cheung May 2, 2025
1f0ebe7
update get branch
viv-cheung May 2, 2025
fc2a2c6
update get branch
viv-cheung May 2, 2025
40c50a1
chore(i18n): update translations [en]
github-actions[bot] May 2, 2025
2008d39
update translation
viv-cheung May 2, 2025
f0158c5
Merge branch 'custom-github-action' of github.com:viv-cheung/sequence…
viv-cheung May 2, 2025
ee2bf90
chore(i18n): update translations [en]
github-actions[bot] May 2, 2025
41005fc
Test edit
viv-cheung May 4, 2025
2e2a685
Test 2
viv-cheung May 4, 2025
b512afe
chore(i18n): update translations [en]
github-actions[bot] May 4, 2025
cf98554
test 3
viv-cheung May 4, 2025
bea7567
Merge branch 'custom-github-action' of github.com:viv-cheung/sequence…
viv-cheung May 4, 2025
82580e0
chore(i18n): update translations [en]
github-actions[bot] May 4, 2025
9627c29
update
viv-cheung May 4, 2025
e8a6320
wip
viv-cheung May 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# prod
#FRENGLISH_API_KEY = $2b$10$sWXauOt1hTqnoDSiTaPc3.XzC1OFUww.qydrD4r2ZbwqtvhpH5pw.
#dev
FRENGLISH_API_KEY = $2b$10$kXXCMKtfGx/9spX3yvnhTuBNAAMpGvwtlfNVQAc/nTlNO6KMS4uqe
68 changes: 68 additions & 0 deletions .github/scripts/fetch-frenglish-configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// .github/scripts/fetch-frenglish-translation.js
// Import the 'fs' module for file system operations
const fs = require('fs');

// Use dynamic import
(async () => {
const { FrenglishSDK } = await import('@frenglish/sdk');

async function fetchConfigAndSetOutputs() {
const apiKey = process.env.FRENGLISH_API_KEY;

if (!apiKey) {
console.error('::error::FRENGLISH_API_KEY secret is not set.');
process.exit(1);
}

// Check if GITHUB_OUTPUT path is available
if (!process.env.GITHUB_OUTPUT) {
console.error('::error::GITHUB_OUTPUT environment variable is not set. Are you running this script in GitHub Actions?');
process.exit(1);
}

try {
console.log('Initializing Frenglish SDK...');
const frenglish = FrenglishSDK(apiKey); // Assuming this is correct based on your usage

console.log('Fetching default configuration from Frenglish SDK instance...');
const config = await frenglish.getDefaultConfiguration();

if (!config || !config.originLanguage || !config.languages || !Array.isArray(config.languages)) {
console.error(`::error::Failed to retrieve a valid configuration object from SDK. Received: ${JSON.stringify(config)}`);
process.exit(1);
}

const originLanguage = config.originLanguage;
const targetLanguages = config.languages; // Assuming 'languages' contains ALL languages including origin

// It's safer to check if originLanguage is actually in the languages array before filtering
const actualTargetLanguages = targetLanguages.filter(lang => lang !== originLanguage);

if (actualTargetLanguages.length === 0) {
console.warn('::warning::No target languages found in the configuration after filtering out the origin language.');
}

const targetLangsString = actualTargetLanguages.join(' '); // Create space-separated string

console.log(`Source Language Determined: ${originLanguage}`);
console.log(`Target Languages Determined: ${targetLangsString}`);

// --- Use GITHUB_OUTPUT to set outputs ---
// Write outputs to the file specified by GITHUB_OUTPUT
fs.appendFileSync(process.env.GITHUB_OUTPUT, `source_lang=${originLanguage}\n`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `target_langs=${targetLangsString}\n`);
// --- End of GITHUB_OUTPUT usage ---

console.log('Outputs set successfully.');

} catch (error) {
console.error(`::error::Error during Frenglish configuration fetch: ${error.message}`);
process.exit(1);
}
}

await fetchConfigAndSetOutputs();
})().catch(error => {
console.error('::error::Fatal error executing script:', error);
process.exit(1);
});
109 changes: 109 additions & 0 deletions .github/scripts/format-locales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path"); // Import path module

const LOCALES_DIR = "."; // Root directory to start search
const EXCLUDE_DIR = path.resolve(LOCALES_DIR, "node_modules"); // Absolute path to node_modules

function formatJsonFile(filePath) {
try {
console.log(`Formatting ${filePath}...`);

// Read the file
const content = fs.readFileSync(filePath, "utf-8");

// Parse and reformat the JSON
// Ensure content is not empty before parsing
if (content.trim() === "") {
console.warn(`✓ Skipping empty file: ${filePath}`);
return true; // Treat empty files as success (nothing to format)
}

const parsedJson = JSON.parse(content);

// Sort keys - handle non-object JSON (e.g., arrays, primitives)
let formattedContent;
if (typeof parsedJson === 'object' && parsedJson !== null && !Array.isArray(parsedJson)) {
// Sort keys only for non-null, non-array objects
const sortedKeys = Object.keys(parsedJson).sort();
const sortedJson = {};
sortedKeys.forEach(key => {
sortedJson[key] = parsedJson[key];
});
formattedContent = JSON.stringify(sortedJson, null, 2);
} else {
// For arrays or primitives, just stringify with indentation
formattedContent = JSON.stringify(parsedJson, null, 2);
}


// Write the formatted content back to the file
// Add newline at the end for POSIX compatibility
fs.writeFileSync(filePath, formattedContent + "\n", "utf-8");

console.log(`✓ Formatted ${filePath}`);
return true;
} catch (error) {
// Provide more context on parsing errors
console.error(`✗ Failed to format ${filePath}: ${error.name} - ${error.message}`);
// Optionally log a snippet of the file around the error if possible/needed
return false;
}
}

function formatAllLocalesFiles() {
try {
// Find all JSON files recursively starting from LOCALES_DIR
const command = `find ${LOCALES_DIR} -type f -name "*.json"`;
console.log(`Running command: ${command}`);
const output = execSync(command).toString().trim();
const allFiles = output.split("\n").filter(Boolean);

// Filter out files within the node_modules directory
const filesToFormat = allFiles.filter((filePath) => {
const absoluteFilePath = path.resolve(filePath);
// Check if the file path starts with the node_modules path
return !absoluteFilePath.startsWith(EXCLUDE_DIR + path.sep) && // Exclude files *inside* node_modules
absoluteFilePath !== EXCLUDE_DIR; // Exclude node_modules itself if it were a file somehow
});

console.log(`Found ${allFiles.length} total JSON files.`);
console.log(`Excluded ${allFiles.length - filesToFormat.length} files within node_modules.`);
console.log("Files to format:", filesToFormat);

if (filesToFormat.length === 0) {
return []; // Return empty array if no files left after filtering
}

return filesToFormat.map(formatJsonFile);
} catch (error) {
// Handle errors from the 'find' command itself
console.error("Error finding JSON files:", error.message);
if (error.stderr) {
console.error("Find command stderr:", error.stderr.toString());
}
return [];
}
}

function main() {
const results = formatAllLocalesFiles(); // results is now an array of booleans (true for success, false for failure)

if (results.length === 0) {
console.log("No relevant JSON files found or processed. Nothing to format.");
// Decide if this should be an error or not; exiting 0 is fine if it's expected
process.exit(0);
}

// Count failures
const failedCount = results.filter((success) => !success).length;

if (failedCount > 0) {
console.error(`\nFormatting complete, but failed for ${failedCount} file(s). See logs above.`);
process.exit(1); // Exit with error code if any file failed
}

console.log("\nAll relevant JSON files formatted successfully!");
}

main();
Loading
Loading