transduck 0.2.2 → 0.2.3

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/handler.js CHANGED
@@ -30,7 +30,7 @@ export async function handleTranslationRequest(body, configPath) {
30
30
  const translations = {};
31
31
  const plurals = {};
32
32
  // Translate regular strings
33
- for (const item of body.strings) {
33
+ for (const item of body.strings ?? []) {
34
34
  const stringContextHash = hash(item.context ?? '');
35
35
  const key = `${item.text}||${item.context ?? ''}`;
36
36
  // Cache lookup
@@ -70,7 +70,7 @@ export async function handleTranslationRequest(body, configPath) {
70
70
  }
71
71
  }
72
72
  // Translate plurals
73
- for (const item of body.plurals) {
73
+ for (const item of body.plurals ?? []) {
74
74
  const stringContextHash = hash(item.context ?? '');
75
75
  const sourceKey = item.one + '\x00' + item.other;
76
76
  const responseKey = `${sourceKey}||${item.context ?? ''}`;
@@ -122,7 +122,10 @@ export function createTransDuckHandler(configPath) {
122
122
  }
123
123
  catch (err) {
124
124
  console.error('[transduck] Handler error:', err);
125
- return new Response(JSON.stringify({ error: 'Translation failed' }), {
125
+ return new Response(JSON.stringify({
126
+ error: 'Translation failed',
127
+ detail: process.env.NODE_ENV === 'development' ? err?.message : undefined,
128
+ }), {
126
129
  status: 500,
127
130
  headers: { 'Content-Type': 'application/json' },
128
131
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "transduck",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "AI-native translation tool using source text as keys",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/handler.ts CHANGED
@@ -63,7 +63,7 @@ export async function handleTranslationRequest(
63
63
  const plurals: Record<string, Record<string, string>> = {};
64
64
 
65
65
  // Translate regular strings
66
- for (const item of body.strings) {
66
+ for (const item of body.strings ?? []) {
67
67
  const stringContextHash = hash(item.context ?? '');
68
68
  const key = `${item.text}||${item.context ?? ''}`;
69
69
 
@@ -113,7 +113,7 @@ export async function handleTranslationRequest(
113
113
  }
114
114
 
115
115
  // Translate plurals
116
- for (const item of body.plurals) {
116
+ for (const item of body.plurals ?? []) {
117
117
  const stringContextHash = hash(item.context ?? '');
118
118
  const sourceKey = item.one + '\x00' + item.other;
119
119
  const responseKey = `${sourceKey}||${item.context ?? ''}`;
@@ -175,9 +175,12 @@ export function createTransDuckHandler(configPath?: string) {
175
175
  status: 200,
176
176
  headers: { 'Content-Type': 'application/json' },
177
177
  });
178
- } catch (err) {
178
+ } catch (err: any) {
179
179
  console.error('[transduck] Handler error:', err);
180
- return new Response(JSON.stringify({ error: 'Translation failed' }), {
180
+ return new Response(JSON.stringify({
181
+ error: 'Translation failed',
182
+ detail: process.env.NODE_ENV === 'development' ? err?.message : undefined,
183
+ }), {
181
184
  status: 500,
182
185
  headers: { 'Content-Type': 'application/json' },
183
186
  });