Skip to content

Instantly share code, notes, and snippets.

@underoot
Last active June 17, 2022 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save underoot/5db2d02995e3583cbf8628faeda67795 to your computer and use it in GitHub Desktop.
Save underoot/5db2d02995e3583cbf8628faeda67795 to your computer and use it in GitHub Desktop.
Getting languages with similar words for pronouns She and He
code pronoun
az O
bn সে
ceb Siya
et Ta
fa او
fi Hän
hi वह
hmn Nws
ht Li
hu Ő
hy Նա
id Dia
ka ის
kk Ол
ky Ал
mi Ko ia
mn Тэр
ny Iye
or ସେ
pa ਉਹ
rw We
sm O ia
sn Iye
st Eena
sw Yeye
tk Ol
tl Siya
tr O
tt Ул
ur وہ
uz U
xh Yena
zu Yena
const PROJECT_ID = Deno.env.get("PROJECT_ID");
const ACCESS_TOKEN = new TextDecoder("utf-8").decode(
await Deno.run({ cmd: ["gcloud", "auth", "print-access-token"], stdout: "piped" }).output()
);
const KEY = Deno.env.get("KEY");
function getGCPClient(projectId: string) {
return async (method: string, body?: Record<string, any>) => {
const methodName = method === "translateText" ? ":translateText" : `/${method}`;
const res = await fetch(`https://translate.googleapis.com/v3/projects/${projectId}${methodName}?key=${KEY}`, {
method: body ? "POST" : "GET",
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
Accept: 'application/json',
'X-Goog-User-Project': PROJECT_ID ?? ''
},
body: body ? JSON.stringify(body) : undefined
});
const json = await res.json();
return json;
}
}
if (!PROJECT_ID) {
Deno.exit(1);
}
const client = getGCPClient(PROJECT_ID);
const languages = (await client("supportedLanguages")).languages.map(
(lang: {languageCode: string}) => lang.languageCode
);
type TranslationResponse = {
translations: Array<{ translatedText: string }>;
}
for (let languageCode of languages) {
const sheTranslation: TranslationResponse = (await client("translateText", {
contents: ["She"],
sourceLanguageCode: "en",
targetLanguageCode: languageCode
})).translations?.[0]?.translatedText;
const heTranslation: TranslationResponse = (await client("translateText", {
contents: ["He"],
sourceLanguageCode: "en",
targetLanguageCode: languageCode
})).translations?.[0]?.translatedText;
if (sheTranslation === heTranslation && sheTranslation) {
console.log(`${languageCode},${sheTranslation}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment