translation-terrace/components/ui/ISpeakButton.tsx
2025-01-23 07:00:50 -08:00

37 lines
967 B
TypeScript

import AsyncStorage from '@react-native-async-storage/async-storage';
import { CachedTranslator } from "@/app/i18n/api"
import { longLang } from "@/app/i18n/lang"
import { useEffect, useRef, useState } from "react"
import { Button } from "react-native"
type ISpeakButtonProps = {
country: string,
language: string,
}
function iSpeak(language : string) {
return `I speak ${longLang(language)}.`
}
async function iSpeakTr(targetLang : string, sourceLang = "en") {
const sourceStr = iSpeak(targetLang)
const translator = new CachedTranslator(sourceLang, targetLang);
return await translator.translate(sourceStr)
}
const ISpeakButton = (props : ISpeakButtonProps) => {
const [title, setTitle] = useState("");
useEffect(() => {
async function () {
setTitle(await iSpeakTr(props.language) as string);
}
}, []);
<Button onPress={setLanguage} title={}>
</Button>
}
export default ISpeakButton;