mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 08:20:14 +01:00
🪟 fix: Windows Build (npm) (#3889)
* chore: package-lock.json * chore: remove shadcn files (temp) * refactor: language comparisons script * fix: resolve package-lock file for windows compatibility * chore: Enable Windows unit tests for frontend * refactor: move shadcn components to data-provider
This commit is contained in:
parent
136599081c
commit
9ec665dd2c
7 changed files with 15089 additions and 15207 deletions
|
|
@ -2,8 +2,7 @@ import fs from 'fs';
|
|||
import path from 'path';
|
||||
import { exec } from 'child_process';
|
||||
|
||||
async function main(baseFilePath: string, languagesDir: string) {
|
||||
const { default: baseLanguage } = await import(path.resolve(baseFilePath));
|
||||
async function main(languagesDir: string) {
|
||||
const files = fs.readdirSync(languagesDir);
|
||||
|
||||
for (const file of files) {
|
||||
|
|
@ -13,41 +12,22 @@ async function main(baseFilePath: string, languagesDir: string) {
|
|||
}
|
||||
|
||||
const filePath = path.resolve(languagesDir, file);
|
||||
if (filePath === baseFilePath) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const { default: otherLanguage } = await import(filePath);
|
||||
const comparisons = {};
|
||||
|
||||
for (const key in otherLanguage) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(otherLanguage, key) &&
|
||||
Object.prototype.hasOwnProperty.call(baseLanguage, key)
|
||||
) {
|
||||
comparisons[key] = {
|
||||
english: baseLanguage[key],
|
||||
translated: otherLanguage[key],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let fileContent = fs.readFileSync(filePath, 'utf8');
|
||||
const comparisonsObjRegex = /export const comparisons = {[\s\S]*?};/gm;
|
||||
const hasComparisons = comparisonsObjRegex.test(fileContent);
|
||||
const comparisonsExport = `\nexport const comparisons = ${JSON.stringify(
|
||||
comparisons,
|
||||
null,
|
||||
2,
|
||||
)};\n`;
|
||||
|
||||
if (hasComparisons) {
|
||||
fileContent = fileContent.replace(comparisonsObjRegex, comparisonsExport);
|
||||
if (comparisonsObjRegex.test(fileContent)) {
|
||||
// Remove the comparisons object
|
||||
fileContent = fileContent.replace(comparisonsObjRegex, '');
|
||||
|
||||
// Remove any empty lines at the end of the file
|
||||
fileContent = fileContent.trim() + '\n';
|
||||
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
console.log(`Removed comparisons from ${file}`);
|
||||
} else {
|
||||
fileContent = fileContent.trim() + comparisonsExport;
|
||||
console.log(`No comparisons found in ${file}`);
|
||||
}
|
||||
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
||||
|
||||
// Execute ESLint with the --fix option on the entire directory
|
||||
|
|
@ -65,17 +45,5 @@ async function main(baseFilePath: string, languagesDir: string) {
|
|||
}
|
||||
|
||||
const languagesDir = './client/src/localization/languages';
|
||||
const baseFilePath = path.resolve(languagesDir, 'Eng.ts');
|
||||
|
||||
main(baseFilePath, languagesDir).catch(console.error);
|
||||
|
||||
// const prompt = `
|
||||
|
||||
// Write a prompt that is mindful of the nuances in the language with respect to its English counterpart, which serves as the baseline for translations. Here are the comparisons between the language translations and their English counterparts:
|
||||
|
||||
// ${comparisons}
|
||||
|
||||
// Please consider the above comparisons to enhance understanding and guide improvements in translations. Provide insights or suggestions that could help refine the translation process, focusing on cultural and contextual relevance.
|
||||
|
||||
// Please craft a prompt that can be used to better inform future translations to this language. Write this prompt in the translated language, with all its nuances detected, not in the English.
|
||||
// `;
|
||||
main(languagesDir).catch(console.error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue