lobe-chat

Форк
0
54 строки · 1.8 Кб
1
import { consola } from 'consola';
2
import { colors } from 'consola/utils';
3
import { readFileSync, writeFileSync } from 'node:fs';
4
import { resolve } from 'node:path';
5

6
import i18nConfig from '../../.i18nrc';
7

8
export const readJSON = (filePath: string) => {
9
  const data = readFileSync(filePath, 'utf8');
10
  return JSON.parse(data);
11
};
12

13
export const writeJSON = (filePath: string, data: any) => {
14
  const jsonStr = JSON.stringify(data, null, 2);
15
  writeFileSync(filePath, jsonStr, 'utf8');
16
};
17

18
export const genResourcesContent = (locales: string[]) => {
19
  let index = '';
20
  let indexObj = '';
21

22
  for (const locale of locales) {
23
    index += `import ${locale} from "./${locale}";\n`;
24
    indexObj += `   "${locale.replace('_', '-')}": ${locale},\n`;
25
  }
26

27
  return `${index}
28
const resources = {
29
${indexObj}} as const;
30
export default resources;
31
export const defaultResources = ${i18nConfig.entryLocale};
32
export type Resources = typeof resources;
33
export type DefaultResources = typeof defaultResources;
34
export type Namespaces = keyof DefaultResources;
35
export type Locales = keyof Resources;
36
`;
37
};
38

39
export const genNamespaceList = (files: string[], locale: string) => {
40
  return files.map((file) => ({
41
    name: file.replace('.json', ''),
42
    path: resolve(i18nConfig.output, locale, file),
43
  }));
44
};
45

46
export const tagBlue = (text: string) => colors.bgBlueBright(colors.black(` ${text} `));
47
export const tagYellow = (text: string) => colors.bgYellowBright(colors.black(` ${text} `));
48
export const tagGreen = (text: string) => colors.bgGreenBright(colors.black(` ${text} `));
49
export const tagWhite = (text: string) => colors.bgWhiteBright(colors.black(` ${text} `));
50

51
export const split = (name: string) => {
52
  consola.log('');
53
  consola.log(colors.gray(`========================== ${name} ==============================`));
54
};
55

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.