From 5294069b2006746e39e9b0ab82d7af68acea1138 Mon Sep 17 00:00:00 2001 From: N-Pex Date: Fri, 10 Jan 2025 11:44:26 +0100 Subject: [PATCH] Basic support for translated numerals --- .../channel/QuickReactionsChannel.vue | 3 +- src/plugins/lang.js | 38 +++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/components/messages/channel/QuickReactionsChannel.vue b/src/components/messages/channel/QuickReactionsChannel.vue index 247808d..8e2e422 100644 --- a/src/components/messages/channel/QuickReactionsChannel.vue +++ b/src/components/messages/channel/QuickReactionsChannel.vue @@ -12,7 +12,7 @@ {{ $t("global.click_to_remove") }} - $vuetify.icons.ic_like {{ value.length }} + $vuetify.icons.ic_like {{ $i18n.toLocalNumbers(value.length.toFixed()) }} @@ -45,6 +45,7 @@ export default { } }, mounted() { + console.log("I18", this.$i18n.toLocalNumbers); this.reactions = this.timelineSet.relations.getChildEventsForEvent(this.event.getId(), 'm.annotation', 'm.reaction'); this.event.on("Event.relationsCreated", this.onRelationsCreated); }, diff --git a/src/plugins/lang.js b/src/plugins/lang.js index 182c261..456ecc0 100644 --- a/src/plugins/lang.js +++ b/src/plugins/lang.js @@ -15,8 +15,7 @@ function importAll(r) { } importAll(require.context('@/assets/translations/', true, /\.json$/)); - -export default new VueI18n({ +const vue18n = new VueI18n({ locale: 'en', fallbackLocale: 'en', silentFallbackWarn: true, @@ -51,4 +50,37 @@ export default new VueI18n({ return (choicesLength < 4) ? 2 : 3; } } -}) \ No newline at end of file +}) + +vue18n.toLocalNumbers = (str) => { + if (vue18n.locale == "my") { + // Translate to burmese numerals + var result = ""; + for (var i = 0; i < str.length; i++) { + var c = str.charCodeAt(i); + if (c >= 48 && c <= 57) { + result += String.fromCharCode(c + 0x1040 - 48); + } else { + result += String.fromCharCode(c); + } + } + return result; + } else if (vue18n.locale == "bo") { + // Translate to tibetan numerals + result = ""; + for (i = 0; i < str.length; i++) { + c = str.charCodeAt(i); + if (c >= 48 && c <= 57) { + result += String.fromCharCode(c + 0x0f20 - 48); + } else { + result += String.fromCharCode(c); + } + } + return result; + } + + return str; +}; + + +export default vue18n; \ No newline at end of file