From 517b140911cb063c42790168c8510eab09fa6559 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:01:48 +0200 Subject: [PATCH] Localize only the moment instance --- public/scripts/i18n.js | 3 ++- public/scripts/utils.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/scripts/i18n.js b/public/scripts/i18n.js index 4764b1b8d..39dccda4d 100644 --- a/public/scripts/i18n.js +++ b/public/scripts/i18n.js @@ -9,6 +9,8 @@ var langs; // eslint-disable-next-line prefer-const var localeData; +export const getCurrentLocale = () => localeFile; + /** * An observer that will check if any new i18n elements are added to the document * @type {MutationObserver} @@ -215,7 +217,6 @@ function addLanguagesToDropdown() { } export async function initLocales() { - moment.locale(localeFile); langs = await fetch('/locales/lang.json').then(response => response.json()); localeData = await getLocaleData(localeFile); applyLocale(); diff --git a/public/scripts/utils.js b/public/scripts/utils.js index 1196f5c42..7bda1a499 100644 --- a/public/scripts/utils.js +++ b/public/scripts/utils.js @@ -7,6 +7,7 @@ import { Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js'; import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js'; import { getTagsList } from './tags.js'; import { groups, selected_group } from './group-chats.js'; +import { getCurrentLocale } from './i18n.js'; /** * Pagination status string template. @@ -831,7 +832,7 @@ export function timestampToMoment(timestamp) { } const iso8601 = parseTimestamp(timestamp); - const objMoment = iso8601 ? moment(iso8601) : moment.invalid(); + const objMoment = iso8601 ? moment(iso8601).locale(getCurrentLocale()) : moment.invalid(); dateCache.set(timestamp, objMoment); return objMoment;