refactor(ui): remove unnecessary checks (i18n is always defined)

This commit is contained in:
Edouard Vanbelle
2026-04-25 22:55:42 +02:00
parent 156f3bc7ba
commit 4e2029969e
20 changed files with 142 additions and 215 deletions
+2 -5
View File
@@ -66,7 +66,7 @@ function createLanguageSelector(containerId = 'language-selector') {
// Get current language
const languages = getAvailableLanguages();
const currentLocale = i18n ? i18n.getCurrentLocale() : 'en';
const currentLocale = i18n.getCurrentLocale();
const currentLang = languages.find((l) => l.code === currentLocale) || languages[0];
// Set initial HTML attributes
@@ -185,10 +185,7 @@ function closeDropdown(container) {
* Select a language
*/
async function selectLanguage(langCode, container) {
// Update i18n if available
if (i18n) {
await i18n.setLocale(langCode);
}
await i18n.setLocale(langCode);
// Update HTML lang attribute and dir for RTL languages
updateHtmlAttributes(langCode);
+4 -5
View File
@@ -108,16 +108,15 @@ const Modal = {
this.input.placeholder = placeholder;
this.input.value = value;
// Set button text (use i18n if available)
if (confirmText) {
this.confirmBtn.textContent = confirmText;
} else if (i18n) {
} else {
this.confirmBtn.textContent = i18n.t('actions.confirm');
}
if (cancelText) {
this.cancelBtn.textContent = cancelText;
} else if (i18n) {
} else {
this.cancelBtn.textContent = i18n.t('actions.cancel');
}
@@ -138,7 +137,7 @@ const Modal = {
* @returns {Promise<string|null>}
*/
promptNewFolder() {
const t = i18n ? i18n.t.bind(i18n) : (k) => k;
const t = i18n.t.bind(i18n);
return this.prompt({
title: t('dialogs.new_folder_title') || 'New folder',
@@ -156,7 +155,7 @@ const Modal = {
* @returns {Promise<string|null>}
*/
promptRename(currentName, isFolder = false) {
const t = i18n ? i18n.t.bind(i18n) : (k) => k;
const t = i18n.t.bind(i18n);
// For files, we want to select only the name part (without extension)
this._selectNameOnly = !isFolder;
+3 -3
View File
@@ -149,7 +149,7 @@ const notifications = (() => {
item.className = 'notif-item';
item.id = batchId;
const t = i18n?.t || ((k) => k);
const t = i18n.t.bind(i18n);
const uploadingText = folderName ? `📁 ${t('upload.uploading')} ${_esc(folderName)}…` : t('upload.uploading');
const filesLabel = t('upload.files');
@@ -254,7 +254,7 @@ const notifications = (() => {
const pctEl = $(`${batchId}-pct`);
const statsEl = $(`${batchId}-stats`);
const t = i18n?.t || ((k) => k);
const t = i18n.t.bind(i18n);
const filesLabel = t('upload.files');
if (fillEl) fillEl.style.width = `${pctVal}%`;
@@ -282,7 +282,7 @@ const notifications = (() => {
const curEl = $(`${batchId}-current`);
if (curEl) curEl.textContent = '';
const t = i18n?.t || ((k) => k);
const t = i18n.t.bind(i18n);
const completeText = t('upload.complete', {
count: successCount,
total: totalFiles