Skip to content

Commit

Permalink
Fixed: exclude base language when exporting localization strings (#10)
Browse files Browse the repository at this point in the history
Resolved #5
  • Loading branch information
icodesign authored Dec 28, 2024
1 parent 121f08c commit ef203f0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fresh-apricots-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rootapp/dolphin': patch
---

Exclude base language when exporting localization strings
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 ef203f0

Please sign in to comment.