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A,IAAAA,IAAAA,EAAA,IACtC,IAAMC,EAAgB,KAA6B1B,KAAK,GAAU/H,GAA4BwJ,GAE9F,OAAO,IAAIE,SAAQ,SAACC,EAASC,GAC3B,IAAMC,EAAOX,EAAkBV,EAAMiB,GAC/BK,EAAMxJ,EAAmBmJ,GAEzBM,EAAM,UAERD,EACA,CACEE,OAAQ,OACRC,QAAS,EAAF,CACL,eAAgB,oCAChB,iBAAkBC,OAAOC,WAAWN,IACjCJ,EAAiBQ,WAGxB,SAACG,GACC,IAAIpC,EAAO,GAEXoC,EAAKC,GAAG,QAAQ,SAACC,GACftC,GAAQsC,CACV,IAEAF,EAAKC,GAAG,OAAO,WACbV,EAAQ9B,EAAkBG,EAAMyB,EAAiB1B,KACnD,GACF,IAEDsC,GAAG,QAAST,GAEfG,EAAIQ,MAAMV,GACVE,EAAIS,KACN,GACF,CCnCA,U","sources":["webpack://google-translate-api-browser/webpack/bootstrap","webpack://google-translate-api-browser/webpack/runtime/define property getters","webpack://google-translate-api-browser/webpack/runtime/hasOwnProperty shorthand","webpack://google-translate-api-browser/webpack/runtime/make namespace object","webpack://google-translate-api-browser/./src/defaultTranslateOptions.ts","webpack://google-translate-api-browser/./src/generateRequestUrl.ts","webpack://google-translate-api-browser/./src/languages.ts","webpack://google-translate-api-browser/./src/isLanguageSupported.ts","webpack://google-translate-api-browser/./src/normaliseResponse.ts","webpack://google-translate-api-browser/external node-commonjs \"node:https\"","webpack://google-translate-api-browser/./src/createRequestBody.ts","webpack://google-translate-api-browser/./src/translate.server.ts","webpack://google-translate-api-browser/./src/index.server.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { TranslateOptions } from \"./types/TranslateOptions\";\n\nexport const defaultTranslateOptions: TranslateOptions = {\n  from: \"auto\",\n  to: \"en\",\n  hl: \"en\", // Host language\n  tld: \"com\",\n  rpcids: \"MkEWBc\",\n};\n","import { defaultTranslateOptions } from \"./defaultTranslateOptions\";\nimport { GenerateRequestUrlOptions } from \"./types/GenerateRequestUrlOptions\";\n\nfunction validateTLD(tld: string): boolean {\n  return Boolean(tld.match(/^[a-zA-Z]{2,63}$/));\n}\n\nexport function generateRequestUrl({\n  rpcids = defaultTranslateOptions.rpcids,\n  hl = defaultTranslateOptions.hl,\n  tld = defaultTranslateOptions.tld,\n}: GenerateRequestUrlOptions = {}): string {\n  if (!validateTLD(tld)) {\n    throw new Error(\"Invalid TLD: Must be 2-63 letters only\");\n  }\n\n  const searchParams = new URLSearchParams({\n    rpcids: rpcids,\n    \"source-path\": \"/\",\n    hl: hl,\n    \"soc-app\": \"1\",\n    \"soc-platform\": \"1\",\n    \"soc-device\": \"1\",\n  });\n\n  return `https://translate.google.${tld}/_/TranslateWebserverUi/data/batchexecute?${searchParams}`;\n}\n","const langs = {\n  auto: \"Automatic\",\n  af: \"Afrikaans\",\n  sq: \"Albanian\",\n  am: \"Amharic\",\n  ar: \"Arabic\",\n  hy: \"Armenian\",\n  az: \"Azerbaijani\",\n  eu: \"Basque\",\n  be: \"Belarusian\",\n  bn: \"Bengali\",\n  bs: \"Bosnian\",\n  bg: \"Bulgarian\",\n  ca: \"Catalan\",\n  ceb: \"Cebuano\",\n  ny: \"Chichewa\",\n  zh: \"Chinese Simplified\",\n  \"zh-cn\": \"Chinese Simplified\",\n  \"zh-tw\": \"Chinese Traditional\",\n  co: \"Corsican\",\n  hr: \"Croatian\",\n  cs: \"Czech\",\n  da: \"Danish\",\n  nl: \"Dutch\",\n  en: \"English\",\n  'en-US': \"English\",\n  eo: \"Esperanto\",\n  et: \"Estonian\",\n  tl: \"Filipino\",\n  fi: \"Finnish\",\n  fr: \"French\",\n  fy: \"Frisian\",\n  gl: \"Galician\",\n  ka: \"Georgian\",\n  de: \"German\",\n  el: \"Greek\",\n  gu: \"Gujarati\",\n  ht: \"Haitian Creole\",\n  ha: \"Hausa\",\n  haw: \"Hawaiian\",\n  he: \"Hebrew\",\n  iw: \"Hebrew\",\n  hi: \"Hindi\",\n  hmn: \"Hmong\",\n  hu: \"Hungarian\",\n  is: \"Icelandic\",\n  ig: \"Igbo\",\n  id: \"Indonesian\",\n  ga: \"Irish\",\n  it: \"Italian\",\n  ja: \"Japanese\",\n  jw: \"Javanese\",\n  kn: \"Kannada\",\n  kk: \"Kazakh\",\n  km: \"Khmer\",\n  rw: \"Kinyarwanda\",\n  ko: \"Korean\",\n  ku: \"Kurdish (Kurmanji)\",\n  ky: \"Kyrgyz\",\n  lo: \"Lao\",\n  la: \"Latin\",\n  lv: \"Latvian\",\n  lt: \"Lithuanian\",\n  lb: \"Luxembourgish\",\n  mk: \"Macedonian\",\n  mg: \"Malagasy\",\n  ms: \"Malay\",\n  ml: \"Malayalam\",\n  mt: \"Maltese\",\n  mi: \"Maori\",\n  mr: \"Marathi\",\n  mn: \"Mongolian\",\n  my: \"Myanmar (Burmese)\",\n  ne: \"Nepali\",\n  no: \"Norwegian\",\n  or: \"Odia (Oriya)\",\n  ps: \"Pashto\",\n  fa: \"Persian\",\n  pl: \"Polish\",\n  pt: \"Portuguese\",\n  pa: \"Punjabi\",\n  ro: \"Romanian\",\n  ru: \"Russian\",\n  sm: \"Samoan\",\n  gd: \"Scots Gaelic\",\n  sr: \"Serbian\",\n  st: \"Sesotho\",\n  sn: \"Shona\",\n  sd: \"Sindhi\",\n  si: \"Sinhala\",\n  sk: \"Slovak\",\n  sl: \"Slovenian\",\n  so: \"Somali\",\n  es: \"Spanish\",\n  su: \"Sundanese\",\n  sw: \"Swahili\",\n  sv: \"Swedish\",\n  tg: \"Tajik\",\n  ta: \"Tamil\",\n  tt: \"Tatar\",\n  te: \"Telugu\",\n  th: \"Thai\",\n  tr: \"Turkish\",\n  tk: \"Turkmen\",\n  uk: \"Ukrainian\",\n  ur: \"Urdu\",\n  ug: \"Uyghur\",\n  uz: \"Uzbek\",\n  vi: \"Vietnamese\",\n  cy: \"Welsh\",\n  xh: \"Xhosa\",\n  yi: \"Yiddish\",\n  yo: \"Yoruba\",\n  zu: \"Zulu\",\n} as const;\n\nexport default langs;\n","import langs from \"./languages\";\nimport { LangKey } from \"./types/LangKey\";\n\nexport const isLanguageSupported = (desiredLang: LangKey): boolean => {\n  return Boolean(langs[desiredLang]);\n};\n","import { RawContentType, RawTranslationResponse, TranslationResult } from \"./types/TranslationResult\";\n\nfunction parseData(data: string) {\n  try {\n    const content: RawContentType = JSON.parse(data.replace(/^\\)]}'/, \"\"));\n    const translationResponse: RawTranslationResponse = JSON.parse(content[0][2]);\n\n    return translationResponse;\n  } catch (e) {\n    throw new Error(\"Data is either empty or corrupted\");\n  }\n}\n\nexport function normaliseResponse(rawBody: string, raw = false): TranslationResult {\n  const data = parseData(rawBody);\n  const translatedPhrases = data[1][0][0][5];\n  const text = translatedPhrases.reduce<string>((fullText, [textBlock]) => {\n    return fullText ? `${fullText} ${textBlock}` : textBlock;\n  }, \"\");\n\n  const result: TranslationResult = {\n    text,\n    pronunciation: data[1][0][0][1],\n    from: {\n      language: {\n        didYouMean: Boolean(data[0][1]),\n        iso: data[2]\n      },\n      text: {\n        pronunciation: data[0][0],\n        autoCorrected: Boolean(data[0][1]),\n        value: data[0][6][0],\n        didYouMean: data[0][1] ? data[0][1][0][4] : null\n      }\n    }\n  };\n\n  if (raw) {\n    result.raw = data;\n  }\n\n  return result;\n}\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"node:https\");","import { defaultTranslateOptions } from \"./defaultTranslateOptions\";\nimport { CreateRequestBodyOptions } from \"./types/CreateRequestBodyOptions\";\n\nfunction escapeSpecialSymbols(inputString: string): string {\n  const escapedString = inputString.replace(/[\"]/g, \"\\\\\\\\\\\\$&\");\n  const normalizedString = escapedString.replace(/\\r\\n|\\r|\\n/g, \"\\\\\\\\n\");\n\n  return normalizedString;\n}\n\nexport function createRequestBody(\n  text: string,\n  { rpcids = defaultTranslateOptions.rpcids, from = defaultTranslateOptions.from, to = defaultTranslateOptions.to }: CreateRequestBodyOptions = {},\n): string {\n  const normalizedText = escapeSpecialSymbols(text.trim());\n  const encodedData = encodeURIComponent(`[[[\"${rpcids}\",\"[[\\\\\"${normalizedText}\\\\\",\\\\\"${from}\\\\\",\\\\\"${to}\\\\\",1],[]]\",null,\"generic\"]]]`);\n\n  return `f.req=${encodedData}&`;\n}\n","import * as https from \"node:https\";\nimport { createRequestBody } from \"./createRequestBody\";\nimport { defaultTranslateOptions } from \"./defaultTranslateOptions\";\nimport { generateRequestUrl } from \"./generateRequestUrl\";\nimport { normaliseResponse } from \"./normaliseResponse\";\nimport { ServerTranslateOptions } from \"./types/ServerTranslateOptions\";\nimport { TranslationResult } from \"./types/TranslationResult\";\n\nexport function translate(text: string, options: ServerTranslateOptions = {}): Promise<TranslationResult> {\n  const translateOptions: ServerTranslateOptions = { raw: false, ...defaultTranslateOptions, ...options };\n\n  return new Promise((resolve, reject) => {\n    const body = createRequestBody(text, translateOptions);\n    const url = generateRequestUrl(translateOptions);\n\n    const req = https\n      .request(\n        url,\n        {\n          method: \"POST\",\n          headers: {\n            \"Content-Type\": \"application/x-www-form-urlencoded\",\n            \"Content-Length\": Buffer.byteLength(body),\n            ...translateOptions.headers,\n          },\n        },\n        (resp) => {\n          let data = \"\";\n\n          resp.on(\"data\", (chunk) => {\n            data += chunk;\n          });\n\n          resp.on(\"end\", () => {\n            resolve(normaliseResponse(data, translateOptions.raw));\n          });\n        },\n      )\n      .on(\"error\", reject);\n\n    req.write(body);\n    req.end();\n  });\n}\n","import { generateRequestUrl } from \"./generateRequestUrl\";\nimport { isLanguageSupported } from \"./isLanguageSupported\";\nimport { normaliseResponse } from \"./normaliseResponse\";\nimport { translate } from \"./translate.server\";\nimport { createRequestBody } from \"./createRequestBody\";\n\nexport { createRequestBody, isLanguageSupported, translate, normaliseResponse, generateRequestUrl };\n\nexport default translate;\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","defaultTranslateOptions","from","to","hl","tld","rpcids","generateRequestUrl","Boolean","match","validateTLD","Error","searchParams","URLSearchParams","auto","af","sq","am","ar","hy","az","eu","be","bn","bs","bg","ca","ceb","ny","zh","co","hr","cs","da","nl","en","eo","et","tl","fi","fr","fy","gl","ka","de","el","gu","ht","ha","haw","he","iw","hi","hmn","hu","is","ig","id","ga","it","ja","jw","kn","kk","km","rw","ko","ku","ky","lo","la","lv","lt","lb","mk","mg","ms","ml","mt","mi","mr","mn","my","ne","no","or","ps","fa","pl","pt","pa","ro","ru","sm","gd","sr","st","sn","sd","si","sk","sl","so","es","su","sw","sv","tg","ta","tt","te","th","tr","tk","uk","ur","ug","uz","vi","cy","xh","yi","yo","zu","isLanguageSupported","desiredLang","normaliseResponse","rawBody","raw","data","content","JSON","parse","replace","e","parseData","result","text","reduce","fullText","textBlock","pronunciation","language","didYouMean","iso","autoCorrected","require","createRequestBody","normalizedText","trim","encodedData","encodeURIComponent","translate","options","translateOptions","Promise","resolve","reject","body","url","req","method","headers","Buffer","byteLength","resp","on","chunk","write","end"],"sourceRoot":""}