Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

translation fix

Murtaza Nasir6456a0c12d91
diff --git a/static/js/app.js b/static/js/app.js
index 4f7bfec8..b0acb6af 100644
--- a/static/js/app.js
+++ b/static/js/app.js
@@ -3897,7 +3897,12 @@ document.addEventListener('DOMContentLoaded', async () => {
// --- i18n Helper Functions ---
const t = (key, params = {}) => {
- return window.i18n ? window.i18n.t(key, params) : key;
+ // Defensive check - return key if i18n not ready
+ if (!window.i18n || !window.i18n.t) {
+ console.warn('i18n not initialized, returning key:', key);
+ return key;
+ }
+ return window.i18n.t(key, params);
};
const tc = (key, count, params = {}) => {
diff --git a/static/js/i18n.js b/static/js/i18n.js
index 50c4c1b2..f491bce2 100644
--- a/static/js/i18n.js
+++ b/static/js/i18n.js
@@ -281,7 +281,16 @@ class I18n {
// Create global i18n instance
const i18n = new I18n();
-// Export for use in Vue components
+// Create a fallback t function immediately
if (typeof window !== 'undefined') {
+ // Ensure window.i18n exists with at least a basic t function
window.i18n = i18n;
+
+ // Add a fallback t function if the class method isn't ready
+ if (!window.i18n.t) {
+ window.i18n.t = function(key, params) {
+ console.warn('i18n.t called before initialization, returning key:', key);
+ return key;
+ };
+ }
}
\ No newline at end of file
diff --git a/templates/index.html b/templates/index.html
index d65d9268..db021ce3 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -2680,6 +2680,28 @@
<!-- i18n System -->
<script src="{{ url_for('static', filename='js/i18n.js') }}"></script>
+ <!-- Initialize i18n immediately with fallback -->
+ <script>
+ // Ensure i18n is initialized before Vue app
+ (async function() {
+ if (window.i18n && window.i18n.init) {
+ const userLang = localStorage.getItem('preferredLanguage') || '{{ user_language }}' || 'en';
+ try {
+ await window.i18n.init(userLang);
+ console.log('i18n pre-initialized with language:', userLang);
+ } catch (error) {
+ console.error('Failed to initialize i18n:', error);
+ }
+ }
+
+ // Hide loader after i18n is ready
+ const loader = document.getElementById('loader');
+ if (loader) {
+ loader.style.display = 'none';
+ }
+ })();
+ </script>
+
<!-- Vue.js Application Script -->
<script src="{{ url_for('static', filename='js/app.js') }}"></script>
</body>