mirror of
https://github.com/JonasunderscoreJones/docs.jonasjones.dev.git
synced 2025-10-22 18:49:18 +02:00
optimizing translation lookup
This commit is contained in:
parent
fb82267977
commit
08ddd51506
1 changed files with 7 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue