Skip to content

Commit

Permalink
[debug] starting to reverse engineering google translate X-Goog-Batch…
Browse files Browse the repository at this point in the history
…Execute-Bgr
  • Loading branch information
Animenosekai committed Jul 22, 2022
1 parent 31c6a11 commit 67fa8aa
Show file tree
Hide file tree
Showing 4 changed files with 27,700 additions and 1 deletion.
134 changes: 134 additions & 0 deletions docs/English/API Documentation/Objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Objects

This file defines the different objects which can be returned to the client.

## Language

The `Language` object represents a `translatepy.Language` object, which is a class holding information about any Language.

### Example

```json
{
"id": "eng",
"similarity": 100,
"alpha2": "en",
"alpha3b": "eng",
"alpha3t": "eng",
"alpha3": "eng",
"name": "English",
"inForeignLanguages": {
"af": "Engels",
"sq": "Anglisht",
"am": "እንግሊዝኛ",
"ar": "الإنجليزية",
"hy": "Անգլերեն",
"...": "...",
"zh": "英语",
"he": "אנגלית",
"jv": "Inggris",
"en": "English"
},
"extra": {
"type": "Living",
"scope": "Individual"
}
}
```

### Attributes

| Field | Description | Type | Nullable |
| ---------- | -------------------------------- | ------ | --------- |
| `id` | The ID of the language | string | No |
| `similarity` | The string similarity of the input string with the one in the database | float | No |
| `alpha2` | The ISO 639-1 (alpha 2) code | string | Yes |
| `alpha3b` | The ISO 639-2B code | string | Yes |
| `alpha3t` | The ISO 639-2T code | string | Yes |
| `alpha3` | The ISO 639-3 code | string | No |
| `name` | The English name of the language | string | No |
| `inForeignLanguages` | If available, the translation of the language name in different languages | object[alpha2Code(string): string] | No |
| `extra` | Extra information on the language | [`LanguageExtra`](#languageextra) | No |

## LanguageExtra

The `LanguageExtra` object is an object holding extra information about a `Language`.

### Example

```json
{
"type": "Living",
"scope": "Individual"
}
```

### Attributes

| Field | Description | Type | Nullable |
| ---------- | -------------------------------- | ------ | --------- |
| `type` | The type of the language | [`LanguageExtraType`](#languageextratype) | Yes |
| `scope` | The scope of the language | [`LanguageExtraScope`](#languageextrascope) | Yes |

### LanguageExtraType

This is a string enum which can be any of the following strings :

```typescript
"Ancient" | "Constructed" | "Extinct" | "Historical" | "Living" | "Special"
```

### LanguageExtraScope

This is a string enum which can be any of the following strings :

```typescript
"Individual" | "Macrolanguage" | "Special"
```

## StarredTranslation

This represents a starred translation.

### Attributes

| Field | Description | Type | Nullable |
| ---------- | -------------------------------- | ------ | --------- |
| `source` | This is the source text | string | No |
| `result` | This is the resulting text | string | No |
| `language` | This is the translation language data | [`StarredTranslationLanguage`](#starredtranslationlanguage) | No |
| `users` | This is the number of users who starred the translation | int | No |

### Example

```json
{
"source": "Hello world",
"result": "ハローワールド",
"language": {
"source": "eng",
"dest": "jpn"
},
"users": 35
}
```

### StarredTranslationLanguage

This is the language data for the starred translation.

#### Attributes

| Field | Description | Type | Nullable |
| ---------- | -------------------------------- | ------ | --------- |
| `source` | This is the source language | string | No |
| `dest` | This is the destination language | string | No |

#### Example

```json
{
"source": "eng",
"dest": "jpn"
}
```
143 changes: 143 additions & 0 deletions google-batch-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
$E.prototype.j({
"j": {},
"o": 2,
"v": null,
"H": false
})


const xya = function (a) {
const newSet = new Set;

for (let c of a) {
newSet.add(c.getName())
newSet.add(c.ua)
}

return (d) => {
// d.ya("rpcids")
const rpcids = d.j.o.j.rpcids // => "QShL0"
if (!d) {
return true
}

for (let char of rpcids) {
if (newSet.has(char)) { // if e in set
return true
}
}

return false
}
}

const this_H = xya("...TRANSLATEPY__UNKNOWN_VALUE") // what do I need to put ?

$E.prototype.j = function (a) {
var b = ["[[[\"QShL0\",\"[\\\"fr\\\",\\\"en\\\",[\\\"Salut le monde, comment vas-tu\\\",\\\"Bonjour le monde, comment allez-vous\\\"]]\",null,\"generic\"]]]"]
if (b && this_H(a)) {
var c = this_N_jf(b)
.then(
(d) => {
a.na.set("X-Goog-BatchExecute-Bgr", d);
return a
},
() => a // rejection
);
return _.Xh(c)
}
};

const ya = (a) => {
return this.j.o.get(a)
}

const _B = (a) => {
var newIterator = Symbol.iterator && a[Symbol.iterator];
return newIterator ? newIterator.call(a) : {
next: pe(a)
}
}



const this_N_jf = function (a) {
return H.promise.then(function () {
return N_state_jf(a)
})
}

const this_N_state_jf = function (a) {
var currentDateTime = Date.now();
if (this.j < currentDateTime) {
return kF(this.service), this.service.jf(a);
}
var c = Eya(this.service);
try {
return this.o(a)
.then((d) => { // fullfilled
c.kf(0);
_.A(c, 1, d);
gF(c, Date.now() - currentDateTime);
return c.od()
}, () => { // rejected
c.kf(2);
gF(c, Date.now() - currentDateTime);
return c.od()
})
} catch (d) {
return c.kf(2), gF(c, Date.now() - currentDateTime), Promise.resolve(c.od())
}
}


const a = {
N: {
"j": {
"f.req": ["[[[\"QShL0\",\"[\\\"fr\\\",\\\"en\\\",[\\\"Salut le monde, comment vas-tu\\\",\\\"Bonjour le monde, comment allez-vous\\\"]]\",null,\"generic\"]]]"],
"at": "AAaZcx0lrxcKw6kC7PCAN-wnkVpE:1657560161959"
},
"o": 2,
"v": null,
"H": false
},
Pt: "BEST_EFFORT",
Va: true,
Wa: 769763,
fR: false,
j: {
"H": "",
"ua": "",
"v": "",
"wa": null,
"j": "/_/TranslateWebserverUi/data/batchexecute",
"na": "",
"N": false,
"o": {
"j": {
'rpcids': 'QShL0',
'source-path': '/',
'f.sid': '-6597052306162989274',
'bl': 'boq_translate-webserver_20220706.08_p0',
'hl': 'en',
'soc-app': '1',
'soc-platform': '1',
'soc-device': '1'
},
"o": 8,
"v": null,
"H": false
}
},
kc: false,
na: {
"o": {},
"j": [],
"size": 0,
"v": 0
},
v: "POST",
wa: "...TRANSLATEPY__CONTAINS_CYCLIC_REFERENCE...",
xc: 7,
yb: -1
}
Loading

1 comment on commit 67fa8aa

@vercel
Copy link

@vercel vercel bot commented on 67fa8aa Sep 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.