Skip to content

Commit 750ba1f

Browse files
committed
#2 add email option
1 parent 0204a21 commit 750ba1f

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aem-polyglot",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "translate i18n dictionairies with ease using Google Translate. Tool designed mainly for developers. ",
55
"repository": "https://github.com/zietas/aem-polyglot",
66
"main": "src/index.js",

src/commands/translateCommand.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ async function translateCommand (source, target, options) {
1616
const CurrentTranslationService = TranslateServiceFactory(options.service);
1717
const translationService = new CurrentTranslationService(apiKey);
1818
const translateDictionaryService = new TranslateDictionaryService(translationService, {
19-
keys: options.keys
19+
keys: options.keys,
20+
email: options.email || ''
2021
});
2122

2223
let translatedDict = await translateDictionaryService.translate(sourceDict, targetDict);

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ program
4646
.option('--service <service>', 'Translation Service, Yandex default')
4747
.option('--apiKey <key>', 'Translation Service API Key')
4848
.option('--keys <key>', 'A comma separated list of dictionaries keys. I.e. --keys=key1,key2,key3')
49+
.option('--email <email>', 'Adds an email address to query')
4950
.action(translateCommand);
5051

5152
program
@@ -55,6 +56,7 @@ program
5556
.option('--service <service>', 'Translation Service, Yandex default')
5657
.option('--apiKey <key>', 'Translation Service API Key')
5758
.option('--keys <key>', 'A comma separated list of dictionaries keys. I.e. --keys=key1,key2,key3')
59+
.option('--email <email>', 'Adds an email address to query')
5860
.action(translateBatchCommand);
5961

6062
program

src/translate/MyMemoryTranslateService.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const dictionaryService = require('../dictionaryService');
66
const API = 'https://api.mymemory.translated.net/get';
77

88
class MyMemoryTranslateService extends TranslateService {
9-
async translate (key, text, from, to) {
9+
async translate (key, text, from, to, options) {
1010
return new Promise((resolve, reject) => {
1111
this.log.addEntry(key, from, text);
1212

13-
const URL = this.getUrl(this.getParams(text, from, to));
13+
const URL = this.getUrl(this.getParams(text, from, to, options.email));
1414

1515
fetch(URL)
1616
.then(data => data.json())
@@ -27,12 +27,16 @@ class MyMemoryTranslateService extends TranslateService {
2727
return `${API}?${params}`;
2828
}
2929

30-
getParams (text, from, to) {
30+
getParams (text, from, to, email = '') {
3131
const params = new URLSearchParams();
3232

3333
params.append('q', text);
3434
params.append('langpair', `${from}|${to}`);
3535

36+
if (email) {
37+
params.append('de', email)
38+
}
39+
3640
return params.toString();
3741
}
3842
}

src/translate/TranslateDictionaryService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TranslateDictionaryService {
3636
for (const key of keysToTranslate) {
3737
try {
3838
const value = sourceEntries[key]['_attributes']['sling:message'];
39-
targetDictionary['jcr:root'][key] = await this.translateService.translate(key, value, sourceLang, targetLang);
39+
targetDictionary['jcr:root'][key] = await this.translateService.translate(key, value, sourceLang, targetLang, this.options);
4040
} catch (e) {
4141
reject(e);
4242
}

0 commit comments

Comments
 (0)