Skip to content

Commit

Permalink
🐛 fix: Fix scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Oct 8, 2024
1 parent 4f11665 commit 945d18e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ import { join } from 'node:path';

import { config, readmeSplit } from './const';

export const normalizeLocale = (locale?: string): string => {
if (!locale) return 'en-US';

if (locale.startsWith('ar')) return 'ar';

if (locale.startsWith('cn')) return 'zh-CN';

for (const l of config.outputLocales) {
if (l.startsWith(locale)) {
return l;
}
}

return 'en-US';
};

export const writeJSON = (filePath, data, format = true) => {
const jsonStr = format ? JSON.stringify(data, null, 2) : JSON.stringify(data);
writeFileSync(filePath, jsonStr, 'utf8');
Expand All @@ -22,12 +38,14 @@ export const split = (name) => {
};

export const getLocaleAgentFileName = (id: string, locale?: string) => {
const localeSuffix = locale === config.entryLocale ? '' : `.${locale}`;
const formatedLocale = normalizeLocale(locale);
const localeSuffix = formatedLocale === config.entryLocale ? '' : `.${formatedLocale}`;
return join(id, 'index' + localeSuffix + '.json');
};

export const getBuildLocaleAgentFileName = (id: string, locale?: string) => {
const localeSuffix = locale === config.entryLocale ? '' : `.${locale}`;
const formatedLocale = normalizeLocale(locale);
const localeSuffix = formatedLocale === config.entryLocale ? '' : `.${formatedLocale}`;
return id + localeSuffix + '.json';
};

Expand Down

0 comments on commit 945d18e

Please sign in to comment.