From 1bdfe0112cf537dd5a4d934f02e5e27fa0f1a164 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Sun, 12 Dec 2021 15:43:19 -0500 Subject: [PATCH] extractText from translations where strings expected --- js/src/admin/components/ExtensionPage.tsx | 3 ++- js/src/common/utils/abbreviateNumber.ts | 5 +++-- js/src/forum/ForumApplication.ts | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/js/src/admin/components/ExtensionPage.tsx b/js/src/admin/components/ExtensionPage.tsx index fa7f70751..fa6acccaa 100644 --- a/js/src/admin/components/ExtensionPage.tsx +++ b/js/src/admin/components/ExtensionPage.tsx @@ -16,6 +16,7 @@ import RequestError from '../../common/utils/RequestError'; import { Extension } from '../AdminApplication'; import { IPageAttrs } from '../../common/components/Page'; import type Mithril from 'mithril'; +import extractText from '../../common/utils/extractText'; export interface ExtensionPageAttrs extends IPageAttrs { id: string; @@ -156,7 +157,7 @@ export default class ExtensionPage { - if (confirm(app.translator.trans('core.admin.extension.confirm_purge'))) { + if (confirm(extractText(app.translator.trans('core.admin.extension.confirm_purge')))) { app .request({ url: app.forum.attribute('apiUrl') + '/extensions/' + this.extension.id, diff --git a/js/src/common/utils/abbreviateNumber.ts b/js/src/common/utils/abbreviateNumber.ts index 9f3c5366e..43586876a 100644 --- a/js/src/common/utils/abbreviateNumber.ts +++ b/js/src/common/utils/abbreviateNumber.ts @@ -1,4 +1,5 @@ import app from '../../common/app'; +import extractText from './extractText'; /** * The `abbreviateNumber` utility converts a number to a shorter localized form. @@ -10,9 +11,9 @@ import app from '../../common/app'; export default function abbreviateNumber(number: number): string { // TODO: translation if (number >= 1000000) { - return Math.floor(number / 1000000) + app.translator.trans('core.lib.number_suffix.mega_text'); + return Math.floor(number / 1000000) + extractText(app.translator.trans('core.lib.number_suffix.mega_text')); } else if (number >= 1000) { - return (number / 1000).toFixed(1) + app.translator.trans('core.lib.number_suffix.kilo_text'); + return (number / 1000).toFixed(1) + extractText(app.translator.trans('core.lib.number_suffix.kilo_text')); } else { return number.toString(); } diff --git a/js/src/forum/ForumApplication.ts b/js/src/forum/ForumApplication.ts index 169e28135..3c88f4e1e 100644 --- a/js/src/forum/ForumApplication.ts +++ b/js/src/forum/ForumApplication.ts @@ -23,6 +23,7 @@ import isSafariMobile from './utils/isSafariMobile'; import type Notification from './components/Notification'; import type Post from './components/Post'; import Discussion from '../common/models/Discussion'; +import extractText from '../common/utils/extractText'; export default class ForumApplication extends Application { /** @@ -99,7 +100,7 @@ export default class ForumApplication extends Application { } this.routes[defaultAction].path = '/'; - this.history.push(defaultAction, this.translator.trans('core.forum.header.back_to_index_tooltip'), '/'); + this.history.push(defaultAction, extractText(this.translator.trans('core.forum.header.back_to_index_tooltip')), '/'); this.pane = new Pane(document.getElementById('app')); @@ -124,8 +125,9 @@ export default class ForumApplication extends Application { app.history.home(); // Reload the current user so that their unread notification count is refreshed. - if (app.session.user) { - app.store.find('users', app.session.user.id()); + const userId = app.session.user?.id() + if (userId) { + app.store.find('users', userId); m.redraw(); } });