optimizing translation lookup

This commit is contained in:
Jonas_Jones 2025-02-03 02:59:57 +01:00
parent fb82267977
commit 08ddd51506

View file

@ -8,6 +8,13 @@ const Translate = ({ id }) => {
const [loading, setLoading] = useState(true);
const { i18n } = useDocusaurusContext();
// Look up translation from the default Docusaurus translations first
let translation = translate({ id });
if (translation !== id) {
return <>{translation}</>; // Return the translation if found
}
useEffect(() => {
const fetchTranslations = async () => {
try {
@ -28,9 +35,6 @@ const Translate = ({ id }) => {
return <span>Loading...</span>; // Show a loading state while translations are being fetched
}
// Look up translation from the default Docusaurus translations first
let translation = translate({ id });
// If not found in the default translations, try additional files
if (translation == id && translations[id]) {
console.log('translations', translations);