Skip to content

Commit

Permalink
Make executable path compatible with Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
danyeaw committed Jan 28, 2025
1 parent c4bc347 commit 90252cf
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tools/build-translations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// scripts/build-translations.js
const { spawn } = require('child_process');
const path = require('path');

Expand All @@ -9,13 +10,25 @@ const translations = [
{ locale: 'zh_CN' }
];

// Get the correct po2json executable path based on platform
const getPo2JsonPath = () => {
const isWindows = process.platform === 'win32';
return path.join(
process.cwd(),
'node_modules',
'.bin',
`po2json${isWindows ? '.cmd' : ''}`
);
};

async function buildTranslation(locale) {
const baseDir = path.join('nbclassic', 'i18n', locale, 'LC_MESSAGES');
const poFile = path.join(baseDir, 'nbjs.po');
const jsonFile = path.join(baseDir, 'nbjs.json');

return new Promise((resolve, reject) => {
const process = spawn('po2json', [
const po2jsonPath = getPo2JsonPath();
const process = spawn(po2jsonPath, [
'-p', // pretty print
'-F', // force overwrite
'-f', 'jed1.x', // format
Expand All @@ -32,12 +45,17 @@ async function buildTranslation(locale) {
console.error(`${locale} error: ${data}`);
});

process.on('error', (err) => {
console.error(`Failed to start po2json for ${locale}:`, err);
reject(err);
});

process.on('close', (code) => {
if (code === 0) {
console.log(`✓ Built translation for ${locale}`);
resolve();
} else {
reject(new Error(`Failed to build translation for ${locale}`));
reject(new Error(`Failed to build translation for ${locale} with code ${code}`));
}
});
});
Expand Down

0 comments on commit 90252cf

Please sign in to comment.