Skip to content

Commit

Permalink
Fixed: Exclude base language when exporting localization strings
Browse files Browse the repository at this point in the history
  • Loading branch information
icodesign committed Dec 28, 2024
1 parent 121f08c commit 8fa6d81
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/base/src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ localizations:
id: 'text',
path: './translations',
format: LocalizationFormat.TEXT,
languages: ['en', 'es', 'fr'],
languages: ['es', 'fr'],
});

// Cleanup
Expand Down Expand Up @@ -262,5 +262,31 @@ localizations:
globalContext: 'This is a global context',
});
});

it('should exclude base language from languages array', async () => {
const configContent = `
baseLanguage: en
translator:
agent: openai
mode: automatic
localizations:
- id: text
path: ./translations
format: text
languages: ['en', 'es', 'fr', 'de']
`;

const config = await parseConfigText({
yamlText: configContent,
configPath: '/virtual/dolphin.yml',
});

expect(config.localizations[0]).toMatchObject({
id: 'text',
path: './translations',
format: LocalizationFormat.TEXT,
languages: ['es', 'fr', 'de'],
});
});
});
});
11 changes: 11 additions & 0 deletions packages/base/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ export async function parseConfigText({
throw new Error(`Invalid config file: ${validationError}`);
} else {
const config = result.data;
// exclude base language from languages array
const baseLanguage = config.baseLanguage;
config.localizations = config.localizations.map((localization) => {
// if has languages, exclude base language
if ('languages' in localization) {
localization.languages = localization.languages.filter(
(language) => language !== baseLanguage,
);
}
return localization;
});
await validateConfig(config);
return config;
}
Expand Down

0 comments on commit 8fa6d81

Please sign in to comment.