feat: update legal document translations and add new language support

- Replaced the existing legal document files with more specific ones for delivery, payment, and consumer rights.
- Added new legal documents related to data protection, including basic, customer, Google orders, newsletter, chatbot, cookies, and rights.
- Introduced Albanian language support in the translation files and language switcher component.
- Enhanced the translation functions to ensure structural files are copied correctly for new languages.
This commit is contained in:
sebseb7
2025-08-05 18:17:08 +02:00
parent 9f707737b4
commit c1d2205e6c
18 changed files with 290 additions and 162 deletions

View File

@@ -36,8 +36,16 @@ const TRANSLATION_FILES = [
// Legal document files that need special translation handling
const LEGAL_FILES = [
'legal-agb.js',
'legal-datenschutz.js',
'legal-agb-delivery.js',
'legal-agb-payment.js',
'legal-agb-consumer.js',
'legal-datenschutz-basic.js',
'legal-datenschutz-customer.js',
'legal-datenschutz-google-orders.js',
'legal-datenschutz-newsletter.js',
'legal-datenschutz-chatbot.js',
'legal-datenschutz-cookies-payment.js',
'legal-datenschutz-rights.js',
'legal-impressum.js',
'legal-widerruf.js',
'legal-batterie.js'
@@ -62,6 +70,7 @@ const TARGET_LANGUAGES = {
'ru': 'Russian',
'sk': 'Slovak',
'sl': 'Slovenian',
'sq': 'Albanian',
'sr': 'Serbian',
'sv': 'Swedish',
'tr': 'Turkish',
@@ -85,6 +94,7 @@ ro (Romanian) -> kSprache: 26
ru (Russian) -> kSprache: 16
sk (Slovak) -> kSprache: 18
sl (Slovenian) -> kSprache: 19
sq (Albanian) -> kSprache: 190
sr (Serbian) -> kSprache: 93
sv (Swedish) -> kSprache: 17
tr (Turkish) -> kSprache: 22
@@ -244,8 +254,6 @@ function getFilesNeedingEnglishTranslation() {
if (isSourceNewer(germanFile, englishFile)) {
filesToTranslate.push(fileName);
console.log(`📝 ${fileName} needs German → English translation`);
} else {
console.log(`⏭️ ${fileName} is up to date (German → English)`);
}
}
@@ -262,8 +270,6 @@ function getFilesNeedingEnglishTranslation() {
if (isSourceNewer(germanFile, englishFile)) {
filesToTranslate.push(fileName);
console.log(`📋 ${fileName} needs German → English legal translation`);
} else {
console.log(`⏭️ ${fileName} is up to date (German → English legal)`);
}
}
@@ -288,8 +294,6 @@ function getFilesNeedingTargetTranslation(langCode) {
if (isSourceNewer(englishFile, targetFile)) {
filesToTranslate.push(fileName);
console.log(`📝 ${fileName} needs English → ${langCode} translation`);
} else {
console.log(`⏭️ ${fileName} is up to date (English → ${langCode})`);
}
}
@@ -306,8 +310,6 @@ function getFilesNeedingTargetTranslation(langCode) {
if (isSourceNewer(englishFile, targetFile)) {
filesToTranslate.push(fileName);
console.log(`📋 ${fileName} needs English → ${langCode} legal translation`);
} else {
console.log(`⏭️ ${fileName} is up to date (English → ${langCode} legal)`);
}
}
@@ -439,6 +441,14 @@ async function translateToEnglish() {
console.log(`🔄 Translating ${filesToTranslate.length} files from German to English using ${GERMAN_TO_ENGLISH_MODEL}...`);
// Ensure English directory exists
if (!fs.existsSync(ENGLISH_DIR)) {
fs.mkdirSync(ENGLISH_DIR, { recursive: true });
}
// Copy structural files (index.js and translation.js) from German directory
copyStructuralFiles(ENGLISH_DIR, 'en');
const translatedFiles = [];
for (const fileName of filesToTranslate) {
@@ -497,6 +507,9 @@ async function translateToOtherLanguages(availableEnglishFiles) {
fs.mkdirSync(targetDir, { recursive: true });
}
// Copy structural files (index.js and translation.js) from German directory
copyStructuralFiles(targetDir, langCode);
const filesToTranslate = getFilesNeedingTargetTranslation(langCode);
if (filesToTranslate.length === 0) {
@@ -561,6 +574,30 @@ async function translateToOtherLanguages(availableEnglishFiles) {
}
}
// Function to copy index.js and translation.js files from German to target language
function copyStructuralFiles(targetDir, langCode) {
const filesToCopy = ['index.js', 'translation.js'];
for (const fileName of filesToCopy) {
const sourceFile = path.join(GERMAN_DIR, fileName);
const targetFile = path.join(targetDir, fileName);
// Only copy if source exists and target doesn't exist or is older
if (fs.existsSync(sourceFile)) {
if (!fs.existsSync(targetFile) || isSourceNewer(sourceFile, targetFile)) {
try {
fs.copyFileSync(sourceFile, targetFile);
console.log(`📋 Copied ${fileName} to ${langCode} directory`);
} catch (error) {
console.error(`❌ Error copying ${fileName} to ${langCode}:`, error.message);
}
}
} else {
console.warn(`⚠️ Source file not found: ${sourceFile}`);
}
}
}
// Helper function to get locale codes
function getLocaleCode(langCode) {
const localeCodes = {