Skip to content

Commit

Permalink
- fixes microsoft translation by providing api region (#3)
Browse files Browse the repository at this point in the history
* - fixes microsoft translation by providing api region

* - builds
  • Loading branch information
baywet committed Sep 2, 2020
1 parent 865e6b6 commit 7c9ad76
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 148 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Identifier is `microsoft`.
#### How to get API key
Please follow the steps described in [this](https://docs.microsoft.com/en-us/azure/cognitive-services/translator/translator-text-how-to-signup) article.

You will also need to provide the region of the key using the `api_additional_parameter` eg

```YAML
with:
api_additional_parameter: canadacentral
```
### MyMemory
Identifier is `mymemory`.
#### Supported translation directions
Expand Down
9 changes: 5 additions & 4 deletions __tests__/test-providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ const fixture = [{
name: 'linguatools',
apiKey: null,
lang: 'en-de'
}, /* Disable it as current API key is not valid anymore */ /*{
}, /* {
title: 'Microsoft',
name: 'microsoft',
apiKey: process.env.MICROSOFT_API_KEY,
addParam: 'canadacentral',
lang: 'nl'
},*/ {
}, */ {
title: 'MyMemory (Free)',
name: 'mymemory',
apiKey: null,
Expand All @@ -33,14 +34,14 @@ const fixture = [{
describe('Provider tests', () => {
itParam('${value.title} should get correct translation', fixture, async (arg) => {
const translate = require(`../src/providers/${arg.name}`);
const translations = await translate(arg.apiKey, 'Evening', arg.lang);
const translations = await translate(arg.apiKey, 'Evening', arg.lang, arg.addParam);
assert(translations.length > 0);
});

itParam('${value.title} should fail because of invalid lang', fixture, async (arg) => {
const translate = require(`../src/providers/${arg.name}`);
try {
await translate(arg.apiKey, 'Evening', 'abc123');
await translate(arg.apiKey, 'Evening', 'abc123', arg.addParam);
} catch (e) {
assert.isNotNull(e);
return;
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ inputs:
description: 'API key that should be used for chosen provider.'
required: false
default: null
api_additional_parameter:
description: 'Additional parameter for the API. eg the region for Microsoft: canadacentral.'
required: false
default: null
lang:
description: 'The translation direction. Should be one of the option proposed by chosen provider.'
required: true
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

Loading

0 comments on commit 7c9ad76

Please sign in to comment.