Skip to content

Commit

Permalink
✨ feat: Update i18n config
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Mar 24, 2024
1 parent c025ceb commit dded0e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
31 changes: 25 additions & 6 deletions packages/lobe-i18n/src/commands/TranslateMarkdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ class TranslateMarkdown {
if (!entry || entry.length === 0) alert.error('No markdown entry was found.', true);

let files = globSync(matchInputPattern(entry, '.md'), {
ignore: matchInputPattern(this.markdownConfig.exclude || [], '.md'),
ignore: this.markdownConfig.exclude
? matchInputPattern(this.markdownConfig.exclude || [], '.md')
: undefined,
nodir: true,
}).filter((file) => file.includes(this.markdownConfig.entryExtension || '.md'));
});

if (this.markdownConfig.entryExtension)
files = files.filter((file) => file.includes(this.markdownConfig.entryExtension || '.md'));

if (!files || files.length === 0) alert.error('No markdown entry was found.', true);

Expand Down Expand Up @@ -141,10 +146,24 @@ class TranslateMarkdown {
}

private getTargetFilename(filePath: string, targetExtension: string) {
return resolve(
'.',
filePath.replace(this.markdownConfig.entryExtension || '.md', targetExtension),
);
if (this.markdownConfig.entryExtension) {
return resolve(
'.',
filePath.replace(this.markdownConfig.entryExtension || '.md', targetExtension),
);
} else {
if (
this.markdownConfig.entryLocale &&
filePath.includes(`.${this.markdownConfig.entryLocale}.`)
) {
const filePaths = filePath.split(`.${this.markdownConfig.entryLocale}.`) as string[];
return [filePaths[0], targetExtension].join('');
} else {
const filePaths = filePath.split('.');
filePaths.pop();
return [filePaths.join('.'), targetExtension].join('');
}
}
}

private getMode(filePath: string, fileContent: string) {
Expand Down
1 change: 0 additions & 1 deletion packages/lobe-i18n/src/store/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const DEFAULT_CONFIG: Partial<I18nConfig> = {
concurrency: 5,
markdown: {
entry: [],
entryExtension: '.md',
mode: MarkdownModeType.STRING,
outputExtensions: getDefaultExtension,
},
Expand Down

0 comments on commit dded0e0

Please sign in to comment.