@babelize/engine 0.3.9 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analysis/scan.d.ts +21 -0
- package/dist/analysis/scan.js +87 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -1
- package/dist/local/hosted-provider.d.ts +13 -0
- package/dist/local/hosted-provider.js +28 -2
- package/dist/modules/extractor/extract.js +9 -0
- package/dist/modules/translator/translate.js +8 -0
- package/dist/utils/endonyms.d.ts +2 -0
- package/dist/utils/endonyms.js +38 -0
- package/dist/utils/source-scope.d.ts +4 -1
- package/dist/utils/source-scope.js +6 -3
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type SourceScope } from '../utils/source-scope';
|
|
2
|
+
export interface ScannedString {
|
|
3
|
+
text: string;
|
|
4
|
+
line: number;
|
|
5
|
+
/** An ICU message (plural/select) built from the source. */
|
|
6
|
+
is_icu: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ScannedFile {
|
|
9
|
+
/** Relative to `cwd`. */
|
|
10
|
+
path: string;
|
|
11
|
+
hardcoded_strings: ScannedString[];
|
|
12
|
+
}
|
|
13
|
+
export interface ScanStringsOptions {
|
|
14
|
+
/** File extensions to read (default: .js .jsx .ts .tsx .vue .html). */
|
|
15
|
+
extensions?: string[];
|
|
16
|
+
/** Each list given replaces the project's `.babelize/config.json` include/exclude. */
|
|
17
|
+
sourceScope?: SourceScope;
|
|
18
|
+
/** Paths in the result are relative to this (default: process.cwd()). */
|
|
19
|
+
cwd?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function scanStrings(dir: string, options?: ScanStringsOptions): Promise<ScannedFile[]>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.scanStrings = scanStrings;
|
|
37
|
+
/**
|
|
38
|
+
* `babelize scan` / MCP `babelize_scan`: the hardcoded strings in a folder,
|
|
39
|
+
* found by the same extractor `translate` uses (#381). Read-only, no network,
|
|
40
|
+
* no framework setup needed.
|
|
41
|
+
*/
|
|
42
|
+
const fs_1 = require("fs");
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
const types_1 = require("../runtime/types");
|
|
45
|
+
const extract_1 = require("../modules/extractor/extract");
|
|
46
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
47
|
+
const source_scope_1 = require("../utils/source-scope");
|
|
48
|
+
const PROJECT_MARKERS = ['.babelize', 'package.json', 'manage.py', '.git'];
|
|
49
|
+
/** The nearest folder at or above `dir` that looks like a project root; `dir` when none. */
|
|
50
|
+
async function projectRoot(dir) {
|
|
51
|
+
for (let current = dir;; current = path.dirname(current)) {
|
|
52
|
+
for (const marker of PROJECT_MARKERS) {
|
|
53
|
+
if (await fs_1.promises.stat(path.join(current, marker)).then(() => true, () => false))
|
|
54
|
+
return current;
|
|
55
|
+
}
|
|
56
|
+
if (path.dirname(current) === current)
|
|
57
|
+
return dir;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const ICU = /\{\s*\w+\s*,\s*(?:plural|select|selectordinal)\s*,/;
|
|
61
|
+
async function scanStrings(dir, options = {}) {
|
|
62
|
+
const abs = path.resolve(dir);
|
|
63
|
+
const cwd = options.cwd ?? process.cwd();
|
|
64
|
+
const root = await projectRoot(abs);
|
|
65
|
+
// Globs are relative to the project root, as in translate.
|
|
66
|
+
const inScope = (0, source_scope_1.createScopeMatcher)((0, source_scope_1.mergeSourceScope)(await (0, source_scope_1.readSourceScope)(root), options.sourceScope));
|
|
67
|
+
const extensions = (options.extensions ?? types_1.SUPPORTED_EXTENSIONS).map((e) => (e.startsWith('.') ? e : `.${e}`).toLowerCase());
|
|
68
|
+
(0, file_utils_1.clearFindFilesCache)();
|
|
69
|
+
const files = (await (0, file_utils_1.findFiles)(abs, extensions, types_1.EXCLUDED_PATTERNS))
|
|
70
|
+
.filter((file) => inScope(path.relative(root, file)))
|
|
71
|
+
.sort();
|
|
72
|
+
const out = [];
|
|
73
|
+
for (const file of files) {
|
|
74
|
+
const content = await fs_1.promises.readFile(file, 'utf8').catch(() => null);
|
|
75
|
+
if (content === null)
|
|
76
|
+
continue;
|
|
77
|
+
const rel = path.relative(root, file).split(path.sep).join('/');
|
|
78
|
+
const { strings } = await (0, extract_1.extractStringsFromFile)(content, rel).catch(() => ({ strings: [] }));
|
|
79
|
+
if (strings.length === 0)
|
|
80
|
+
continue;
|
|
81
|
+
out.push({
|
|
82
|
+
path: path.relative(cwd, file).split(path.sep).join('/'),
|
|
83
|
+
hardcoded_strings: strings.map((s) => ({ text: s.text, line: s.line, is_icu: ICU.test(s.text) })),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -62,5 +62,8 @@ export { checkProjectLocales, localeIssueFile, readProjectLocaleConfig } from '.
|
|
|
62
62
|
export type { CheckProjectOptions, LocaleSetReport, ProjectLocaleCheck, ProjectLocaleConfig } from './qa/check-project';
|
|
63
63
|
export { hashText, translationCacheKey, TRANSLATION_CACHE_TTL_SECONDS } from './utils/cache-keys';
|
|
64
64
|
export { createScopeMatcher, mergeSourceScope, normalizeScopePatterns, readSourceScope } from './utils/source-scope';
|
|
65
|
+
export { scanStrings } from './analysis/scan';
|
|
66
|
+
export type { ScannedFile, ScannedString, ScanStringsOptions } from './analysis/scan';
|
|
67
|
+
export { extractStringsFromFile } from './modules/extractor/extract';
|
|
65
68
|
export type { SourceScope } from './utils/source-scope';
|
|
66
69
|
export * from './local';
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
22
22
|
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.CircuitBreaker = exports.validateBatchQuality = exports.validateTranslationQuality = exports.translatorLoadBalancer = exports.warmupTranslator = exports.checkTranslatorHealth = exports.callTranslator = exports.requiredPluralCategories = exports.parseIcu = exports.isIcuMessage = exports.compareIcuMessages = exports.sameProtectedSpans = exports.restoreText = exports.protectText = exports.hasNothingToTranslate = exports.checkTokens = exports.validateRawTokens = exports.sanitizeTranslation = exports.restorePlaceholders = exports.protectPlaceholders = exports.hashString = exports.hasICUSyntax = exports.extractPlaceholders = exports.parseCode = exports.I18N_LIBRARY_NAMES = exports.detectI18n = exports.SUPPORTED_SUMMARY = exports.FRAMEWORK_DISPLAY_NAMES = exports.localRepoFiles = exports.detectStack = exports.saveProjectConfig = exports.saveCachedStrings = exports.getProjectInfo = exports.getBabelizeSummary = exports.detectProjectInfo = exports.addBabelToHistory = exports.formatSyncNotificationMessage = exports.detectSyncIssues = exports.matchFromMemory = exports.setLocaleValue = exports.applyTranslationOverrides = exports.setEngineLogger = exports.runWithEngineLogger = exports.validateWorkspace = exports.scanKeyReferences = exports.RunAbortedError = exports.validateEngineConfigV2 = exports.runEngineV2 = exports.loadBabelizeConfig = exports.BabelizeEngine = void 0;
|
|
25
|
-
exports.readSourceScope = exports.normalizeScopePatterns = exports.mergeSourceScope = exports.createScopeMatcher = exports.TRANSLATION_CACHE_TTL_SECONDS = exports.translationCacheKey = exports.hashText = exports.readProjectLocaleConfig = exports.localeIssueFile = exports.checkProjectLocales = exports.ReviewError = exports.reviewLocaleChanges = exports.loadLocale = exports.isLocaleCode = exports.isIgnoredLocalePath = exports.groupLocaleFiles = exports.findLocaleFileSets = exports.DEFAULT_LOCALE_IGNORE_DIRS = exports.sanitizeFormality = exports.parseFormalityList = exports.hasFormalitySplit = exports.formalityOf = exports.formalityIssues = exports.formalityInstruction = exports.formalityFor = exports.detectFormality = exports.glossaryFingerprint = exports.normalizeGlossary = exports.localeValue = exports.containsTerm = exports.canonicalizeLocaleKeys = exports.canonicalLocale = exports.tallyLocaleIssues = exports.flattenLocaleMessages = exports.checkLocalePair = exports.frameworkSupport = exports.analyzeWorkspace = exports.analyzeProject = exports.localeExtension = exports.getCircuitBreaker = exports.CircuitState = void 0;
|
|
25
|
+
exports.extractStringsFromFile = exports.scanStrings = exports.readSourceScope = exports.normalizeScopePatterns = exports.mergeSourceScope = exports.createScopeMatcher = exports.TRANSLATION_CACHE_TTL_SECONDS = exports.translationCacheKey = exports.hashText = exports.readProjectLocaleConfig = exports.localeIssueFile = exports.checkProjectLocales = exports.ReviewError = exports.reviewLocaleChanges = exports.loadLocale = exports.isLocaleCode = exports.isIgnoredLocalePath = exports.groupLocaleFiles = exports.findLocaleFileSets = exports.DEFAULT_LOCALE_IGNORE_DIRS = exports.sanitizeFormality = exports.parseFormalityList = exports.hasFormalitySplit = exports.formalityOf = exports.formalityIssues = exports.formalityInstruction = exports.formalityFor = exports.detectFormality = exports.glossaryFingerprint = exports.normalizeGlossary = exports.localeValue = exports.containsTerm = exports.canonicalizeLocaleKeys = exports.canonicalLocale = exports.tallyLocaleIssues = exports.flattenLocaleMessages = exports.checkLocalePair = exports.frameworkSupport = exports.analyzeWorkspace = exports.analyzeProject = exports.localeExtension = exports.getCircuitBreaker = exports.CircuitState = void 0;
|
|
26
26
|
var BabelizeEngine_1 = require("./BabelizeEngine");
|
|
27
27
|
Object.defineProperty(exports, "BabelizeEngine", { enumerable: true, get: function () { return BabelizeEngine_1.BabelizeEngine; } });
|
|
28
28
|
var config_1 = require("./config");
|
|
@@ -158,5 +158,9 @@ Object.defineProperty(exports, "createScopeMatcher", { enumerable: true, get: fu
|
|
|
158
158
|
Object.defineProperty(exports, "mergeSourceScope", { enumerable: true, get: function () { return source_scope_1.mergeSourceScope; } });
|
|
159
159
|
Object.defineProperty(exports, "normalizeScopePatterns", { enumerable: true, get: function () { return source_scope_1.normalizeScopePatterns; } });
|
|
160
160
|
Object.defineProperty(exports, "readSourceScope", { enumerable: true, get: function () { return source_scope_1.readSourceScope; } });
|
|
161
|
+
var scan_1 = require("./analysis/scan");
|
|
162
|
+
Object.defineProperty(exports, "scanStrings", { enumerable: true, get: function () { return scan_1.scanStrings; } });
|
|
163
|
+
var extract_1 = require("./modules/extractor/extract");
|
|
164
|
+
Object.defineProperty(exports, "extractStringsFromFile", { enumerable: true, get: function () { return extract_1.extractStringsFromFile; } });
|
|
161
165
|
// ── Local translation runner (CLI `babelize translate`, MCP `babelize_translate`) ──
|
|
162
166
|
__exportStar(require("./local"), exports);
|
|
@@ -66,7 +66,15 @@ export interface HostedProviderOptions {
|
|
|
66
66
|
timeoutMs?: number;
|
|
67
67
|
/** Sent as User-Agent. */
|
|
68
68
|
userAgent?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Batch requests in flight at once, across every locale of the run
|
|
71
|
+
* (default HOSTED_MAX_IN_FLIGHT). The hosted translator is shared: a run
|
|
72
|
+
* that floods it times out and fails everyone's batches (#388).
|
|
73
|
+
*/
|
|
74
|
+
maxInFlight?: number;
|
|
69
75
|
}
|
|
76
|
+
/** Default cap on concurrent /v1/translate/batch requests per run. */
|
|
77
|
+
export declare const HOSTED_MAX_IN_FLIGHT = 2;
|
|
70
78
|
export declare function parseRetryAfterMs(value: string | null): number | undefined;
|
|
71
79
|
export declare class HostedTranslationProvider implements TranslationProvider {
|
|
72
80
|
/** Model the server reported (X-Babelize-Model), once a request succeeded. */
|
|
@@ -86,6 +94,9 @@ export declare class HostedTranslationProvider implements TranslationProvider {
|
|
|
86
94
|
private token;
|
|
87
95
|
/** In-flight refresh, shared by concurrent batches that all got a 401. */
|
|
88
96
|
private refreshing?;
|
|
97
|
+
/** Requests running now, and the ones waiting for a slot. */
|
|
98
|
+
private inFlight;
|
|
99
|
+
private readonly waiting;
|
|
89
100
|
constructor(options: HostedProviderOptions);
|
|
90
101
|
/**
|
|
91
102
|
* Ask the server what serves translation (GET /v1/translate/capabilities)
|
|
@@ -95,6 +106,8 @@ export declare class HostedTranslationProvider implements TranslationProvider {
|
|
|
95
106
|
detectCapabilities(): Promise<void>;
|
|
96
107
|
translateBatch(request: TranslationBatchRequest): Promise<KeyResult[]>;
|
|
97
108
|
private post;
|
|
109
|
+
/** Run `task` once fewer than maxInFlight requests are running. */
|
|
110
|
+
private withSlot;
|
|
98
111
|
private backoff;
|
|
99
112
|
private toError;
|
|
100
113
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HostedTranslationProvider = exports.HostedTranslationError = exports.BILLING_URL = exports.API_KEYS_URL = exports.HOSTED_CREDITS_HEADER = exports.HOSTED_MODEL_HEADER = exports.HOSTED_REQUEST_TIMEOUT_MS = exports.HOSTED_MAX_BATCH = void 0;
|
|
3
|
+
exports.HostedTranslationProvider = exports.HOSTED_MAX_IN_FLIGHT = exports.HostedTranslationError = exports.BILLING_URL = exports.API_KEYS_URL = exports.HOSTED_CREDITS_HEADER = exports.HOSTED_MODEL_HEADER = exports.HOSTED_REQUEST_TIMEOUT_MS = exports.HOSTED_MAX_BATCH = void 0;
|
|
4
4
|
exports.parseRetryAfterMs = parseRetryAfterMs;
|
|
5
5
|
const node_crypto_1 = require("node:crypto");
|
|
6
6
|
const language_codes_1 = require("../modules/translator/language-codes");
|
|
@@ -39,6 +39,8 @@ class HostedTranslationError extends Error {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.HostedTranslationError = HostedTranslationError;
|
|
42
|
+
/** Default cap on concurrent /v1/translate/batch requests per run. */
|
|
43
|
+
exports.HOSTED_MAX_IN_FLIGHT = 2;
|
|
42
44
|
const RETRYABLE_STATUS = new Set([429, 500, 502, 503, 504]);
|
|
43
45
|
function parseRetryAfterMs(value) {
|
|
44
46
|
if (!value)
|
|
@@ -59,6 +61,9 @@ class HostedTranslationProvider {
|
|
|
59
61
|
this.plainText = false;
|
|
60
62
|
/** Credits charged so far by this provider's batches (X-Credits-Charged). */
|
|
61
63
|
this.creditsCharged = 0;
|
|
64
|
+
/** Requests running now, and the ones waiting for a slot. */
|
|
65
|
+
this.inFlight = 0;
|
|
66
|
+
this.waiting = [];
|
|
62
67
|
this.token = options.apiKey;
|
|
63
68
|
this.opts = {
|
|
64
69
|
fetch: globalThis.fetch.bind(globalThis),
|
|
@@ -67,6 +72,7 @@ class HostedTranslationProvider {
|
|
|
67
72
|
baseDelayMs: 1000,
|
|
68
73
|
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
69
74
|
timeoutMs: exports.HOSTED_REQUEST_TIMEOUT_MS,
|
|
75
|
+
maxInFlight: exports.HOSTED_MAX_IN_FLIGHT,
|
|
70
76
|
...options,
|
|
71
77
|
apiUrl: options.apiUrl.replace(/\/+$/, ''),
|
|
72
78
|
};
|
|
@@ -120,7 +126,7 @@ class HostedTranslationProvider {
|
|
|
120
126
|
const hints = request.hints
|
|
121
127
|
? Object.fromEntries(Object.entries(request.hints).filter(([k]) => keys.has(k)))
|
|
122
128
|
: undefined;
|
|
123
|
-
for (const r of await this.post({ ...request, entries, hints }))
|
|
129
|
+
for (const r of await this.withSlot(() => this.post({ ...request, entries, hints })))
|
|
124
130
|
remote.set(r.key, r);
|
|
125
131
|
}
|
|
126
132
|
return request.entries.flatMap((e) => {
|
|
@@ -227,6 +233,26 @@ class HostedTranslationProvider {
|
|
|
227
233
|
throw error;
|
|
228
234
|
}
|
|
229
235
|
}
|
|
236
|
+
/** Run `task` once fewer than maxInFlight requests are running. */
|
|
237
|
+
async withSlot(task) {
|
|
238
|
+
if (this.inFlight >= Math.max(1, this.opts.maxInFlight)) {
|
|
239
|
+
// A finishing request hands its slot straight to us (inFlight unchanged).
|
|
240
|
+
await new Promise((resolve) => this.waiting.push(resolve));
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
this.inFlight++;
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
return await task();
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
const next = this.waiting.shift();
|
|
250
|
+
if (next)
|
|
251
|
+
next();
|
|
252
|
+
else
|
|
253
|
+
this.inFlight--;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
230
256
|
backoff(attempt) {
|
|
231
257
|
return this.opts.baseDelayMs * 2 ** attempt;
|
|
232
258
|
}
|
|
@@ -255,6 +255,9 @@ async function extractStringsFromFile(content, filePath, detectFormats, options)
|
|
|
255
255
|
return;
|
|
256
256
|
if (isOptionValue(path, text))
|
|
257
257
|
return;
|
|
258
|
+
// SVG geometry (`<path d="M12 .297c-6.63…">`) is numbers, not copy or prices (#381).
|
|
259
|
+
if (isSvgGeometry(path))
|
|
260
|
+
return;
|
|
258
261
|
// A literal in a branch (`role === 'brand' ? 'brand' : 'creator'`, `user?.id ?? 'usr_1'`)
|
|
259
262
|
// goes where the whole expression goes, so that's where it's judged.
|
|
260
263
|
const site = valueSite(path);
|
|
@@ -614,6 +617,12 @@ async function extractStringsFromFile(content, filePath, detectFormats, options)
|
|
|
614
617
|
return { strings, warnings, notInjected: unwired };
|
|
615
618
|
}
|
|
616
619
|
/** A string that names something rather than being shown: a property key, or part of a TypeScript type. */
|
|
620
|
+
/** SVG attributes whose value is geometry (`d`, `viewBox`, `points`, …). */
|
|
621
|
+
const SVG_GEOMETRY_ATTRS = new Set(['d', 'viewBox', 'points', 'transform', 'gradientTransform', 'patternTransform', 'strokeDasharray', 'stroke-dasharray', 'pathLength']);
|
|
622
|
+
function isSvgGeometry(path) {
|
|
623
|
+
const attr = path.parentPath;
|
|
624
|
+
return !!attr?.isJSXAttribute() && ast_helpers_1.t.isJSXIdentifier(attr.node.name) && SVG_GEOMETRY_ATTRS.has(attr.node.name.name);
|
|
625
|
+
}
|
|
617
626
|
function isKeyOrType(path) {
|
|
618
627
|
const parent = path.parentPath;
|
|
619
628
|
if (!parent)
|
|
@@ -16,6 +16,7 @@ const placeholder_protection_1 = require("../../utils/placeholder-protection");
|
|
|
16
16
|
const icu_message_1 = require("../../utils/icu-message");
|
|
17
17
|
const keygen_1 = require("../keygen");
|
|
18
18
|
const concurrent_map_1 = require("../../utils/concurrent-map");
|
|
19
|
+
const endonyms_1 = require("../../utils/endonyms");
|
|
19
20
|
const language_codes_1 = require("./language-codes");
|
|
20
21
|
const glossary_1 = require("../glossary");
|
|
21
22
|
const check_project_1 = require("../../qa/check-project");
|
|
@@ -674,6 +675,13 @@ configuredFormality) {
|
|
|
674
675
|
const countArgs = options.targetPlurals && !icu && (isLlm || (0, icu_branches_1.targetCategories)(targetLocale, 'cardinal').length > 1)
|
|
675
676
|
? (0, icu_message_1.countArguments)(entry.value)
|
|
676
677
|
: [];
|
|
678
|
+
if ((0, endonyms_1.isEndonym)(entry.value)) {
|
|
679
|
+
// A language's own name ("Deutsch", "日本語") stays as written: language
|
|
680
|
+
// pickers list them so every visitor finds their language.
|
|
681
|
+
result[entry.key] = entry.value;
|
|
682
|
+
metadata[entry.key] = { ...(metadata[entry.key] ?? {}), passthrough: true, endonym: true };
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
677
685
|
const ownTokens = (0, placeholder_protection_1.protectText)(entry.value, neverTranslateTerms);
|
|
678
686
|
if ((0, placeholder_protection_1.hasNothingToTranslate)(ownTokens.text)) {
|
|
679
687
|
result[entry.key] = entry.value;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEndonym = isEndonym;
|
|
4
|
+
/**
|
|
5
|
+
* A language's name for itself ("Deutsch", "español", "日本語"). Language
|
|
6
|
+
* pickers list these on purpose so every visitor can find their own
|
|
7
|
+
* language; translating them ("Deutsch" → "ドイツ語") breaks the picker.
|
|
8
|
+
*/
|
|
9
|
+
let endonyms = null;
|
|
10
|
+
/** Regional variants pickers commonly list besides the plain languages. */
|
|
11
|
+
const REGIONAL = ['pt-BR', 'pt-PT', 'zh-Hans', 'zh-Hant', 'zh-CN', 'zh-TW', 'es-419', 'es-MX', 'en-GB', 'en-US', 'fr-CA', 'sr-Latn'];
|
|
12
|
+
const normalize = (name) => name.trim().toLocaleLowerCase('und');
|
|
13
|
+
function build() {
|
|
14
|
+
const names = new Set();
|
|
15
|
+
const add = (code) => {
|
|
16
|
+
try {
|
|
17
|
+
const name = new Intl.DisplayNames([code], { type: 'language' }).of(code);
|
|
18
|
+
// An unknown code comes back as itself.
|
|
19
|
+
if (name && normalize(name) !== code.toLowerCase())
|
|
20
|
+
names.add(normalize(name));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Not a valid tag in this runtime.
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
27
|
+
for (const a of letters)
|
|
28
|
+
for (const b of letters)
|
|
29
|
+
add(a + b);
|
|
30
|
+
for (const code of REGIONAL)
|
|
31
|
+
add(code);
|
|
32
|
+
return names;
|
|
33
|
+
}
|
|
34
|
+
/** True when `text` is exactly some language's own name, in any letter case. */
|
|
35
|
+
function isEndonym(text) {
|
|
36
|
+
endonyms ?? (endonyms = build());
|
|
37
|
+
return endonyms.has(normalize(text));
|
|
38
|
+
}
|
|
@@ -17,7 +17,10 @@ export interface SourceScope {
|
|
|
17
17
|
export declare function normalizeScopePatterns(value: unknown): string[] | undefined;
|
|
18
18
|
/** `include`/`exclude` from `.babelize/config.json`; missing or malformed is no scope. */
|
|
19
19
|
export declare function readSourceScope(workspacePath: string): Promise<SourceScope>;
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* The config's scope with each list given by the caller (flags) replacing the
|
|
22
|
+
* config's. An empty list given clears it (`exclude: []`: nothing excluded).
|
|
23
|
+
*/
|
|
21
24
|
export declare function mergeSourceScope(config: SourceScope, override?: SourceScope): SourceScope;
|
|
22
25
|
/** Whether `scope` limits anything. */
|
|
23
26
|
export declare function hasSourceScope(scope: SourceScope | undefined): boolean;
|
|
@@ -75,11 +75,14 @@ async function readSourceScope(workspacePath) {
|
|
|
75
75
|
const { include, exclude } = raw;
|
|
76
76
|
return compactScope({ include: normalizeScopePatterns(include), exclude: normalizeScopePatterns(exclude) });
|
|
77
77
|
}
|
|
78
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* The config's scope with each list given by the caller (flags) replacing the
|
|
80
|
+
* config's. An empty list given clears it (`exclude: []`: nothing excluded).
|
|
81
|
+
*/
|
|
79
82
|
function mergeSourceScope(config, override = {}) {
|
|
80
83
|
return compactScope({
|
|
81
|
-
include: normalizeScopePatterns(override.include)
|
|
82
|
-
exclude: normalizeScopePatterns(override.exclude)
|
|
84
|
+
include: Array.isArray(override.include) ? normalizeScopePatterns(override.include) : config.include,
|
|
85
|
+
exclude: Array.isArray(override.exclude) ? normalizeScopePatterns(override.exclude) : config.exclude,
|
|
83
86
|
});
|
|
84
87
|
}
|
|
85
88
|
function compactScope(scope) {
|
package/package.json
CHANGED