Google Cloud Translate API: Casing with responses

JoelV
New Member

We are using google cloud translate api and we suddenly saw the following behavior when translating the english word 'False' to french (fr). It will always come back as 'FAUX' no matter the casing of the input. See below output

```
--- translating False to fr ---

FAUX
--- translating false to fr ---
FAUX
--- translating FALSE to fr ---
FAUX
--- translating True to fr ---
Vrai
--- translating true to fr ---
vrai
--- translating TRUE to fr ---
VRAI

```

As you can see translating true seems to be consistent. 

We just recently started seeing this behavior and it always wasn't acting like this.

Please advise.


Here's the node js script (typescript) for reference if it's useful.

```

import * as dotenv from 'dotenv';
import { v2 as translate } from '@google-cloud/translate';
import { accessSync, PathLike, writeFileSync } from 'fs';

dotenv.config();

function fileExists(path: PathLike): boolean {
try {
accessSync(path);
return true;
} catch {
return false;
}
}

function ensureCredentialsExist(): void {
const credentialsFile = process.env['GOOGLE_APPLICATION_CREDENTIALS'] ?? '';
const credentialsFileExists = fileExists(credentialsFile);
if (!credentialsFileExists) {
writeFileSync(credentialsFile, process.env['GOOGLE_CREDENTIALS_DATA'] ?? '');
}
}

 

async function main(): Promise<void> {
ensureCredentialsExist();
const projectId = process.env['GOOGLE_PROJECT_ID'] ?? '0xdeadcode';
const translationClient = new translate.Translate({ projectId });
console.log('--- translating False to fr ---');
const [translation1] = await translationClient.translate('False', 'fr');
console.log(translation1);
console.log('--- translating false to fr ---');
const [translation2] = await translationClient.translate('false', 'fr');
console.log(translation2);
console.log('--- translating FALSE to fr ---');
const [translation3] = await translationClient.translate('FALSE', 'fr');
console.log(translation3);

console.log('--- translating True to fr ---');
const [translation4] = await translationClient.translate('True', 'fr');
console.log(translation4);
console.log('--- translating true to fr ---');
const [translation5] = await translationClient.translate('true', 'fr');
console.log(translation5);
console.log('--- translating TRUE to fr ---');
const [translation6] = await translationClient.translate('TRUE', 'fr');
console.log(translation6);
}

main().catch(console.error);


```


1 2 331
2 REPLIES 2

Are you using the Basic edition of Translation API?

JoelV
New Member

Yes I'm using the basic edition of the Translation API.