@x18n/builtins 0.0.13 → 0.0.15
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/angular-templates-DqIOGfzT.mjs +8 -0
- package/dist/checks.d.mts +1 -0
- package/dist/checks.mjs +26 -1
- package/dist/extractors.mjs +7 -3
- package/dist/finders.d.mts +4 -1
- package/dist/finders.mjs +1 -1
- package/dist/formats/ecmascript.d.mts +5 -0
- package/dist/formats/ecmascript.mjs +232 -0
- package/dist/formats/ftl.d.mts +5 -0
- package/dist/formats/ftl.mjs +234 -0
- package/dist/formats/ini.d.mts +5 -0
- package/dist/formats/ini.mjs +158 -0
- package/dist/formats/json.d.mts +6 -0
- package/dist/formats/json.mjs +10 -0
- package/dist/formats/json5.d.mts +5 -0
- package/dist/formats/json5.mjs +143 -0
- package/dist/formats/jsonc.d.mts +6 -0
- package/dist/formats/jsonc.mjs +10 -0
- package/dist/formats/php.d.mts +5 -0
- package/dist/formats/php.mjs +198 -0
- package/dist/formats/po.d.mts +5 -0
- package/dist/formats/po.mjs +177 -0
- package/dist/formats/properties.d.mts +5 -0
- package/dist/formats/properties.mjs +123 -0
- package/dist/formats/resx.d.mts +6 -0
- package/dist/formats/resx.mjs +202 -0
- package/dist/formats/yaml.d.mts +5 -0
- package/dist/formats/yaml.mjs +140 -0
- package/dist/formats.d.mts +10 -34
- package/dist/formats.mjs +61 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +30 -22
- package/dist/{vue-CF4pe-Yr.mjs → js-CV-ECNJG.mjs} +67 -222
- package/dist/json-CGNSGS97.mjs +109 -0
- package/dist/json-CyjI8bjp.d.mts +8 -0
- package/dist/jsx-templates-B1J0no3i.mjs +17 -0
- package/dist/literal-gIdB1VGy.mjs +125 -0
- package/dist/locale-root-C_rch3IQ.mjs +15 -0
- package/dist/manifests.d.mts +8 -0
- package/dist/manifests.mjs +66 -2
- package/dist/placeholders.d.mts +11 -0
- package/dist/placeholders.mjs +28 -1
- package/dist/plugin-Cb1b0axD.mjs +83 -0
- package/dist/plural-forms-B7_QX4nG.mjs +12 -0
- package/dist/presets/cargo-i18n.d.mts +6 -0
- package/dist/presets/cargo-i18n.mjs +28 -0
- package/dist/presets/chrome-extension.d.mts +6 -0
- package/dist/presets/chrome-extension.mjs +52 -0
- package/dist/presets/dotnet-resx.d.mts +6 -0
- package/dist/presets/dotnet-resx.mjs +64 -0
- package/dist/presets/easy-localization.d.mts +6 -0
- package/dist/presets/easy-localization.mjs +36 -0
- package/dist/presets/ember-intl.d.mts +5 -0
- package/dist/presets/ember-intl.mjs +31 -0
- package/dist/presets/fluent-react.d.mts +5 -0
- package/dist/presets/fluent-react.mjs +46 -0
- package/dist/presets/fluent-vue.d.mts +5 -0
- package/dist/presets/fluent-vue.mjs +51 -0
- package/dist/presets/flutter-translate.d.mts +6 -0
- package/dist/presets/flutter-translate.mjs +30 -0
- package/dist/presets/flutter.d.mts +6 -0
- package/dist/presets/flutter.mjs +21 -0
- package/dist/presets/general.d.mts +6 -0
- package/dist/presets/general.mjs +17 -0
- package/dist/presets/globalize.d.mts +5 -0
- package/dist/presets/globalize.mjs +25 -0
- package/dist/presets/gravity-ui-i18n.d.mts +6 -0
- package/dist/presets/gravity-ui-i18n.mjs +41 -0
- package/dist/presets/i18n-tag.d.mts +5 -0
- package/dist/presets/i18n-tag.mjs +21 -0
- package/dist/presets/i18next-shopify.d.mts +6 -0
- package/dist/presets/i18next-shopify.mjs +23 -0
- package/dist/presets/i18next.d.mts +5 -0
- package/dist/presets/i18next.mjs +10 -0
- package/dist/presets/i18nice.d.mts +6 -0
- package/dist/presets/i18nice.mjs +29 -0
- package/dist/presets/jekyll.d.mts +5 -0
- package/dist/presets/jekyll.mjs +23 -0
- package/dist/presets/laravel-vue-i18n.d.mts +6 -0
- package/dist/presets/laravel-vue-i18n.mjs +54 -0
- package/dist/presets/laravel.d.mts +6 -0
- package/dist/presets/laravel.mjs +23 -0
- package/dist/presets/lingui.d.mts +5 -0
- package/dist/presets/lingui.mjs +61 -0
- package/dist/presets/next-international.d.mts +5 -0
- package/dist/presets/next-international.mjs +27 -0
- package/dist/presets/next-intl.d.mts +5 -0
- package/dist/presets/next-intl.mjs +55 -0
- package/dist/presets/next-translate.d.mts +5 -0
- package/dist/presets/next-translate.mjs +53 -0
- package/dist/presets/ngx-translate.d.mts +5 -0
- package/dist/presets/ngx-translate.mjs +41 -0
- package/dist/presets/nuxt-i18n-micro.d.mts +5 -0
- package/dist/presets/nuxt-i18n-micro.mjs +81 -0
- package/dist/presets/nuxt-i18n.d.mts +5 -0
- package/dist/presets/nuxt-i18n.mjs +23 -0
- package/dist/presets/paraglide.d.mts +5 -0
- package/dist/presets/paraglide.mjs +38 -0
- package/dist/presets/php-gettext.d.mts +6 -0
- package/dist/presets/php-gettext.mjs +27 -0
- package/dist/presets/php-joomla.d.mts +6 -0
- package/dist/presets/php-joomla.mjs +22 -0
- package/dist/presets/polyglot.d.mts +5 -0
- package/dist/presets/polyglot.mjs +23 -0
- package/dist/presets/python-gettext.d.mts +6 -0
- package/dist/presets/python-gettext.mjs +44 -0
- package/dist/presets/react-i18next.d.mts +5 -0
- package/dist/presets/react-i18next.mjs +67 -0
- package/dist/presets/react-intl.d.mts +5 -0
- package/dist/presets/react-intl.mjs +47 -0
- package/dist/presets/ruby-i18n-js.d.mts +5 -0
- package/dist/presets/ruby-i18n-js.mjs +19 -0
- package/dist/presets/ruby-rails.d.mts +7 -0
- package/dist/presets/ruby-rails.mjs +44 -0
- package/dist/presets/solid-primitives-i18n.d.mts +5 -0
- package/dist/presets/solid-primitives-i18n.mjs +29 -0
- package/dist/presets/svelte-i18n.d.mts +5 -0
- package/dist/presets/svelte-i18n.mjs +33 -0
- package/dist/presets/svelte-i18next.d.mts +5 -0
- package/dist/presets/svelte-i18next.mjs +27 -0
- package/dist/presets/transloco.d.mts +5 -0
- package/dist/presets/transloco.mjs +44 -0
- package/dist/presets/typesafe-i18n.d.mts +6 -0
- package/dist/presets/typesafe-i18n.mjs +61 -0
- package/dist/presets/ui5.d.mts +5 -0
- package/dist/presets/ui5.mjs +35 -0
- package/dist/presets/vscode-extension.d.mts +5 -0
- package/dist/presets/vscode-extension.mjs +53 -0
- package/dist/presets/vue-i18n.d.mts +5 -0
- package/dist/presets/vue-i18n.mjs +59 -0
- package/dist/presets.d.mts +7 -54
- package/dist/presets.mjs +346 -1
- package/dist/reporters/github.d.mts +6 -0
- package/dist/reporters/github.mjs +27 -0
- package/dist/reporters/json.d.mts +6 -0
- package/dist/reporters/json.mjs +24 -0
- package/dist/reporters/markdown.d.mts +6 -0
- package/dist/reporters/markdown.mjs +37 -0
- package/dist/reporters/pretty.d.mts +6 -0
- package/dist/reporters/pretty.mjs +64 -0
- package/dist/reporters/sarif.d.mts +6 -0
- package/dist/reporters/sarif.mjs +48 -0
- package/dist/reporters.d.mts +5 -12
- package/dist/reporters.mjs +8 -218
- package/dist/reviews.d.mts +6 -0
- package/dist/reviews.mjs +35 -0
- package/dist/scanners/astro.d.mts +6 -0
- package/dist/scanners/astro.mjs +256 -0
- package/dist/scanners/js.d.mts +6 -0
- package/dist/scanners/js.mjs +33 -0
- package/dist/scanners/regex-scopes.d.mts +14 -0
- package/dist/scanners/regex-scopes.mjs +41 -0
- package/dist/scanners/regex.d.mts +9 -0
- package/dist/{regex-AYVhuSb6.mjs → scanners/regex.mjs} +2 -40
- package/dist/scanners/svelte.d.mts +6 -0
- package/dist/{scanners-DhnnVp7s.mjs → scanners/svelte.mjs} +3 -3
- package/dist/scanners/vue.d.mts +6 -0
- package/dist/scanners/vue.mjs +172 -0
- package/dist/scanners.d.mts +9 -50
- package/dist/scanners.mjs +36 -4
- package/dist/sfc-blocks-DaGKDZsb.mjs +213 -0
- package/dist/shared-C7ceptwi.mjs +55 -0
- package/dist/shared-D-tbsYmc.mjs +30 -0
- package/dist/shared-D4NJBKEP.mjs +17 -0
- package/dist/shared-Tq06G0gp.mjs +6 -0
- package/dist/shared-meYeVckh.mjs +11 -0
- package/dist/vue-compiler-0sfLIiiL.mjs +8 -0
- package/package.json +68 -3
- package/dist/formats-CFkM5co0.mjs +0 -1370
- package/dist/presets-Co5SlnKr.mjs +0 -1187
- package/dist/sfc-blocks-BqQ8m9rX.mjs +0 -161
- package/dist/yaml-plugin.d.mts +0 -8
- package/dist/yaml-plugin.mjs +0 -68
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { a as json5, o as json, t as yaml } from "./formats-CFkM5co0.mjs";
|
|
2
|
-
import { t as loadVueCompiler } from "./vue-CF4pe-Yr.mjs";
|
|
3
|
-
import { isMessageLeaf, pathId } from "@x18n/core";
|
|
4
|
-
//#region src/finders/sfc-blocks.ts
|
|
5
|
-
const formatOfLang = {
|
|
6
|
-
json: "json",
|
|
7
|
-
json5: "json5",
|
|
8
|
-
yaml: "yaml",
|
|
9
|
-
yml: "yaml"
|
|
10
|
-
};
|
|
11
|
-
/** A format for blocks that hold every locale (`{ "en": {...}, "de": {...} }`): each resource sees its locale's subtree. */
|
|
12
|
-
function localeRoot(base) {
|
|
13
|
-
return {
|
|
14
|
-
id: `sfc-${base.id}`,
|
|
15
|
-
extensions: [],
|
|
16
|
-
parse(text, ctx) {
|
|
17
|
-
const parsed = base.parse(text, ctx);
|
|
18
|
-
const subtree = parsed.tree[ctx.locale];
|
|
19
|
-
const tree = subtree && !isMessageLeaf(subtree) ? subtree : {};
|
|
20
|
-
const ranges = /* @__PURE__ */ new Map();
|
|
21
|
-
const prefix = `${pathId([ctx.locale])}\u0000`;
|
|
22
|
-
for (const [id, range] of parsed.ranges ?? []) if (id.startsWith(prefix)) ranges.set(id.slice(prefix.length), range);
|
|
23
|
-
return {
|
|
24
|
-
tree,
|
|
25
|
-
ranges
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
edit: base.edit ? (text, ops, ctx) => base.edit(text, ops.map((op) => ({
|
|
29
|
-
...op,
|
|
30
|
-
path: [ctx.locale, ...op.path]
|
|
31
|
-
})), ctx) : void 0
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/** Vue `<i18n>` blocks: one resource per block and locale (`locale="en"`, or every top-level locale key). */
|
|
35
|
-
function sfcBlocks() {
|
|
36
|
-
const bases = [
|
|
37
|
-
json(),
|
|
38
|
-
json5(),
|
|
39
|
-
yaml()
|
|
40
|
-
].flatMap((plugin) => plugin.formats ?? []);
|
|
41
|
-
return {
|
|
42
|
-
name: "x18n:finder-sfc-blocks",
|
|
43
|
-
formats: bases.map(localeRoot),
|
|
44
|
-
localeFinders: [{
|
|
45
|
-
id: "sfc-blocks",
|
|
46
|
-
async find(ctx) {
|
|
47
|
-
const files = await ctx.host.glob(["**/*.vue"], {
|
|
48
|
-
ignore: ctx.config.usage.exclude,
|
|
49
|
-
gitignore: true
|
|
50
|
-
});
|
|
51
|
-
const { parse } = await loadVueCompiler();
|
|
52
|
-
const out = [];
|
|
53
|
-
for (const path of files) {
|
|
54
|
-
const text = await ctx.host.readFile(path);
|
|
55
|
-
if (!text?.includes("<i18n")) continue;
|
|
56
|
-
const { descriptor } = parse(text, {
|
|
57
|
-
filename: path,
|
|
58
|
-
sourceMap: false
|
|
59
|
-
});
|
|
60
|
-
descriptor.customBlocks.forEach((block, index) => {
|
|
61
|
-
if (block.type !== "i18n") return;
|
|
62
|
-
const lang = typeof block.attrs.lang === "string" ? block.attrs.lang : "json";
|
|
63
|
-
const formatId = formatOfLang[lang] ?? "json";
|
|
64
|
-
const blockInfo = {
|
|
65
|
-
index,
|
|
66
|
-
range: {
|
|
67
|
-
start: block.loc.start.offset,
|
|
68
|
-
end: block.loc.end.offset
|
|
69
|
-
},
|
|
70
|
-
lang
|
|
71
|
-
};
|
|
72
|
-
if (typeof block.attrs.locale === "string") {
|
|
73
|
-
out.push({
|
|
74
|
-
path,
|
|
75
|
-
locale: block.attrs.locale,
|
|
76
|
-
namespace: void 0,
|
|
77
|
-
format: formatId,
|
|
78
|
-
block: blockInfo
|
|
79
|
-
});
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const base = bases.find((f) => f.id === formatId);
|
|
83
|
-
try {
|
|
84
|
-
const tree = base.parse(block.content, {
|
|
85
|
-
path,
|
|
86
|
-
locale: "",
|
|
87
|
-
namespace: void 0,
|
|
88
|
-
indent: void 0
|
|
89
|
-
}).tree;
|
|
90
|
-
for (const locale of Object.keys(tree)) out.push({
|
|
91
|
-
path,
|
|
92
|
-
locale,
|
|
93
|
-
namespace: void 0,
|
|
94
|
-
format: `sfc-${formatId}`,
|
|
95
|
-
block: {
|
|
96
|
-
...blockInfo,
|
|
97
|
-
index: index * 1e3 + Object.keys(tree).indexOf(locale)
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
} catch {
|
|
101
|
-
out.push({
|
|
102
|
-
path,
|
|
103
|
-
locale: ctx.config.sourceLocale,
|
|
104
|
-
namespace: void 0,
|
|
105
|
-
format: `sfc-${formatId}`,
|
|
106
|
-
block: blockInfo
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return out;
|
|
112
|
-
}
|
|
113
|
-
}]
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/** fluent-vue `<fluent locale="en">` blocks in Vue SFCs, read with the `ftl` format. */
|
|
117
|
-
function sfcFluentBlocks() {
|
|
118
|
-
return {
|
|
119
|
-
name: "x18n:finder-sfc-fluent-blocks",
|
|
120
|
-
localeFinders: [{
|
|
121
|
-
id: "sfc-fluent-blocks",
|
|
122
|
-
async find(ctx) {
|
|
123
|
-
const files = await ctx.host.glob(["**/*.vue"], {
|
|
124
|
-
ignore: ctx.config.usage.exclude,
|
|
125
|
-
gitignore: true
|
|
126
|
-
});
|
|
127
|
-
const { parse } = await loadVueCompiler();
|
|
128
|
-
const out = [];
|
|
129
|
-
for (const path of files) {
|
|
130
|
-
const text = await ctx.host.readFile(path);
|
|
131
|
-
if (!text?.includes("<fluent")) continue;
|
|
132
|
-
parse(text, {
|
|
133
|
-
filename: path,
|
|
134
|
-
sourceMap: false
|
|
135
|
-
}).descriptor.customBlocks.forEach((block, index) => {
|
|
136
|
-
if (block.type === "fluent" && typeof block.attrs.locale === "string") {
|
|
137
|
-
const range = {
|
|
138
|
-
start: block.loc.start.offset,
|
|
139
|
-
end: block.loc.end.offset
|
|
140
|
-
};
|
|
141
|
-
out.push({
|
|
142
|
-
path,
|
|
143
|
-
locale: block.attrs.locale,
|
|
144
|
-
namespace: void 0,
|
|
145
|
-
format: "ftl",
|
|
146
|
-
block: {
|
|
147
|
-
index,
|
|
148
|
-
range,
|
|
149
|
-
lang: "ftl"
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
return out;
|
|
156
|
-
}
|
|
157
|
-
}]
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
//#endregion
|
|
161
|
-
export { sfcFluentBlocks as n, sfcBlocks as t };
|
package/dist/yaml-plugin.d.mts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Plugin, PluginFile, Preset } from "@x18n/core";
|
|
2
|
-
//#region src/yaml-plugin/index.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Compiles a validated YAML plugin into plugin objects. Each section maps to the
|
|
5
|
-
* options of a built-in factory, so moving to a TS plugin is a small change.
|
|
6
|
-
*/
|
|
7
|
-
export declare function compileYamlPlugin(data: PluginFile): Plugin | Preset;
|
|
8
|
-
//#endregion
|
package/dist/yaml-plugin.mjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { placeholderFromShape } from "./placeholders.mjs";
|
|
2
|
-
import { r as regexScopes } from "./regex-AYVhuSb6.mjs";
|
|
3
|
-
//#region src/yaml-plugin/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* Compiles a validated YAML plugin into plugin objects. Each section maps to the
|
|
6
|
-
* options of a built-in factory, so moving to a TS plugin is a small change.
|
|
7
|
-
*/
|
|
8
|
-
function compileYamlPlugin(data) {
|
|
9
|
-
const replacements = (data.normalizeKey ?? []).map((rule) => ({
|
|
10
|
-
from: new RegExp(rule.replace.pattern, "g"),
|
|
11
|
-
to: rule.replace.with
|
|
12
|
-
}));
|
|
13
|
-
const localeInfo = data.localeInfo;
|
|
14
|
-
const plugin = {
|
|
15
|
-
name: data.name,
|
|
16
|
-
config(draft) {
|
|
17
|
-
const defaults = data.config;
|
|
18
|
-
if (defaults?.sourceLocale) draft.sourceLocale = defaults.sourceLocale;
|
|
19
|
-
if (defaults?.locales) draft.locales = defaults.locales;
|
|
20
|
-
if (defaults?.resources && draft.resources.length === 0) draft.resources = defaults.resources;
|
|
21
|
-
if (defaults?.keyStyle) draft.keyStyle = defaults.keyStyle;
|
|
22
|
-
if (defaults?.namespace) draft.namespace = {
|
|
23
|
-
separator: defaults.namespace.separator ?? draft.namespace.separator,
|
|
24
|
-
default: defaults.namespace.default ?? draft.namespace.default,
|
|
25
|
-
fromPath: defaults.namespace.fromPath ?? draft.namespace.fromPath
|
|
26
|
-
};
|
|
27
|
-
draft.usage = {
|
|
28
|
-
...draft.usage,
|
|
29
|
-
calls: [...draft.usage.calls, ...data.scanners?.calls ?? []],
|
|
30
|
-
regex: [...draft.usage.regex, ...data.scanners?.regex ?? []]
|
|
31
|
-
};
|
|
32
|
-
if (data.extract?.templates) draft.extract = {
|
|
33
|
-
...draft.extract,
|
|
34
|
-
templates: [...draft.extract.templates ?? [], ...data.extract.templates]
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
derivedKeys: data.derivedKeys,
|
|
38
|
-
placeholders: data.placeholders?.map(placeholderFromShape),
|
|
39
|
-
normalizeKey: replacements.length > 0 ? (raw) => replacements.reduce((text, rule) => text.replace(rule.from, rule.to), raw) : void 0,
|
|
40
|
-
localeInfo: localeInfo ? (code) => {
|
|
41
|
-
const info = localeInfo[code];
|
|
42
|
-
return info ? {
|
|
43
|
-
...info.flag ? { flag: info.flag } : {},
|
|
44
|
-
...info.displayName ? { displayName: info.displayName } : {}
|
|
45
|
-
} : void 0;
|
|
46
|
-
} : void 0
|
|
47
|
-
};
|
|
48
|
-
const plugins = [plugin, ...data.scopes ? [regexScopes(data.scopes.regex, `${data.name}-scopes`)] : []];
|
|
49
|
-
const detect = data.detect;
|
|
50
|
-
if (!detect) return plugins.length === 1 ? plugin : {
|
|
51
|
-
name: data.name,
|
|
52
|
-
plugins
|
|
53
|
-
};
|
|
54
|
-
return {
|
|
55
|
-
name: data.name,
|
|
56
|
-
exclusive: data.exclusive,
|
|
57
|
-
plugins,
|
|
58
|
-
async detect(ctx) {
|
|
59
|
-
const deps = detect.dependencies;
|
|
60
|
-
if (deps?.any && !ctx.hasAnyDependency(deps.any)) return false;
|
|
61
|
-
if (deps?.all && !deps.all.every(ctx.hasDependency)) return false;
|
|
62
|
-
for (const pattern of detect.files ?? []) if (!await ctx.fileExists(pattern)) return false;
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
//#endregion
|
|
68
|
-
export { compileYamlPlugin };
|