adding search engine

This commit is contained in:
DioCrafts
2025-03-27 01:13:34 +01:00
parent dacc3ecc4c
commit 7affff379d
24 changed files with 1531 additions and 66 deletions
+22 -3
View File
@@ -227,14 +227,33 @@ function getSupportedLocales() {
return [...supportedLocales];
}
// Flag to track if translations are loaded
let translationsLoaded = false;
// Initialize when DOM is ready
document.addEventListener('DOMContentLoaded', initI18n);
document.addEventListener('DOMContentLoaded', async () => {
await initI18n();
translationsLoaded = true;
// Dispatch an event when translations are fully loaded
window.dispatchEvent(new Event('translationsLoaded'));
});
// Improved t function with fallback for early calls
function safeT(key, params = {}) {
if (!translationsLoaded) {
console.warn(`Translations for ${currentLocale} not loaded yet`);
// Return a default value or the key depending on context
return key.split('.').pop() || key;
}
return t(key, params);
}
// Export functions for use in other modules
window.i18n = {
t,
t: safeT,
setLocale,
getCurrentLocale,
getSupportedLocales,
translatePage
translatePage,
isLoaded: () => translationsLoaded
};