nativtongue-cli 0.0.1 → 0.0.2

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.
@@ -5,6 +5,9 @@ var JSX_TEXT_RE = /<(h[1-6]|p|span|div|li|td|th|label|a|strong|em)(?:\s[^>]*)?>(
5
5
  var ATTR_RE = /(?:aria-label|placeholder|title|alt)=["']([^"']+)["']/g;
6
6
  var SCOPE_RE = /<TranslationScope\s+context=["']([^"']+)["']\s*>/g;
7
7
  var SCOPE_CLOSE_RE = /<\/TranslationScope>/g;
8
+ function normalizeWhitespace(s) {
9
+ return s.replace(/\s+/g, " ").trim();
10
+ }
8
11
  function isTranslatableText(text) {
9
12
  if (!text || text.length < 2) return false;
10
13
  if (text.includes("${")) return false;
@@ -35,33 +38,33 @@ function extractKeysFromSource(source) {
35
38
  return regions.some((r) => pos >= r.start && pos < r.end);
36
39
  }
37
40
  for (const match of source.matchAll(T_FUNCTION_RE)) {
38
- if (!isInScope(match.index)) keys.add(match[1]);
41
+ if (!isInScope(match.index)) keys.add(normalizeWhitespace(match[1]));
39
42
  }
40
43
  for (const match of source.matchAll(JSX_TEXT_RE)) {
41
44
  if (!isInScope(match.index)) {
42
- const text = match[2].trim();
45
+ const text = normalizeWhitespace(match[2]);
43
46
  if (isTranslatableText(text)) keys.add(text);
44
47
  }
45
48
  }
46
49
  for (const match of source.matchAll(ATTR_RE)) {
47
50
  if (!isInScope(match.index)) {
48
- const text = match[1].trim();
51
+ const text = normalizeWhitespace(match[1]);
49
52
  if (isTranslatableText(text)) keys.add(text);
50
53
  }
51
54
  }
52
55
  for (const { scope, start, end } of regions) {
53
56
  const region = source.slice(start, end);
54
57
  for (const match of region.matchAll(T_FUNCTION_RE)) {
55
- keys.add(`${scope}::${match[1]}`);
58
+ keys.add(`${scope}::${normalizeWhitespace(match[1])}`);
56
59
  }
57
60
  for (const match of region.matchAll(JSX_TEXT_RE)) {
58
- const text = match[2].trim();
61
+ const text = normalizeWhitespace(match[2]);
59
62
  if (isTranslatableText(text)) {
60
63
  keys.add(`${scope}::${text}`);
61
64
  }
62
65
  }
63
66
  for (const match of region.matchAll(ATTR_RE)) {
64
- const text = match[1].trim();
67
+ const text = normalizeWhitespace(match[1]);
65
68
  if (isTranslatableText(text)) {
66
69
  keys.add(`${scope}::${text}`);
67
70
  }
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  extractKeysFromFile,
5
5
  isValidLocale,
6
6
  syncLocaleFile
7
- } from "./chunk-QQ3TF54X.js";
7
+ } from "./chunk-AGVUK664.js";
8
8
 
9
9
  // src/cli.ts
10
10
  import fs3 from "fs";
@@ -44,7 +44,7 @@ var VITE_CONFIG_NAMES = [
44
44
  "vite.config.mts",
45
45
  "vite.config.mjs"
46
46
  ];
47
- function init(locales) {
47
+ async function init(locales) {
48
48
  const cwd = process.cwd();
49
49
  if (locales.length === 0) {
50
50
  console.error("[nativtongue] Specify at least one locale: nativtongue init fr es de");
@@ -98,17 +98,24 @@ function init(locales) {
98
98
  fs2.writeFileSync(gitignorePath, "# nativtongue\n.nativtongue/\n");
99
99
  console.log("[nativtongue] Created .gitignore");
100
100
  }
101
+ const srcDir = path.resolve(cwd, "./src");
102
+ console.log("\n[nativtongue] Extracting and translating...");
103
+ await sync({
104
+ srcDir,
105
+ i18nDir,
106
+ locales,
107
+ provider: createClaudeCliProvider()
108
+ });
101
109
  console.log(`
102
- Done! Next steps:
103
- 1. Wrap your root component:
110
+ Done! Wrap your root component:
104
111
 
105
- import { TranslationProvider } from 'nativtongue'
112
+ import { TranslationProvider } from 'nativtongue'
106
113
 
107
- <TranslationProvider defaultLocale="en">
108
- <App />
109
- </TranslationProvider>
114
+ <TranslationProvider defaultLocale="en">
115
+ <App />
116
+ </TranslationProvider>
110
117
 
111
- 2. Start your dev server \u2014 translations sync automatically.
118
+ Start your dev server \u2014 translations sync automatically on save.
112
119
  `);
113
120
  }
114
121
 
@@ -127,23 +134,23 @@ async function main() {
127
134
  const command = process.argv[2];
128
135
  if (!command || command === "help" || command === "--help") {
129
136
  console.log(`
130
- nativtongue \u2014 translation sync CLI
137
+ \u{1F30D} nativtongue
131
138
 
132
- Commands:
133
- init <locales...> Set up nativtongue in your project
134
- Example: nativtongue init fr es de
139
+ Write code. We handle the translations.
135
140
 
136
- sync [options] Extract keys and update translation files
137
- --translate Auto-fill missing translations
138
- --prune Remove stale keys from translation files
141
+ Commands:
142
+ \u{1F680} init fr es de Set up + extract + translate in one shot
143
+ \u{1F50D} sync Extract keys from your source files
144
+ \u{1F916} sync --translate Auto-translate missing keys via Claude
145
+ \u{1F9F9} sync --prune Clean out keys no longer in your code
139
146
 
140
- Translation uses your local Claude Code installation (no API key needed).
147
+ Powered by Claude Code \u2728
141
148
  `);
142
149
  return;
143
150
  }
144
151
  if (command === "init") {
145
152
  const locales = process.argv.slice(3).filter((a) => !a.startsWith("-"));
146
- init(locales);
153
+ await init(locales);
147
154
  return;
148
155
  }
149
156
  if (command === "sync") {
@@ -3,7 +3,7 @@ import {
3
3
  extractKeysFromSource,
4
4
  isValidLocale,
5
5
  syncLocaleFile
6
- } from "./chunk-QQ3TF54X.js";
6
+ } from "./chunk-AGVUK664.js";
7
7
 
8
8
  // src/tongue-sync.ts
9
9
  import fs from "fs";
package/package.json CHANGED
@@ -1,8 +1,24 @@
1
1
  {
2
2
  "name": "nativtongue-cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "CLI and dev tooling for nativtongue — extract, sync, and translate",
5
5
  "license": "MIT",
6
+ "author": "Adah",
7
+ "keywords": [
8
+ "i18n",
9
+ "internationalization",
10
+ "translation",
11
+ "cli",
12
+ "vite-plugin",
13
+ "claude"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/ada-h/nativtongue",
18
+ "directory": "packages/nativtongue-cli"
19
+ },
20
+ "homepage": "https://github.com/ada-h/nativtongue",
21
+ "bugs": "https://github.com/ada-h/nativtongue/issues",
6
22
  "type": "module",
7
23
  "main": "./dist/cli.js",
8
24
  "exports": {
@@ -24,7 +40,7 @@
24
40
  "test": "vitest run"
25
41
  },
26
42
  "dependencies": {
27
- "glob": "^11.0.2"
43
+ "glob": "^13.0.6"
28
44
  },
29
45
  "devDependencies": {
30
46
  "@types/node": "^24.12.2",