@vitalets/google-translate-api
Advanced tools
Comparing version 2.9.0 to 3.0.0
@@ -25,5 +25,4 @@ /** | ||
'ny': 'Chichewa', | ||
'zh': 'Chinese (Simplified)', | ||
'zh-cn': 'Chinese (Simplified)', | ||
'zh-tw': 'Chinese (Traditional)', | ||
'zh-CN': 'Chinese (Simplified)', | ||
'zh-TW': 'Chinese (Traditional)', | ||
'co': 'Corsican', | ||
@@ -121,3 +120,3 @@ 'hr': 'Croatian', | ||
* Returns the ISO 639-1 code of the desiredLang – if it is supported by Google Translate | ||
* @param {string} desiredLang – the name or the code of the desired language | ||
* @param {string} desiredLang – the name or the code(case sensitive) of the desired language | ||
* @returns {string|boolean} The ISO 639-1 code of the language or false if the language is not supported | ||
@@ -129,3 +128,2 @@ */ | ||
} | ||
desiredLang = desiredLang.toLowerCase(); | ||
@@ -141,3 +139,3 @@ if (langs[desiredLang]) { | ||
return langs[key].toLowerCase() === desiredLang; | ||
return langs[key].toLowerCase() === desiredLang.toLowerCase(); | ||
}); | ||
@@ -144,0 +142,0 @@ |
{ | ||
"name": "@vitalets/google-translate-api", | ||
"version": "2.9.0", | ||
"version": "3.0.0", | ||
"description": "A free and unlimited API for Google Translate", | ||
@@ -14,2 +14,8 @@ "main": "index.js", | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "xo", | ||
"pre-push": "npm test" | ||
} | ||
}, | ||
"repository": { | ||
@@ -47,2 +53,3 @@ "type": "git", | ||
"coveralls": "^2.11.11", | ||
"husky": "^3.0.4", | ||
"nyc": "^7.0.0", | ||
@@ -49,0 +56,0 @@ "xo": "^0.16.0" |
@@ -26,2 +26,3 @@ # google-translate-api | ||
- Added support for custom [got](https://github.com/sindresorhus/got) options. It allows to use proxy and bypass request limits (see [#25](https://github.com/vitalets/google-translate-api/pull/25)) | ||
- Added support for language extensions from outside of the API (See [#18](https://github.com/vitalets/google-translate-api/pull/18)) | ||
@@ -86,2 +87,11 @@ ## Install | ||
You can also add languages in the code and use them in the translation: | ||
``` js | ||
translate = require('google-translate-api'); | ||
translate.languages['sr-Latn'] = 'Serbian Latin'; | ||
translate('translator', {to: 'sr-Latn'}).then(res => ...); | ||
``` | ||
## Too many requests | ||
@@ -130,3 +140,3 @@ Google Translate has request limits. If too many requests are made, you can either end up with a 429 or a 503 error. | ||
The `text` language. Must be `auto` or one of the codes/names (not case sensitive) contained in [languages.js](https://github.com/matheuss/google-translate-api/blob/master/languages.js) | ||
The `text` language. Must be `auto` or one of the codes/names (not case sensitive) contained in [languages.js](https://github.com/vitalets/google-translate-api/blob/master/languages.js) | ||
@@ -136,3 +146,3 @@ ##### to | ||
The language in which the text should be translated. Must be one of the codes/names (not case sensitive) contained in [languages.js](https://github.com/matheuss/google-translate-api/blob/master/languages.js). | ||
The language in which the text should be translated. Must be one of the codes/names (case sensitive!) contained in [languages.js](https://github.com/vitalets/google-translate-api/blob/master/languages.js). | ||
@@ -189,2 +199,2 @@ ##### raw | ||
MIT © [Matheus Fernandes](http://matheus.top) forked by [Vitaliy Potapov](https://github.com/vitalets). | ||
MIT © [Matheus Fernandes](http://matheus.top), forked and maintained by [Vitaliy Potapov](https://github.com/vitalets). |
52
test.js
@@ -145,2 +145,10 @@ import test from 'ava'; | ||
test('translate via an external language from outside of the API', async t => { | ||
translate.languages['sr-Latn'] = 'Serbian Latin'; | ||
const res = await translate('translator', {to: 'sr-Latn'}); | ||
t.is(res.text, 'преводилац'); | ||
t.is(res.from.language.iso, 'en'); | ||
}); | ||
test('pass got options', async t => { | ||
@@ -163,1 +171,45 @@ let a = 0; | ||
}); | ||
test('test get zh code', t => { | ||
t.false(languages.getCode('zh')); | ||
}); | ||
test('test get zh-CN code', t => { | ||
t.is(languages.getCode('zh-CN'), 'zh-CN'); | ||
}); | ||
test('test get zh-cn code', t => { | ||
t.false(languages.getCode('zh-cn')); | ||
}); | ||
test('test get zh-TW code', t => { | ||
t.is(languages.getCode('zh-TW'), 'zh-TW'); | ||
}); | ||
test('test get zh-tw code', t => { | ||
t.false(languages.getCode('zh-tw')); | ||
}); | ||
test('test zh unsupported', t => { | ||
t.false(languages.isSupported('zh')); | ||
}); | ||
test('test zh-CN supported', t => { | ||
t.true(languages.isSupported('zh-CN')); | ||
}); | ||
test('test zh-cn unsupported', t => { | ||
t.false(languages.isSupported('zh-cn')); | ||
}); | ||
test('test zh-TW supported', t => { | ||
t.true(languages.isSupported('zh-TW')); | ||
}); | ||
test('test zh-tw unsupported', t => { | ||
t.false(languages.isSupported('zh-tw')); | ||
}); | ||
test('test zh-CN supported – by name', t => { | ||
t.true(languages.isSupported('chinese (simplified)')); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22695
417
196
6