refactor(ui): remove unnecessary checks (i18n is always defined)
This commit is contained in:
@@ -8,11 +8,9 @@ let usersPage = 0;
|
||||
const PAGE_SIZE = 50;
|
||||
let totalUsers = 0;
|
||||
|
||||
/* ── i18n helper — falls back to key if i18n not ready ── */
|
||||
/* ── i18n helper ── */
|
||||
function t(key, params) {
|
||||
if (i18n && typeof i18n.t === 'function') return i18n.t(key, params);
|
||||
// fallback: strip prefix and humanise
|
||||
return key.split('.').pop().replace(/_/g, ' ');
|
||||
return i18n.t(key, params);
|
||||
}
|
||||
|
||||
/** Escape a string for safe embedding inside a JS string literal within an HTML attribute. */
|
||||
@@ -1105,13 +1103,13 @@ function showAccessDenied() {
|
||||
|
||||
/* ── Apply i18n when translations load / change ── */
|
||||
document.addEventListener('translationsLoaded', () => {
|
||||
if (i18n?.translatePage) i18n.translatePage();
|
||||
i18n.translatePage();
|
||||
// Re-render dynamic content that uses t()
|
||||
loadDashboard();
|
||||
if (activeTabName === 'users') loadUsers();
|
||||
});
|
||||
document.addEventListener('localeChanged', () => {
|
||||
if (i18n?.translatePage) i18n.translatePage();
|
||||
i18n.translatePage();
|
||||
loadDashboard();
|
||||
if (activeTabName === 'users') loadUsers();
|
||||
});
|
||||
|
||||
@@ -3,10 +3,9 @@ import { i18n } from '../../core/i18n.js';
|
||||
|
||||
const API = '/api';
|
||||
|
||||
/* ── i18n helper — falls back to key if i18n not ready ── */
|
||||
/* ── i18n helper ── */
|
||||
function t(key, params) {
|
||||
if (i18n && typeof i18n.t === 'function') return i18n.t(key, params);
|
||||
return key.split('.').pop().replace(/_/g, ' ');
|
||||
return i18n.t(key, params);
|
||||
}
|
||||
|
||||
function headers() {
|
||||
|
||||
@@ -220,9 +220,7 @@ const sharedView = {
|
||||
</div>
|
||||
`;
|
||||
|
||||
if (i18n?.translateElement) {
|
||||
i18n.translateElement(container);
|
||||
}
|
||||
i18n.translateElement(container);
|
||||
},
|
||||
|
||||
// Attach event listeners
|
||||
@@ -662,8 +660,7 @@ const sharedView = {
|
||||
},
|
||||
|
||||
translate(key, defaultText) {
|
||||
if (i18n?.t) return i18n.t(key, defaultText);
|
||||
return defaultText;
|
||||
return i18n.t(key, defaultText);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user