Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
NancyAanchal committed Aug 7, 2024
1 parent f3148c6 commit 1d00be2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
30 changes: 4 additions & 26 deletions nepalingo-web/src/hooks/useDictionary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,28 @@ export type DictionaryResponse = {

async function getFetcherByLanguage(
language: string,
word?: string
word?: string,
): Promise<DictionaryResponse> {
if (!word) {
word = "hello";
}
let newariResult: DictionaryResponse;
// let newariFallbackResult: string;
// let maithiliResult: string;

switch (language) {
case "Newari":
newariResult = await getNewariWord(word);

if (newariResult.meanings.length === 0) {
console.log("Used Google Translate for newari");
return await getGTranslate("newari", word);
// return {
// language,
// word,
// meanings: [
// {
// language,
// meaningOriginal: newariFallbackResult,
// meaningEn: word,
// },
// ],
// };
}
return newariResult;

case "Tajpuriya":
return await getTajpuriyaWord(word);
case "Maithili":
return await getGTranslate("maithili", word);
// return {
// language,
// word,
// meanings: [
// {
// language,
// meaningOriginal: maithiliResult,
// meaningEn: word,
// },
// ],
// };

default:
throw new Error(`Language ${language} not supported`);
}
Expand All @@ -84,7 +62,7 @@ async function getFetcherByLanguage(
const useDictionary = ({ language, word }: DictionaryProps) => {
const cacheKey = word ? `/${language}/${word}` : null;
const { data, error, isLoading } = useSWR(cacheKey, () =>
getFetcherByLanguage(language, word)
getFetcherByLanguage(language, word),
);
return { data, error, isLoading };
};
Expand Down
2 changes: 1 addition & 1 deletion nepalingo-web/src/lib/getGTranslate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const languageCodes: { [key: string]: string } = {

export const getGTranslate = async (
language: string,
word: string
word: string,
): Promise<{
language: string;
word: string;
Expand Down

0 comments on commit 1d00be2

Please sign in to comment.