@tuhama/translation-manager 0.4.0 → 0.5.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuhama/translation-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A modern, web-based UI for managing i18n translation files in React and other JavaScript projects.",
|
|
5
5
|
"author": "Tuhama <tuhama.gh.qlyshi@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { TranslationServiceClient } = require('@google-cloud/translate');
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Service for interacting with Google Cloud Translation API v3.
|
|
@@ -24,7 +24,7 @@ class GoogleTranslator {
|
|
|
24
24
|
clientConfig.keyFilename = this.keyFilename;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
this.
|
|
27
|
+
this.client = new TranslationServiceClient(clientConfig);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -52,7 +52,7 @@ class GoogleTranslator {
|
|
|
52
52
|
targetLanguageCode: targetLang,
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
const [response] = await this.
|
|
55
|
+
const [response] = await this.client.translateText(request);
|
|
56
56
|
const translations = response.translations.map(t => t.translatedText);
|
|
57
57
|
|
|
58
58
|
if (Array.isArray(text)) {
|
package/src/server.js
CHANGED
|
@@ -10,7 +10,7 @@ const TranslatorManager = require('./core/TranslatorManager');
|
|
|
10
10
|
function startServer(targetDir, port = 3000, config = {}) {
|
|
11
11
|
const app = express();
|
|
12
12
|
const manager = new TranslatorManager(targetDir, config);
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
app.use(cors());
|
|
15
15
|
app.use(express.json());
|
|
16
16
|
|
|
@@ -66,9 +66,26 @@ function startServer(targetDir, port = 3000, config = {}) {
|
|
|
66
66
|
app.post('/api/translate', async (req, res) => {
|
|
67
67
|
try {
|
|
68
68
|
const { text, targetLang, sourceLang } = req.body;
|
|
69
|
+
|
|
70
|
+
// Check if Google Translate is configured
|
|
71
|
+
if (!manager.config.googleTranslate || !manager.config.googleTranslate.projectId) {
|
|
72
|
+
return res.status(400).json({
|
|
73
|
+
error: 'Google Translate is not configured. Please add your Google Cloud Project ID and key file in Settings.',
|
|
74
|
+
configurationRequired: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
69
78
|
const translatedText = await manager.translateSingle(text, targetLang, sourceLang);
|
|
70
79
|
res.json({ translatedText });
|
|
71
80
|
} catch (err) {
|
|
81
|
+
// Check if it's a configuration error
|
|
82
|
+
if (err.message.includes('Google Cloud Project ID is required') ||
|
|
83
|
+
err.message.includes('Google Translate configuration is missing')) {
|
|
84
|
+
return res.status(400).json({
|
|
85
|
+
error: err.message,
|
|
86
|
+
configurationRequired: true
|
|
87
|
+
});
|
|
88
|
+
}
|
|
72
89
|
res.status(500).json({ error: err.message });
|
|
73
90
|
}
|
|
74
91
|
});
|
|
@@ -86,9 +103,26 @@ function startServer(targetDir, port = 3000, config = {}) {
|
|
|
86
103
|
app.post('/api/bulk-translate/execute', async (req, res) => {
|
|
87
104
|
try {
|
|
88
105
|
const { sourceLang } = req.body;
|
|
106
|
+
|
|
107
|
+
// Check if Google Translate is configured
|
|
108
|
+
if (!manager.config.googleTranslate || !manager.config.googleTranslate.projectId) {
|
|
109
|
+
return res.status(400).json({
|
|
110
|
+
error: 'Google Translate is not configured. Please add your Google Cloud Project ID and key file in Settings.',
|
|
111
|
+
configurationRequired: true
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
89
115
|
const preview = await manager.bulkTranslate(sourceLang || 'en');
|
|
90
116
|
res.json(preview);
|
|
91
117
|
} catch (err) {
|
|
118
|
+
// Check if it's a configuration error
|
|
119
|
+
if (err.message.includes('Google Cloud Project ID is required') ||
|
|
120
|
+
err.message.includes('Google Translate configuration is missing')) {
|
|
121
|
+
return res.status(400).json({
|
|
122
|
+
error: err.message,
|
|
123
|
+
configurationRequired: true
|
|
124
|
+
});
|
|
125
|
+
}
|
|
92
126
|
res.status(500).json({ error: err.message });
|
|
93
127
|
}
|
|
94
128
|
});
|