Skip to content

Commit

Permalink
debug aggaaainnn
Browse files Browse the repository at this point in the history
  • Loading branch information
NancyAanchal committed Aug 7, 2024
1 parent 8eecb7d commit f3148c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
17 changes: 14 additions & 3 deletions nepalingo-web/src/hooks/useDictionary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ async function getFetcherByLanguage(
newariResult = await getNewariWord(word);

if (newariResult.meanings.length === 0) {
return await getGTranslate("new", word);
console.log("Used Google Translate for newari");
return await getGTranslate("newari", word);
// return {
// language,
// word,
Expand All @@ -63,8 +64,18 @@ async function getFetcherByLanguage(
case "Tajpuriya":
return await getTajpuriyaWord(word);
case "Maithili":
return await getGTranslate("mai", word);

return await getGTranslate("maithili", word);
// return {
// language,
// word,
// meanings: [
// {
// language,
// meaningOriginal: maithiliResult,
// meaningEn: word,
// },
// ],
// };
default:
throw new Error(`Language ${language} not supported`);
}
Expand Down
27 changes: 14 additions & 13 deletions nepalingo-web/src/lib/getGTranslate.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
const GOOGLE_TRANSLATE_API_KEY = "AIzaSyCi239eredIAEEJkI8xzvGwW1GPS7B1vxQ";
let language: string;

const languageCodes: { [key: string]: string } = {
maithili: "mai",
newari: "new",
};

export const getGTranslate = async (
targetLanguage: string,
language: string,
word: string
): Promise<{
language: string;
word: string;
meanings: {
meanings: Array<{
language: string;
meaningOriginal: string;
meaningEn: string;
}[];
}>;
}> => {
const url = `https://translation.googleapis.com/targetLanguage/translate/v2?key=${GOOGLE_TRANSLATE_API_KEY}&q=${word}&target=${targetLanguage}`;
const targetLanguage = languageCodes[language];
if (!targetLanguage) {
throw new Error(`Language code for ${language} not found`);
}

const url = `https://translation.googleapis.com/language/translate/v2?key=${GOOGLE_TRANSLATE_API_KEY}&q=${word}&target=${targetLanguage}`;

const response = await fetch(url);
const data = await response.json();
Expand All @@ -22,14 +31,6 @@ export const getGTranslate = async (
throw new Error(data.error.message);
}

if (targetLanguage === "new") {
language = "newari";
}
if (targetLanguage === "mai") {
language = "maithili";
}

//return data.data.translations[0].translatedText;
return {
language,
word,
Expand Down

0 comments on commit f3148c6

Please sign in to comment.