Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: plainheart/bing-translate-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.0.0
Choose a base ref
...
head repository: plainheart/bing-translate-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 17 commits
  • 12 files changed
  • 3 contributors

Commits on Jan 27, 2024

  1. Copy the full SHA
    ed435ca View commit details

Commits on Feb 14, 2024

  1. chore: update README.md

    plainheart committed Feb 14, 2024
    Copy the full SHA
    7ec9cbb View commit details

Commits on Mar 11, 2024

  1. Copy the full SHA
    0ea8926 View commit details
  2. Copy the full SHA
    8f45520 View commit details
  3. Merge pull request #37 from suejon/master

    fix:index.d.ts: remove nested declare modifier for TS1038
    plainheart authored Mar 11, 2024
    Copy the full SHA
    ec60bd1 View commit details

Commits on Mar 13, 2024

  1. chore: fix comment

    plainheart committed Mar 13, 2024
    Copy the full SHA
    0cdcb5c View commit details
  2. release: v4.0.1

    plainheart committed Mar 13, 2024
    Copy the full SHA
    2187d1f View commit details

Commits on May 21, 2024

  1. Copy the full SHA
    615d09a View commit details

Commits on May 23, 2024

  1. release: v4.0.2

    plainheart committed May 23, 2024
    Copy the full SHA
    5849e65 View commit details

Commits on May 26, 2024

  1. Copy the full SHA
    59da6e0 View commit details

Commits on Jun 24, 2024

  1. Copy the full SHA
    bd8c853 View commit details

Commits on Aug 11, 2024

  1. Copy the full SHA
    f52d25f View commit details

Commits on Nov 3, 2024

  1. Copy the full SHA
    8bdbf27 View commit details

Commits on Dec 8, 2024

  1. Copy the full SHA
    1262da4 View commit details

Commits on Jan 9, 2025

  1. fix config generator

    plainheart committed Jan 9, 2025
    Copy the full SHA
    de1a8c3 View commit details
  2. Copy the full SHA
    d7625ae View commit details

Commits on Apr 17, 2025

  1. Copy the full SHA
    eda35b7 View commit details
Showing with 129 additions and 30 deletions.
  1. +1 −1 LICENSE
  2. +1 −6 README.md
  3. +52 −4 index.d.ts
  4. +2 −2 package-lock.json
  5. +1 −1 package.json
  6. +5 −5 scripts/generate-config.js
  7. +4 −4 scripts/index.tpl.d.ts
  8. +1 −1 src/index.js
  9. +46 −0 src/lang.json
  10. +4 −6 src/met/README.md
  11. +2 −0 src/met/lang.json
  12. +10 −0 test/index.js
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2024 Zhongxiang Wang(plainheart)
Copyright (c) 2021-2025 Zhongxiang Wang(plainheart)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -119,13 +119,8 @@ Set [agents](https://github.com/sindresorhus/got/blob/main/documentation/tips.md

## License

MIT © 2021-2024 [plainheart](https://github.com/plainheart).
MIT © 2021-2025 [plainheart](https://github.com/plainheart).

## Thanks

Great thanks to [Bing Translator](https://bing.com/translator) for providing such an excellent translation service.

## Related Projects
- [Capacitor Bing Translator](https://github.com/sabereen/capacitor-bing-translator) - A fork of this project that works in [Capacitor](https://capacitorjs.com).
- [bing-translate-api-java](https://github.com/marmot-z/bing-translate-api-java) - Bing translate API implemented in Java.
- [i18n-translate-generator](https://github.com/victor-heliomar/i18n-translation-generator) - CLI tool that automates the generation of localizations for all languages supported in your project.
56 changes: 52 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -29,15 +29,15 @@ export interface TranslationResult {
/**
* The detected language code of original text
*/
from: string;
from?: string;
/**
* The language code of translated text
*/
to: string;
/**
* The score of language detection
*/
score: number;
score?: number;
};
/**
* The original response from Bing translator
@@ -68,26 +68,37 @@ export declare function translate(
export declare namespace lang {
const LANGS: {
'auto-detect': 'Auto-detect',
'ace': 'Acehnese (Latin)',
'af': 'Afrikaans',
'sq': 'Albanian',
'am': 'Amharic',
'ar': 'Arabic',
'arz': 'Arabic (Egyptian)',
'ary': 'Arabic (Moroccan)',
'arb': 'Arabic (Romanized)',
'hy': 'Armenian',
'as': 'Assamese',
'ast': 'Asturian',
'az': 'Azerbaijani',
'ban': 'Balinese',
'bn': 'Bangla',
'ba': 'Bashkir',
'eu': 'Basque',
'bbc': 'Batak Toba',
'be': 'Belarusian',
'bho': 'Bhojpuri',
'bik': 'Bikol',
'brx': 'Bodo',
'bs': 'Bosnian',
'bg': 'Bulgarian',
'yue': 'Cantonese (Traditional)',
'ca': 'Catalan',
'ceb': 'Cebuano',
'hne': 'Chhattisgarhi',
'lzh': 'Chinese (Literary)',
'zh-Hans': 'Chinese Simplified',
'zh-Hant': 'Chinese Traditional',
'co': 'Corsican',
'hr': 'Croatian',
'cs': 'Czech',
'da': 'Danish',
@@ -96,13 +107,17 @@ export declare namespace lang {
'doi': 'Dogri',
'nl': 'Dutch',
'en': 'English',
'en-GB': 'English (United Kingdom)',
'epo': 'Esperanto',
'et': 'Estonian',
'fo': 'Faroese',
'fj': 'Fijian',
'fil': 'Filipino',
'fi': 'Finnish',
'fr': 'French',
'fr-CA': 'French (Canada)',
'fy': 'Frisian',
'fur': 'Friulian',
'gl': 'Galician',
'lug': 'Ganda',
'ka': 'Georgian',
@@ -112,81 +127,109 @@ export declare namespace lang {
'ht': 'Haitian Creole',
'ha': 'Hausa',
'he': 'Hebrew',
'hil': 'Hiligaynon',
'hi': 'Hindi',
'mww': 'Hmong Daw',
'hu': 'Hungarian',
'iba': 'Iban',
'is': 'Icelandic',
'ig': 'Igbo',
'ilo': 'Ilocano',
'id': 'Indonesian',
'ikt': 'Inuinnaqtun',
'iu': 'Inuktitut',
'iu-Latn': 'Inuktitut (Latin)',
'ga': 'Irish',
'it': 'Italian',
'jam': 'Jamaican Patois',
'ja': 'Japanese',
'jav': 'Javanese',
'kea': 'Kabuverdianu',
'kn': 'Kannada',
'pam': 'Kapampangan',
'ks': 'Kashmiri',
'kk': 'Kazakh',
'km': 'Khmer',
'rw': 'Kinyarwanda',
'tlh-Latn': 'Klingon (Latin)',
'gom': 'Konkani',
'ko': 'Korean',
'kri': 'Krio',
'ku': 'Kurdish (Central)',
'kmr': 'Kurdish (Northern)',
'ky': 'Kyrgyz',
'lo': 'Lao',
'la': 'Latin',
'lv': 'Latvian',
'lij': 'Ligurian (Genoese)',
'lim': 'Limburgish',
'ln': 'Lingala',
'lt': 'Lithuanian',
'lmo': 'Lombard',
'dsb': 'Lower Sorbian',
'lb': 'Luxembourgish',
'mk': 'Macedonian',
'mai': 'Maithili',
'mg': 'Malagasy',
'ms': 'Malay',
'ml': 'Malayalam',
'mt': 'Maltese',
'mr': 'Marathi',
'mwr': 'Marwari',
'mfe': 'Mauritian Creole',
'min': 'Minangkabau (Latin)',
'mn-Cyrl': 'Mongolian (Cyrillic)',
'mn-Mong': 'Mongolian (Traditional)',
'my': 'Myanmar (Burmese)',
'mi': 'Māori',
'ne': 'Nepali',
'nb': 'Norwegian',
'nno': 'Norwegian Nynorsk',
'nya': 'Nyanja',
'oc': 'Occitan',
'or': 'Odia',
'pap': 'Papiamento',
'ps': 'Pashto',
'fa': 'Persian',
'pl': 'Polish',
'pt': 'Portuguese (Brazil)',
'pt-PT': 'Portuguese (Portugal)',
'pa': 'Punjabi',
'pnb': 'Punjabi (Shahmukhi)',
'otq': 'Querétaro Otomi',
'ro': 'Romanian',
'run': 'Rundi',
'ru': 'Russian',
'sm': 'Samoan',
'sa': 'Sanskrit',
'srd': 'Sardinian',
'sr-Cyrl': 'Serbian (Cyrillic)',
'sr-Latn': 'Serbian (Latin)',
'st': 'Sesotho',
'nso': 'Sesotho sa Leboa',
'tn': 'Setswana',
'crs': 'Seychelles French Creole',
'sn': 'Shona',
'scn': 'Sicilian',
'sd': 'Sindhi',
'si': 'Sinhala',
'sk': 'Slovak',
'sl': 'Slovenian',
'so': 'Somali',
'es': 'Spanish',
'su': 'Sundanese',
'sw': 'Swahili',
'sv': 'Swedish',
'ty': 'Tahitian',
'tgk': 'Tajik',
'ta': 'Tamil',
'tt': 'Tatar',
'te': 'Telugu',
'tet': 'Tetum',
'th': 'Thai',
'bo': 'Tibetan',
'ti': 'Tigrinya',
'tpi': 'Tok Pisin',
'to': 'Tongan',
'tr': 'Turkish',
'tk': 'Turkmen',
@@ -195,9 +238,12 @@ export declare namespace lang {
'ur': 'Urdu',
'ug': 'Uyghur',
'uz': 'Uzbek (Latin)',
'vec': 'Venetian',
'vi': 'Vietnamese',
'war': 'Waray',
'cy': 'Welsh',
'xh': 'Xhosa',
'ydd': 'Yiddish (Eastern)',
'yo': 'Yoruba',
'yua': 'Yucatec Maya',
'zu': 'Zulu'
@@ -240,11 +286,11 @@ export declare namespace MET {

/**
* @param text content to be translated
* @param source language code
* @param from source language code
* @param to target language code(s). `en` by default.
* @param options optional translate options
*/
declare function translate(
function translate(
text: string | string[],
from: string | null | undefined,
to: string | string[],
@@ -259,6 +305,7 @@ export declare namespace MET {
'as': 'Assamese',
'az': 'Azerbaijani',
'ba': 'Bashkir',
'be': 'Belarusian',
'bg': 'Bulgarian',
'bho': 'Bhojpuri',
'bn': 'Bangla',
@@ -315,6 +362,7 @@ export declare namespace MET {
'ks': 'Kashmiri',
'ku': 'Kurdish (Central)',
'ky': 'Kyrgyz',
'lb': 'Luxembourgish',
'ln': 'Lingala',
'lo': 'Lao',
'lt': 'Lithuanian',
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bing-translate-api",
"version": "4.0.0",
"version": "4.0.2",
"description": "A simple and free API for Bing & Microsoft Translator for Node.js",
"main": "src/index.js",
"typings": "index.d.ts",
10 changes: 5 additions & 5 deletions scripts/generate-config.js
Original file line number Diff line number Diff line change
@@ -41,17 +41,17 @@ const DEFAULT_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKi
const eptRichTranslateParams = parseRichTranslateParams(eptBody)

const config = {
websiteEndpoint: richTranslateParams[1],
websiteEndpoint: richTranslateParams[2],
translateEndpoint: richTranslateParams[0],
spellCheckEndpoint: richTranslateParams[33],
spellCheckEndpoint: richTranslateParams[26],
// maxTextLen: richTranslateParams[5],
// PENDING: hard-coding
maxTextLen: 1000,
// PENDING: hard-coding
maxTextLenCN: 5000,
maxCorrectableTextLen: richTranslateParams[30],
maxEPTTextLen: eptRichTranslateParams[5],
correctableLangs: richTranslateParams[31],
maxCorrectableTextLen: richTranslateParams[24],
maxEPTTextLen: eptRichTranslateParams[6],
correctableLangs: richTranslateParams[25],
eptLangs: eptLangCodes,
userAgent: DEFAULT_USER_AGENT
}
8 changes: 4 additions & 4 deletions scripts/index.tpl.d.ts
Original file line number Diff line number Diff line change
@@ -27,15 +27,15 @@ export interface TranslationResult {
/**
* The detected language code of original text
*/
from: string;
from?: string;
/**
* The language code of translated text
*/
to: string;
/**
* The score of language detection
*/
score: number;
score?: number;
};
/**
* The original response from Bing translator
@@ -103,11 +103,11 @@ export declare namespace MET {

/**
* @param text content to be translated
* @param source language code
* @param from source language code
* @param to target language code(s). `en` by default.
* @param options optional translate options
*/
declare function translate(
function translate(
text: string | string[],
from: string | null | undefined,
to: string | string[],
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -314,7 +314,7 @@ async function translate(text, from, to, correct, raw, userAgent, proxyAgents) {
)

const translation = body[0].translations[0]
const detectedLang = body[0].detectedLanguage
const detectedLang = body[0].detectedLanguage || {}

/**
* @type {TranslationResult}
Loading