Pure build version of locales. No "src", no "dist"; just the locale files and instructions on building them.
This commit is contained in:
parent
a241ef03cb
commit
058cdc5180
|
@ -1,8 +1,4 @@
|
||||||
# don't ever lint node_modules
|
# don't ever lint node_modules
|
||||||
node_modules
|
node_modules
|
||||||
# don't lint build output (make sure it's set to your correct build folder name)
|
# don't lint build output (make sure it's set to your correct build folder name)
|
||||||
dist
|
|
||||||
# don't lint nyc coverage output
|
# don't lint nyc coverage output
|
||||||
coverage
|
|
||||||
src/locale-codes.ts
|
|
||||||
storybook-static/
|
|
||||||
|
|
|
@ -112,3 +112,4 @@ storybook-static/
|
||||||
scripts/*.mjs
|
scripts/*.mjs
|
||||||
scripts/*.js
|
scripts/*.js
|
||||||
src/locale-codes.js
|
src/locale-codes.js
|
||||||
|
src
|
||||||
|
|
|
@ -6,12 +6,13 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./src/locale-codes.js",
|
"main": "./src/locale-codes.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "run-s build-locales fix:lint compile fix:prettier",
|
"build": "run-s build-locales compile fix:lint fix:prettier",
|
||||||
"build-locales": "lit-localize build",
|
"build-locales": "lit-localize build",
|
||||||
"compile": "node ./build.mjs",
|
"compile": "node ./build.mjs",
|
||||||
|
"clean": "rimraf src dist scripts/*.mjs",
|
||||||
"extract-locales": "run-p localization:extract localization:pseudolocalize",
|
"extract-locales": "run-p localization:extract localization:pseudolocalize",
|
||||||
"lint:lint": "eslint . --max-warnings 0",
|
"lint:lint": "eslint . --max-warnings 0",
|
||||||
"fix:lint": "eslint . --max-warnings 0 --fix",
|
"fix:lint": "eslint . --max-warnings 0 --fix dist/locale-codes.js",
|
||||||
"fix:prettier": "prettier --write ./src/**/* ./package.json ./lit-localize.json",
|
"fix:prettier": "prettier --write ./src/**/* ./package.json ./lit-localize.json",
|
||||||
"lint:prettier": "prettier ./src/**/* ./package.json ./lit-localize.json",
|
"lint:prettier": "prettier ./src/**/* ./package.json ./lit-localize.json",
|
||||||
"localization:extract": "lit-localize extract",
|
"localization:extract": "lit-localize extract",
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync, writeFileSync } from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import pseudolocale from "pseudolocale";
|
import pseudolocale from "pseudolocale";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
import { makeFormatter } from "@lit/localize-tools/lib/formatters/index.js";
|
import { makeFormatter } from "@lit/localize-tools/lib/formatters/index.js";
|
||||||
import type { Message, ProgramMessage } from "@lit/localize-tools/lib/messages.d.ts";
|
import type { Message, Placeholder, ProgramMessage } from "@lit/localize-tools/lib/messages.d.ts";
|
||||||
import { sortProgramMessages } from "@lit/localize-tools/lib/messages.js";
|
import { sortProgramMessages } from "@lit/localize-tools/lib/messages.js";
|
||||||
import { TransformLitLocalizer } from "@lit/localize-tools/lib/modes/transform.js";
|
import { TransformLitLocalizer } from "@lit/localize-tools/lib/modes/transform.js";
|
||||||
import type { Config } from "@lit/localize-tools/lib/types/config.d.ts";
|
import type { Config } from "@lit/localize-tools/lib/types/config.d.ts";
|
||||||
|
@ -14,7 +14,7 @@ import type { TransformOutputConfig } from "@lit/localize-tools/lib/types/modes.
|
||||||
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||||
const pseudoLocale: Locale = "pseudo-LOCALE" as Locale;
|
const pseudoLocale: Locale = "pseudo-LOCALE" as Locale;
|
||||||
const targetLocales: Locale[] = [pseudoLocale];
|
const targetLocales: Locale[] = [pseudoLocale];
|
||||||
const baseConfig = JSON.parse(readFileSync(path.join(__dirname, "../lit-localize.json"), "utf-8"));
|
const baseConfig = JSON.parse(readFileSync(path.join(__dirname, "../lit-localize.json"), "utf8"));
|
||||||
|
|
||||||
// Need to make some internal specifications to satisfy the transformer. It doesn't actually matter
|
// Need to make some internal specifications to satisfy the transformer. It doesn't actually matter
|
||||||
// which Localizer we use (transformer or runtime), because all of the functionality we care about
|
// which Localizer we use (transformer or runtime), because all of the functionality we care about
|
||||||
|
@ -39,9 +39,61 @@ const pseudoMessagify = (message: ProgramMessage) => ({
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
type Translation = { name: string, contents: (string | Placeholder)[] };
|
||||||
|
|
||||||
|
const removeDupes = (messages: Translation[]) => {
|
||||||
|
const seen = new Map<string, Translation>();
|
||||||
|
for (const message of messages) {
|
||||||
|
if (!seen.has(message.name)) {
|
||||||
|
seen.set(message.name, message);
|
||||||
|
} else {
|
||||||
|
console.log(`Duplicate detected: ${message.name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Array.from(seen.values());
|
||||||
|
};
|
||||||
|
|
||||||
const localizer = new TransformLitLocalizer(config as Config & { output: TransformOutputConfig });
|
const localizer = new TransformLitLocalizer(config as Config & { output: TransformOutputConfig });
|
||||||
const { messages } = localizer.extractSourceMessages();
|
const { messages } = localizer.extractSourceMessages();
|
||||||
const translations = messages.map(pseudoMessagify);
|
|
||||||
|
const translations = removeDupes(messages.map(pseudoMessagify));
|
||||||
const sorted = sortProgramMessages([...messages]);
|
const sorted = sortProgramMessages([...messages]);
|
||||||
|
|
||||||
const formatter = makeFormatter(config);
|
const formatter = makeFormatter(config);
|
||||||
formatter.writeOutput(sorted, new Map<Locale, Message[]>([[pseudoLocale, translations]]));
|
formatter.writeOutput(sorted, new Map<Locale, Message[]>([[pseudoLocale, translations]]));
|
||||||
|
|
||||||
|
// We have this persistent problem where the *formatter* inserts a handful of pseudolocalized lines
|
||||||
|
// twice, even though they end up with the same ID. This removes those entries the hard way.
|
||||||
|
|
||||||
|
function removeXmlDuplicates() {
|
||||||
|
const transUnitRe = /<trans-unit id="(s[a-z0-9]+)">/;
|
||||||
|
const transCloseRe = /<\/trans-unit>/;
|
||||||
|
const seen = new Set<string>();
|
||||||
|
const target = path.join(__dirname, "../xliff/pseudo-LOCALE.xlf");
|
||||||
|
const pseudoXliff = readFileSync(target, "utf8").split("\n");
|
||||||
|
|
||||||
|
const result = [];
|
||||||
|
let inDupe = false;
|
||||||
|
for(const line of pseudoXliff) {
|
||||||
|
if (inDupe && transCloseRe.test(line)) {
|
||||||
|
inDupe = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const mTransId = transUnitRe.exec(line);
|
||||||
|
if (!mTransId) {
|
||||||
|
result.push(line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const id = mTransId[1];
|
||||||
|
if (seen.has(id)) {
|
||||||
|
inDupe = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seen.add(id);
|
||||||
|
result.push(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeFileSync(target, result.join("\n"), "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
removeXmlDuplicates();
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
// Do not modify this file by hand!
|
|
||||||
// Re-generate this file by running lit-localize.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The locale code that templates in this source code are written in.
|
|
||||||
*/
|
|
||||||
export const sourceLocale = `en`;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The other locale codes that this application is localized into. Sorted
|
|
||||||
* lexicographically.
|
|
||||||
*/
|
|
||||||
export const targetLocales = [
|
|
||||||
`de`,
|
|
||||||
`en`,
|
|
||||||
`es`,
|
|
||||||
`fr`,
|
|
||||||
`ko`,
|
|
||||||
`nl`,
|
|
||||||
`pl`,
|
|
||||||
`pseudo-LOCALE`,
|
|
||||||
`tr`,
|
|
||||||
`zh_TW`,
|
|
||||||
`zh-CN`,
|
|
||||||
`zh-Hans`,
|
|
||||||
`zh-Hant`,
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All valid project locale codes. Sorted lexicographically.
|
|
||||||
*/
|
|
||||||
export const allLocales = [
|
|
||||||
`de`,
|
|
||||||
`en`,
|
|
||||||
`en`,
|
|
||||||
`es`,
|
|
||||||
`fr`,
|
|
||||||
`ko`,
|
|
||||||
`nl`,
|
|
||||||
`pl`,
|
|
||||||
`pseudo-LOCALE`,
|
|
||||||
`tr`,
|
|
||||||
`zh_TW`,
|
|
||||||
`zh-CN`,
|
|
||||||
`zh-Hans`,
|
|
||||||
`zh-Hant`,
|
|
||||||
] as const;
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -8157,14 +8157,10 @@ Bindings to groups/users are checked against the user of the event.</source>
|
||||||
<source>Maximum concurrent allowed connections to this endpoint. Can be set to -1 to disable the limit.</source>
|
<source>Maximum concurrent allowed connections to this endpoint. Can be set to -1 to disable the limit.</source>
|
||||||
<target>Màxĩmũm ćōńćũŕŕēńţ àĺĺōŵēď ćōńńēćţĩōńś ţō ţĥĩś ēńďƥōĩńţ. Ćàń ƀē śēţ ţō -1 ţō ďĩśàƀĺē ţĥē ĺĩmĩţ.</target>
|
<target>Màxĩmũm ćōńćũŕŕēńţ àĺĺōŵēď ćōńńēćţĩōńś ţō ţĥĩś ēńďƥōĩńţ. Ćàń ƀē śēţ ţō -1 ţō ďĩśàƀĺē ţĥē ĺĩmĩţ.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="sc39f6abf0daedb0f">
|
|
||||||
<source>Maximum concurrent connections</source>
|
<source>Maximum concurrent connections</source>
|
||||||
<target>Màxĩmũm ćōńćũŕŕēńţ ćōńńēćţĩōńś</target>
|
<target>Màxĩmũm ćōńćũŕŕēńţ ćōńńēćţĩōńś</target>
|
||||||
</trans-unit>
|
|
||||||
<trans-unit id="s62418cbcd2a25498">
|
|
||||||
<source>Maximum concurrent allowed connections to this endpoint. Can be set to -1 to disable the limit.</source>
|
<source>Maximum concurrent allowed connections to this endpoint. Can be set to -1 to disable the limit.</source>
|
||||||
<target>Màxĩmũm ćōńćũŕŕēńţ àĺĺōŵēď ćōńńēćţĩōńś ţō ţĥĩś ēńďƥōĩńţ. Ćàń ƀē śēţ ţō -1 ţō ďĩśàƀĺē ţĥē ĺĩmĩţ.</target>
|
<target>Màxĩmũm ćōńćũŕŕēńţ àĺĺōŵēď ćōńńēćţĩōńś ţō ţĥĩś ēńďƥōĩńţ. Ćàń ƀē śēţ ţō -1 ţō ďĩśàƀĺē ţĥē ĺĩmĩţ.</target>
|
||||||
</trans-unit>
|
|
||||||
<trans-unit id="s94d61907ee22a8c1">
|
<trans-unit id="s94d61907ee22a8c1">
|
||||||
<source>Korean</source>
|
<source>Korean</source>
|
||||||
<target>Ķōŕēàń</target>
|
<target>Ķōŕēàń</target>
|
||||||
|
|
Reference in New Issue