@translation-cms/sync 1.2.9 → 1.2.12
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/README.md +304 -151
- package/dist/api.d.ts +79 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +151 -0
- package/dist/api.js.map +1 -0
- package/dist/bin.js +51 -17
- package/dist/bin.js.map +1 -1
- package/dist/commands/init.d.ts +8 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +18 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/pull.d.ts +7 -0
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +15 -2
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/status.d.ts +12 -0
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +16 -0
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/sync.d.ts +10 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +23 -4
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/watch.d.ts +14 -0
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +23 -3
- package/dist/commands/watch.js.map +1 -1
- package/dist/config/config-internals/args.d.ts +11 -0
- package/dist/config/config-internals/args.d.ts.map +1 -0
- package/dist/config/config-internals/args.js +22 -0
- package/dist/config/config-internals/args.js.map +1 -0
- package/dist/config/config-internals/env.d.ts +10 -0
- package/dist/config/config-internals/env.d.ts.map +1 -0
- package/dist/config/config-internals/env.js +35 -0
- package/dist/config/config-internals/env.js.map +1 -0
- package/dist/config/config-internals/file.d.ts +11 -0
- package/dist/config/config-internals/file.d.ts.map +1 -0
- package/dist/config/config-internals/file.js +28 -0
- package/dist/config/config-internals/file.js.map +1 -0
- package/dist/config/config-internals/resolve.d.ts +21 -0
- package/dist/config/config-internals/resolve.d.ts.map +1 -0
- package/dist/config/config-internals/resolve.js +73 -0
- package/dist/config/config-internals/resolve.js.map +1 -0
- package/dist/config/config-internals/root.d.ts +9 -0
- package/dist/config/config-internals/root.d.ts.map +1 -0
- package/dist/config/config-internals/root.js +22 -0
- package/dist/config/config-internals/root.js.map +1 -0
- package/dist/config/config-internals/types.d.ts +83 -0
- package/dist/config/config-internals/types.d.ts.map +1 -0
- package/dist/config/config-internals/types.js +9 -0
- package/dist/config/config-internals/types.js.map +1 -0
- package/dist/config/resolve-config.d.ts +9 -90
- package/dist/config/resolve-config.d.ts.map +1 -1
- package/dist/config/resolve-config.js +7 -123
- package/dist/config/resolve-config.js.map +1 -1
- package/dist/core/api-internals/pull.d.ts +9 -1
- package/dist/core/api-internals/pull.d.ts.map +1 -1
- package/dist/core/api-internals/pull.js +41 -28
- package/dist/core/api-internals/pull.js.map +1 -1
- package/dist/core/api-internals/sync.d.ts +9 -2
- package/dist/core/api-internals/sync.d.ts.map +1 -1
- package/dist/core/api-internals/sync.js +18 -2
- package/dist/core/api-internals/sync.js.map +1 -1
- package/dist/core/cache-internals/format.d.ts +16 -0
- package/dist/core/cache-internals/format.d.ts.map +1 -1
- package/dist/core/cache-internals/format.js +17 -0
- package/dist/core/cache-internals/format.js.map +1 -1
- package/dist/core/cache-internals/params.d.ts.map +1 -1
- package/dist/core/cache-internals/params.js +24 -24
- package/dist/core/cache-internals/params.js.map +1 -1
- package/dist/core/cache-internals/pull.d.ts +12 -0
- package/dist/core/cache-internals/pull.d.ts.map +1 -1
- package/dist/core/cache-internals/pull.js +13 -0
- package/dist/core/cache-internals/pull.js.map +1 -1
- package/dist/core/cache-internals/sync.d.ts +23 -0
- package/dist/core/cache-internals/sync.d.ts.map +1 -1
- package/dist/core/cache-internals/sync.js +33 -0
- package/dist/core/cache-internals/sync.js.map +1 -1
- package/dist/core/cache-internals/types.d.ts +20 -0
- package/dist/core/cache-internals/types.d.ts.map +1 -1
- package/dist/core/scanner-internals/ast.d.ts +23 -5
- package/dist/core/scanner-internals/ast.d.ts.map +1 -1
- package/dist/core/scanner-internals/ast.js +25 -5
- package/dist/core/scanner-internals/ast.js.map +1 -1
- package/dist/core/scanner-internals/file-walker.d.ts +3 -2
- package/dist/core/scanner-internals/file-walker.d.ts.map +1 -1
- package/dist/core/scanner-internals/file-walker.js +10 -12
- package/dist/core/scanner-internals/file-walker.js.map +1 -1
- package/dist/core/scanner-internals/import-resolver.d.ts +9 -1
- package/dist/core/scanner-internals/import-resolver.d.ts.map +1 -1
- package/dist/core/scanner-internals/import-resolver.js +58 -63
- package/dist/core/scanner-internals/import-resolver.js.map +1 -1
- package/dist/core/scanner-internals/key-extractor.d.ts +12 -8
- package/dist/core/scanner-internals/key-extractor.d.ts.map +1 -1
- package/dist/core/scanner-internals/key-extractor.js +125 -97
- package/dist/core/scanner-internals/key-extractor.js.map +1 -1
- package/dist/core/scanner-internals/route-detector.d.ts +16 -8
- package/dist/core/scanner-internals/route-detector.d.ts.map +1 -1
- package/dist/core/scanner-internals/route-detector.js +37 -33
- package/dist/core/scanner-internals/route-detector.js.map +1 -1
- package/dist/core/scanner.d.ts.map +1 -1
- package/dist/core/scanner.js +25 -8
- package/dist/core/scanner.js.map +1 -1
- package/dist/next.d.ts +28 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +65 -0
- package/dist/next.js.map +1 -0
- package/dist/preview/internals/highlight.d.ts +16 -7
- package/dist/preview/internals/highlight.d.ts.map +1 -1
- package/dist/preview/internals/highlight.js +71 -60
- package/dist/preview/internals/highlight.js.map +1 -1
- package/dist/scaffold/intenrals/scaffold.d.ts +17 -0
- package/dist/scaffold/intenrals/scaffold.d.ts.map +1 -1
- package/dist/scaffold/intenrals/scaffold.js +19 -0
- package/dist/scaffold/intenrals/scaffold.js.map +1 -1
- package/package.json +16 -3
package/dist/core/scanner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/core/scanner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC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cms/sync/next';
|
|
6
|
+
*
|
|
7
|
+
* export default withTranslationsCMS(nextConfig, {
|
|
8
|
+
* pullOnBuild: true, // default
|
|
9
|
+
* pullOnDev: true, // default
|
|
10
|
+
* });
|
|
11
|
+
*/
|
|
12
|
+
import type { NextConfig } from 'next';
|
|
13
|
+
export interface TranslationsCMSPluginOptions {
|
|
14
|
+
/** Automatically pull translations on `next build` (default: true) */
|
|
15
|
+
pullOnBuild?: boolean;
|
|
16
|
+
/** Automatically pull translations on `next dev` (default: true) */
|
|
17
|
+
pullOnDev?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Higher-order function that wraps your Next.js config with automatic translation syncing.
|
|
21
|
+
*
|
|
22
|
+
* @param userConfig - Your existing next.config.ts configuration
|
|
23
|
+
* @param pluginOptions - Plugin-specific options
|
|
24
|
+
* @returns Enhanced Next.js configuration with sync hooks
|
|
25
|
+
*/
|
|
26
|
+
export declare function withTranslationsCMS(userConfig: NextConfig | undefined, pluginOptions?: TranslationsCMSPluginOptions): NextConfig;
|
|
27
|
+
export default withTranslationsCMS;
|
|
28
|
+
//# sourceMappingURL=next.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../src/next.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAQvC,MAAM,WAAW,4BAA4B;IACzC,sEAAsE;IACtE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oEAAoE;IACpE,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,UAAU,EAAE,UAAU,GAAG,SAAS,EAClC,aAAa,GAAE,4BAAiC,GACjD,UAAU,CAoDZ;AAED,eAAe,mBAAmB,CAAC"}
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js Plugin for automatic translation sync
|
|
3
|
+
*
|
|
4
|
+
* Usage in next.config.ts:
|
|
5
|
+
* import withTranslationsCMS from '@translation-cms/sync/next';
|
|
6
|
+
*
|
|
7
|
+
* export default withTranslationsCMS(nextConfig, {
|
|
8
|
+
* pullOnBuild: true, // default
|
|
9
|
+
* pullOnDev: true, // default
|
|
10
|
+
* });
|
|
11
|
+
*/
|
|
12
|
+
import { runPull } from './commands/pull.js';
|
|
13
|
+
import { resolveConfig, findProjectRoot, loadConfigFile, } from './config/resolve-config.js';
|
|
14
|
+
/**
|
|
15
|
+
* Higher-order function that wraps your Next.js config with automatic translation syncing.
|
|
16
|
+
*
|
|
17
|
+
* @param userConfig - Your existing next.config.ts configuration
|
|
18
|
+
* @param pluginOptions - Plugin-specific options
|
|
19
|
+
* @returns Enhanced Next.js configuration with sync hooks
|
|
20
|
+
*/
|
|
21
|
+
export function withTranslationsCMS(userConfig, pluginOptions = {}) {
|
|
22
|
+
const { pullOnBuild = true, pullOnDev = true } = pluginOptions;
|
|
23
|
+
let initialized = false;
|
|
24
|
+
// Initialize and run pull if needed
|
|
25
|
+
const initTranslations = async () => {
|
|
26
|
+
if (initialized)
|
|
27
|
+
return;
|
|
28
|
+
initialized = true;
|
|
29
|
+
try {
|
|
30
|
+
const root = findProjectRoot();
|
|
31
|
+
const fileConfig = loadConfigFile(root);
|
|
32
|
+
const config = resolveConfig(root, fileConfig);
|
|
33
|
+
// Only pull if we have valid configuration
|
|
34
|
+
if (config.cmsUrl && config.projectId && config.apiKey) {
|
|
35
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
36
|
+
const shouldPull = (isDev && pullOnDev) || (!isDev && pullOnBuild);
|
|
37
|
+
if (shouldPull) {
|
|
38
|
+
await runPull(root, config, fileConfig, []);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
// Log error but don't fail the build
|
|
44
|
+
// eslint-disable-next-line no-console
|
|
45
|
+
console.warn('Translation sync failed (continuing with build):', error instanceof Error ? error.message : String(error));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
...userConfig,
|
|
50
|
+
webpack: (config, context) => {
|
|
51
|
+
// Run sync on webpack initialization (first build/dev startup)
|
|
52
|
+
if (context.isServer && !initialized) {
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
initTranslations().catch(console.error);
|
|
55
|
+
}
|
|
56
|
+
// Call any existing webpack config if provided
|
|
57
|
+
if (typeof userConfig?.webpack === 'function') {
|
|
58
|
+
return userConfig.webpack(config, context);
|
|
59
|
+
}
|
|
60
|
+
return config;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export default withTranslationsCMS;
|
|
65
|
+
//# sourceMappingURL=next.js.map
|
package/dist/next.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.js","sourceRoot":"","sources":["../src/next.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACH,aAAa,EACb,eAAe,EACf,cAAc,GACjB,MAAM,4BAA4B,CAAC;AASpC;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAC/B,UAAkC,EAClC,gBAA8C,EAAE;IAEhD,MAAM,EAAE,WAAW,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,EAAE,GAAG,aAAa,CAAC;IAE/D,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,oCAAoC;IACpC,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;QAChC,IAAI,WAAW;YAAE,OAAO;QACxB,WAAW,GAAG,IAAI,CAAC;QAEnB,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;YAC/B,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;YACxC,MAAM,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,20 +3,29 @@
|
|
|
3
3
|
* Handles searching for and highlighting elements that display translations.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Find and highlight DOM elements that display the given translation.
|
|
6
|
+
* Find and highlight all DOM elements that display the given translation.
|
|
7
7
|
*
|
|
8
|
-
* Search order:
|
|
9
|
-
* 0. data-cms-key attribute
|
|
8
|
+
* Search order (first strategy that yields a match wins):
|
|
9
|
+
* 0. `data-cms-key` attribute — precise, skips all heuristics
|
|
10
10
|
* 1. Exact text node match
|
|
11
|
-
* 2. Element content match
|
|
12
|
-
* 3. Normalized text node
|
|
11
|
+
* 2. Element content match — handles text split across siblings
|
|
12
|
+
* 3. Normalized text node — strips `{{interpolation}}` placeholders
|
|
13
13
|
* 4. Normalized element match
|
|
14
|
-
* 5. Key fallback
|
|
14
|
+
* 5. Key fallback — used when `value` is empty (i18next renders the key)
|
|
15
15
|
*/
|
|
16
16
|
export declare function highlightTranslationKey(value: string, key: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Remove the highlight class from all currently highlighted elements and
|
|
19
|
+
* reset the associated state (element list + search value).
|
|
20
|
+
*/
|
|
17
21
|
export declare function clearHighlights(): void;
|
|
18
22
|
/**
|
|
19
|
-
*
|
|
23
|
+
* Patch the live text of highlighted elements as the user types a new
|
|
24
|
+
* translation value in the CMS panel.
|
|
25
|
+
*
|
|
26
|
+
* Searches each highlighted element's text nodes for the old value (or the
|
|
27
|
+
* last live value if the user is already mid-edit) and replaces it in place —
|
|
28
|
+
* no DOM re-render needed.
|
|
20
29
|
*/
|
|
21
30
|
export declare function updateLiveText(oldValue: string, newValue: string): void;
|
|
22
31
|
//# sourceMappingURL=highlight.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["../../../src/preview/internals/highlight.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["../../../src/preview/internals/highlight.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2EH;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAoDxE;AAiBD;;;GAGG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAKtC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAoBvE"}
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
* Handles searching for and highlighting elements that display translations.
|
|
4
4
|
*/
|
|
5
5
|
import * as state from './state.js';
|
|
6
|
+
/**
|
|
7
|
+
* Strip interpolation placeholders (`{{var}}` and `{var}`) and collapse
|
|
8
|
+
* whitespace so that translated strings with variables can still be matched
|
|
9
|
+
* against the rendered text in the DOM.
|
|
10
|
+
*/
|
|
6
11
|
function normalizeForSearch(value) {
|
|
7
12
|
return value
|
|
8
13
|
.replace(/\{\{[^}]+\}\}/g, '')
|
|
@@ -11,57 +16,64 @@ function normalizeForSearch(value) {
|
|
|
11
16
|
.trim();
|
|
12
17
|
}
|
|
13
18
|
/**
|
|
14
|
-
* Strategy 0 (precise): find elements with data-cms-key="key" attribute.
|
|
15
|
-
* When present
|
|
19
|
+
* Strategy 0 (precise): find elements with `data-cms-key="<key>"` attribute.
|
|
20
|
+
* When present this is always preferred over text-content heuristics.
|
|
16
21
|
*/
|
|
17
22
|
function findByDataAttribute(key) {
|
|
18
23
|
return Array.from(document.querySelectorAll(`[data-cms-key="${CSS.escape(key)}"]`));
|
|
19
24
|
}
|
|
20
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Strategy 1: walk all text nodes in the document body and return the parent
|
|
27
|
+
* element of each node whose text includes `searchValue`.
|
|
28
|
+
* Excludes elements that are already highlighted to avoid double-wrapping.
|
|
29
|
+
*/
|
|
21
30
|
function findByTextNodes(searchValue) {
|
|
22
31
|
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null);
|
|
23
32
|
const results = [];
|
|
24
33
|
let node;
|
|
25
34
|
while ((node = walker.nextNode())) {
|
|
26
|
-
if (node.textContent?.includes(searchValue))
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
35
|
+
if (!node.textContent?.includes(searchValue))
|
|
36
|
+
continue;
|
|
37
|
+
const el = node.parentElement;
|
|
38
|
+
if (el && !el.classList.contains('cms-preview-highlight'))
|
|
39
|
+
results.push(el);
|
|
32
40
|
}
|
|
33
41
|
return results;
|
|
34
42
|
}
|
|
35
43
|
/**
|
|
36
|
-
* Strategy 2: find the most specific element
|
|
37
|
-
*
|
|
44
|
+
* Strategy 2: find the most specific (shortest textContent) element in the
|
|
45
|
+
* document whose combined `textContent` includes `searchValue`.
|
|
46
|
+
*
|
|
47
|
+
* This works when the translated string is split across sibling text nodes,
|
|
48
|
+
* which the text-node walker cannot detect.
|
|
38
49
|
*/
|
|
39
50
|
function findByElementContent(searchValue) {
|
|
40
51
|
const all = Array.from(document.body.querySelectorAll('*'));
|
|
41
52
|
let best = null;
|
|
42
53
|
let bestLen = Infinity;
|
|
43
54
|
for (const el of all) {
|
|
44
|
-
if (el.textContent?.includes(searchValue)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
if (!el.textContent?.includes(searchValue))
|
|
56
|
+
continue;
|
|
57
|
+
if (el.classList.contains('cms-preview-highlight'))
|
|
58
|
+
continue;
|
|
59
|
+
const len = el.textContent.length;
|
|
60
|
+
if (len < bestLen) {
|
|
61
|
+
bestLen = len;
|
|
62
|
+
best = el;
|
|
51
63
|
}
|
|
52
64
|
}
|
|
53
65
|
return best ? [best] : [];
|
|
54
66
|
}
|
|
55
67
|
/**
|
|
56
|
-
* Find and highlight DOM elements that display the given translation.
|
|
68
|
+
* Find and highlight all DOM elements that display the given translation.
|
|
57
69
|
*
|
|
58
|
-
* Search order:
|
|
59
|
-
* 0. data-cms-key attribute
|
|
70
|
+
* Search order (first strategy that yields a match wins):
|
|
71
|
+
* 0. `data-cms-key` attribute — precise, skips all heuristics
|
|
60
72
|
* 1. Exact text node match
|
|
61
|
-
* 2. Element content match
|
|
62
|
-
* 3. Normalized text node
|
|
73
|
+
* 2. Element content match — handles text split across siblings
|
|
74
|
+
* 3. Normalized text node — strips `{{interpolation}}` placeholders
|
|
63
75
|
* 4. Normalized element match
|
|
64
|
-
* 5. Key fallback
|
|
76
|
+
* 5. Key fallback — used when `value` is empty (i18next renders the key)
|
|
65
77
|
*/
|
|
66
78
|
export function highlightTranslationKey(value, key) {
|
|
67
79
|
clearHighlights();
|
|
@@ -76,66 +88,66 @@ export function highlightTranslationKey(value, key) {
|
|
|
76
88
|
const hasInterpolation = value ? normalized !== value : false;
|
|
77
89
|
const candidates = [];
|
|
78
90
|
if (value && value.trim() !== '') {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
fn: findByElementContent,
|
|
83
|
-
});
|
|
91
|
+
// Primary: match on the raw translation value
|
|
92
|
+
candidates.push({ label: 'exact text node', search: value, fn: findByTextNodes }, { label: 'element content', search: value, fn: findByElementContent });
|
|
93
|
+
// Secondary: also try the normalized form when the value contains interpolations
|
|
84
94
|
if (hasInterpolation && normalized) {
|
|
85
|
-
candidates.push({
|
|
86
|
-
label: 'normalized text node',
|
|
87
|
-
search: normalized,
|
|
88
|
-
fn: findByTextNodes,
|
|
89
|
-
}, {
|
|
90
|
-
label: 'normalized element',
|
|
91
|
-
search: normalized,
|
|
92
|
-
fn: findByElementContent,
|
|
93
|
-
});
|
|
95
|
+
candidates.push({ label: 'normalized text node', search: normalized, fn: findByTextNodes }, { label: 'normalized element', search: normalized, fn: findByElementContent });
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
else {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
candidates.push({ label: 'key (full)', search: key, fn: findByTextNodes }, { label: 'key (no ns)', search: keyWithoutNs, fn: findByTextNodes }, { label: 'key element', search: key, fn: findByElementContent }, {
|
|
101
|
-
label: 'key element (no ns)',
|
|
102
|
-
search: keyWithoutNs,
|
|
103
|
-
fn: findByElementContent,
|
|
104
|
-
});
|
|
99
|
+
// Value is empty — i18next falls back to rendering the key itself as text
|
|
100
|
+
const keyWithoutNs = key.includes(':') ? key.split(':').slice(1).join(':') : key;
|
|
101
|
+
candidates.push({ label: 'key (full)', search: key, fn: findByTextNodes }, { label: 'key (no ns)', search: keyWithoutNs, fn: findByTextNodes }, { label: 'key element', search: key, fn: findByElementContent }, { label: 'key element (no ns)', search: keyWithoutNs, fn: findByElementContent });
|
|
105
102
|
}
|
|
106
103
|
for (const { label, search, fn } of candidates) {
|
|
107
104
|
const found = fn(search);
|
|
108
|
-
if (found.length
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
if (found.length === 0)
|
|
106
|
+
continue;
|
|
107
|
+
state.setCurrentSearchValue(search);
|
|
108
|
+
applyHighlights(found, label);
|
|
109
|
+
return;
|
|
113
110
|
}
|
|
114
111
|
console.warn(`[CMS Preview] No elements found for key: "${key}" value: "${value}"`);
|
|
115
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Add the highlight CSS class to each element and scroll the first one into
|
|
115
|
+
* view. Registers elements with the state module so `clearHighlights` can
|
|
116
|
+
* remove them later.
|
|
117
|
+
*/
|
|
116
118
|
function applyHighlights(elements, matchLabel) {
|
|
117
119
|
console.log(`[CMS Preview] Highlighting ${elements.length} element(s) via ${matchLabel}`);
|
|
118
|
-
elements.
|
|
120
|
+
for (let i = 0; i < elements.length; i++) {
|
|
121
|
+
const el = elements[i];
|
|
119
122
|
el.classList.add('cms-preview-highlight');
|
|
120
123
|
state.addHighlightedElement(el);
|
|
121
|
-
if (i === 0)
|
|
124
|
+
if (i === 0)
|
|
122
125
|
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
123
|
-
|
|
124
|
-
});
|
|
126
|
+
}
|
|
125
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Remove the highlight class from all currently highlighted elements and
|
|
130
|
+
* reset the associated state (element list + search value).
|
|
131
|
+
*/
|
|
126
132
|
export function clearHighlights() {
|
|
127
|
-
for (const el of state.highlightedElements)
|
|
133
|
+
for (const el of state.highlightedElements)
|
|
128
134
|
el.classList.remove('cms-preview-highlight');
|
|
129
|
-
}
|
|
130
135
|
state.setHighlightedElements([]);
|
|
131
136
|
state.setCurrentSearchValue(null);
|
|
132
137
|
}
|
|
133
138
|
/**
|
|
134
|
-
*
|
|
139
|
+
* Patch the live text of highlighted elements as the user types a new
|
|
140
|
+
* translation value in the CMS panel.
|
|
141
|
+
*
|
|
142
|
+
* Searches each highlighted element's text nodes for the old value (or the
|
|
143
|
+
* last live value if the user is already mid-edit) and replaces it in place —
|
|
144
|
+
* no DOM re-render needed.
|
|
135
145
|
*/
|
|
136
146
|
export function updateLiveText(oldValue, newValue) {
|
|
137
147
|
if (state.highlightedElements.length === 0)
|
|
138
148
|
return;
|
|
149
|
+
// Prefer the last live value so repeated keystrokes replace the previous
|
|
150
|
+
// intermediate value rather than the original translation
|
|
139
151
|
const searchFor = state.currentLiveValue ??
|
|
140
152
|
(oldValue || state.currentSearchValue) ??
|
|
141
153
|
oldValue;
|
|
@@ -143,9 +155,8 @@ export function updateLiveText(oldValue, newValue) {
|
|
|
143
155
|
const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null);
|
|
144
156
|
let node;
|
|
145
157
|
while ((node = walker.nextNode())) {
|
|
146
|
-
if (node.nodeValue?.includes(searchFor))
|
|
158
|
+
if (node.nodeValue?.includes(searchFor))
|
|
147
159
|
node.nodeValue = node.nodeValue.replace(searchFor, newValue);
|
|
148
|
-
}
|
|
149
160
|
}
|
|
150
161
|
}
|
|
151
162
|
state.setCurrentLiveValue(newValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"highlight.js","sourceRoot":"","sources":["../../../src/preview/internals/highlight.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,SAAS,kBAAkB,CAAC,KAAa;IACrC,OAAO,KAAK;SACP,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;SACzB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,GAAW;IACpC,OAAO,KAAK,CAAC,IAAI,CACb,QAAQ,CAAC,gBAAgB,CACrB,kBAAkB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CACxC,CACJ,CAAC;AACN,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"highlight.js","sourceRoot":"","sources":["../../../src/preview/internals/highlight.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,KAAa;IACrC,OAAO,KAAK;SACP,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;SACzB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,GAAW;IACpC,OAAO,KAAK,CAAC,IAAI,CACb,QAAQ,CAAC,gBAAgB,CACrB,kBAAkB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CACxC,CACJ,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,WAAmB;IACxC,MAAM,MAAM,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,S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,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -3,5 +3,22 @@
|
|
|
3
3
|
* Creates i18n configuration files and dictionary placeholders.
|
|
4
4
|
*/
|
|
5
5
|
import { ScaffoldOptions, ScaffoldResult } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Generate the i18n boilerplate inside `opts.i18nDir` (e.g. `src/lib/i18n/`).
|
|
8
|
+
*
|
|
9
|
+
* Writes five TypeScript modules and two placeholder JSON dictionaries:
|
|
10
|
+
* - `settings.ts` — locale list, default locale, namespace config
|
|
11
|
+
* - `types.ts` — shared `I18nKey` type and locale type
|
|
12
|
+
* - `client.ts` — `useTranslation` re-export for client components
|
|
13
|
+
* - `server.ts` — `getTranslation` helper for server components
|
|
14
|
+
* - `provider.tsx` — `<I18nProvider>` wrapper component
|
|
15
|
+
* - `dictionaries/en.json` — empty English dictionary placeholder
|
|
16
|
+
* - `dictionaries/nl.json` — empty Dutch dictionary placeholder
|
|
17
|
+
*
|
|
18
|
+
* Existing files are skipped unless `overwrite: true` is set, so re-running
|
|
19
|
+
* the command after the user has edited their i18n setup is safe by default.
|
|
20
|
+
*
|
|
21
|
+
* @returns Lists of written and skipped relative paths for CLI reporting.
|
|
22
|
+
*/
|
|
6
23
|
export declare function scaffoldI18n(opts: ScaffoldOptions): ScaffoldResult;
|
|
7
24
|
//# sourceMappingURL=scaffold.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../../src/scaffold/intenrals/scaffold.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7D,wBAAgB,YAAY,CAAC,IAAI,EAAE,eAAe,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../../src/scaffold/intenrals/scaffold.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,eAAe,GAAG,cAAc,CAgClE"}
|
|
@@ -5,9 +5,27 @@
|
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { SETTINGS_TS, TYPES_TS, CLIENT_TS, SERVER_TS, PROVIDER_TSX, PLACEHOLDER_DICT, } from './templates.js';
|
|
8
|
+
/**
|
|
9
|
+
* Generate the i18n boilerplate inside `opts.i18nDir` (e.g. `src/lib/i18n/`).
|
|
10
|
+
*
|
|
11
|
+
* Writes five TypeScript modules and two placeholder JSON dictionaries:
|
|
12
|
+
* - `settings.ts` — locale list, default locale, namespace config
|
|
13
|
+
* - `types.ts` — shared `I18nKey` type and locale type
|
|
14
|
+
* - `client.ts` — `useTranslation` re-export for client components
|
|
15
|
+
* - `server.ts` — `getTranslation` helper for server components
|
|
16
|
+
* - `provider.tsx` — `<I18nProvider>` wrapper component
|
|
17
|
+
* - `dictionaries/en.json` — empty English dictionary placeholder
|
|
18
|
+
* - `dictionaries/nl.json` — empty Dutch dictionary placeholder
|
|
19
|
+
*
|
|
20
|
+
* Existing files are skipped unless `overwrite: true` is set, so re-running
|
|
21
|
+
* the command after the user has edited their i18n setup is safe by default.
|
|
22
|
+
*
|
|
23
|
+
* @returns Lists of written and skipped relative paths for CLI reporting.
|
|
24
|
+
*/
|
|
8
25
|
export function scaffoldI18n(opts) {
|
|
9
26
|
const { i18nDir, overwrite = false } = opts;
|
|
10
27
|
const dictsDir = path.join(i18nDir, 'dictionaries');
|
|
28
|
+
// Ensure both the i18n root and the dictionaries sub-directory exist
|
|
11
29
|
fs.mkdirSync(dictsDir, { recursive: true });
|
|
12
30
|
const files = [
|
|
13
31
|
{ rel: 'settings.ts', content: SETTINGS_TS },
|
|
@@ -22,6 +40,7 @@ export function scaffoldI18n(opts) {
|
|
|
22
40
|
const skipped = [];
|
|
23
41
|
for (const { rel, content } of files) {
|
|
24
42
|
const abs = path.join(i18nDir, rel);
|
|
43
|
+
// Skip files that already exist unless the caller explicitly asked to overwrite
|
|
25
44
|
if (fs.existsSync(abs) && !overwrite) {
|
|
26
45
|
skipped.push(rel);
|
|
27
46
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../../../src/scaffold/intenrals/scaffold.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACH,WAAW,EACX,QAAQ,EACR,SAAS,EACT,SAAS,EACT,YAAY,EACZ,gBAAgB,GACnB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,UAAU,YAAY,CAAC,IAAqB;IAC9C,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;IAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAEpD,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE5C,MAAM,KAAK,GAA4C;QACnD,EAAE,GAAG,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../../../src/scaffold/intenrals/scaffold.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACH,WAAW,EACX,QAAQ,EACR,SAAS,EACT,SAAS,EACT,YAAY,EACZ,gBAAgB,GACnB,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAAC,IAAqB;I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C;IACtB,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@translation-cms/sync",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
4
4
|
"description": "Scan translation keys in your codebase and sync them to the Translations CMS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,11 +15,20 @@
|
|
|
15
15
|
"./preview": {
|
|
16
16
|
"import": "./dist/preview.js",
|
|
17
17
|
"types": "./dist/preview.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./next": {
|
|
20
|
+
"import": "./dist/next.js",
|
|
21
|
+
"types": "./dist/next.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./api": {
|
|
24
|
+
"import": "./dist/api.js",
|
|
25
|
+
"types": "./dist/api.d.ts"
|
|
18
26
|
}
|
|
19
27
|
},
|
|
20
28
|
"files": [
|
|
21
29
|
"dist",
|
|
22
|
-
"schema.json"
|
|
30
|
+
"schema.json",
|
|
31
|
+
"next.d.ts"
|
|
23
32
|
],
|
|
24
33
|
"scripts": {
|
|
25
34
|
"build": "tsc",
|
|
@@ -36,11 +45,15 @@
|
|
|
36
45
|
"author": "",
|
|
37
46
|
"license": "MIT",
|
|
38
47
|
"peerDependencies": {
|
|
39
|
-
"react": ">=18"
|
|
48
|
+
"react": ">=18",
|
|
49
|
+
"next": ">=14"
|
|
40
50
|
},
|
|
41
51
|
"peerDependenciesMeta": {
|
|
42
52
|
"react": {
|
|
43
53
|
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"next": {
|
|
56
|
+
"optional": true
|
|
44
57
|
}
|
|
45
58
|
},
|
|
46
59
|
"devDependencies": {
|