Skip to content

Commit

Permalink
typings: add typescript typings
Browse files Browse the repository at this point in the history
Signed-off-by: Sankarsan Kampa <[email protected]>
  • Loading branch information
iamtraction committed May 7, 2020
1 parent dd59a4b commit e1b2c09
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
interface TranslateOption {
/** The language name/ISO 639-1 code to translate from. If none is given, it will auto detect the source language. */
from?: string;
/** The language name/ISO 639-1 code to translate to. If none is given, it will translate to English. */
to?: string;
/** If `true`, it will return the raw output that was received from Google Translate. */
raw?: boolean;
}

interface TranslateResponse {
/** The translated text */
text: string;
from: {
language: {
/** Whether or not the API suggest a correction in the source language. */
didYouMean: boolean;
/** The ISO 639-1 code of the language that the API has recognized in the text. */
iso: string;
};
text: {
/** Whether or not the API has auto corrected the original text. */
autoCorrected: boolean;
/** The auto corrected text or the text with suggested corrections. Only returned if `from.text.autoCorrected` or `from.text.didYouMean` is `true`. */
value: string;
/** Wherether or not the API has suggested corrections to the text. */
didYouMean: boolean;
};
};
/** The raw response from Google Translate servers. Only returned if `options.raw` is `true` in the request options. */
raw: string;
}


/**
* @param {String} text The text you want to translate.
* @param {String} text The options for translating.
*/
declare function translate(text: string, options?: TranslateOption): Promise<TranslateResponse>;

export = translate;

0 comments on commit e1b2c09

Please sign in to comment.