merge translations (based part)

This commit is contained in:
piuvas 2024-10-07 20:38:42 -03:00
parent 5145afb625
commit 6f7c0c2de3
No known key found for this signature in database
GPG Key ID: 82743F52454C621D
3 changed files with 1031 additions and 769 deletions

View File

@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path'; import { dirname } from 'node:path';
import * as yaml from 'js-yaml'; import * as yaml from 'js-yaml';
import ts from 'typescript'; import ts from 'typescript';
import { merge } from './index.js';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
@ -56,7 +57,10 @@ function createMembers(record) {
} }
export default function generateDTS() { export default function generateDTS() {
const locale = yaml.load(fs.readFileSync(`${__dirname}/ja-JP.yml`, 'utf-8')); const sharkeyLocale = yaml.load(fs.readFileSync(`${__dirname}/../sharkey-locales/ja-JP.yml`, 'utf-8'));
const misskeyLocale = yaml.load(fs.readFileSync(`${__dirname}/ja-JP.yml`, 'utf-8'));
const locale = merge(misskeyLocale, sharkeyLocale);
const members = createMembers(locale); const members = createMembers(locale);
const elements = [ const elements = [
ts.factory.createVariableStatement( ts.factory.createVariableStatement(

1787
locales/index.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
import * as fs from 'node:fs'; import * as fs from 'node:fs';
import * as yaml from 'js-yaml'; import * as yaml from 'js-yaml';
const merge = (...args) => args.reduce((a, c) => ({ export const merge = (...args) => args.reduce((a, c) => ({
...a, ...a,
...c, ...c,
...Object.entries(a) ...Object.entries(a)
@ -60,7 +60,10 @@ export function build() {
// https://github.com/vitest-dev/vitest/issues/3988#issuecomment-1686599577 // https://github.com/vitest-dev/vitest/issues/3988#issuecomment-1686599577
// https://github.com/misskey-dev/misskey/pull/14057#issuecomment-2192833785 // https://github.com/misskey-dev/misskey/pull/14057#issuecomment-2192833785
const metaUrl = import.meta.url; const metaUrl = import.meta.url;
const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(new URL(`${c}.yml`, metaUrl), 'utf-8'))) || {}, a), {}); const sharkeyLocales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(new URL(`../sharkey-locales/${c}.yml`, metaUrl), 'utf-8'))) || {}, a), {});
const misskeyLocales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(new URL(`${c}.yml`, metaUrl), 'utf-8'))) || {}, a), {});
// merge sharkey and misskey's locales. the second argument (sharkey) overwrites the first argument (misskey).
const locales = merge(misskeyLocales, sharkeyLocales);
// 空文字列が入ることがあり、フォールバックが動作しなくなるのでプロパティごと消す // 空文字列が入ることがあり、フォールバックが動作しなくなるのでプロパティごと消す
const removeEmpty = (obj) => { const removeEmpty = (obj) => {