From febe997beec6e7d344911412a6f560a07276dc97 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Wed, 2 Feb 2022 23:41:42 +0100 Subject: [PATCH] FIX: Regression in timezone name localizations (#15761) This also switches to using the NPM package for better build stability. And adds a clearer label in the alert that is displayed to show your current timezone (when changing timezones). --- .../addon/components/timezone-input.js | 30 +++++++++++-------- package.json | 2 +- .../discourse-local-dates-create-form.js | 8 +++-- .../discourse-local-dates-create-form.hbs | 3 +- .../common/discourse-local-dates.scss | 1 + .../config/locales/client.en.yml | 1 + yarn.lock | 9 +++--- 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/select-kit/addon/components/timezone-input.js b/app/assets/javascripts/select-kit/addon/components/timezone-input.js index 4590c703a7b..28a0c25e6d9 100644 --- a/app/assets/javascripts/select-kit/addon/components/timezone-input.js +++ b/app/assets/javascripts/select-kit/addon/components/timezone-input.js @@ -1,25 +1,29 @@ import ComboBoxComponent from "select-kit/components/combo-box"; -import { computed } from "@ember/object"; export default ComboBoxComponent.extend({ pluginApiIdentifiers: ["timezone-input"], classNames: ["timezone-input"], - nameProperty: null, - valueProperty: null, selectKitOptions: { filterable: true, allowAny: false, }, - content: computed(function () { - if ( - moment.locale() !== "en" && - typeof moment.tz.localizedNames === "function" - ) { - return moment.tz.localizedNames().mapBy("value"); - } else { - return moment.tz.names(); - } - }), + get nameProperty() { + return this.isLocalized ? "name" : null; + }, + + get valueProperty() { + return this.isLocalized ? "value" : null; + }, + + get content() { + return this.isLocalized ? moment.tz.localizedNames() : moment.tz.names(); + }, + + get isLocalized() { + return ( + moment.locale() !== "en" && typeof moment.tz.localizedNames === "function" + ); + }, }); diff --git a/package.json b/package.json index ddb9c608515..6a7bfc5edee 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "license": "GPL-2.0-only", "dependencies": { "@discourse/itsatrap": "^2.0.10", + "@discourse/moment-timezone-names-translations": "^1.0.0", "@fortawesome/fontawesome-free": "5.11.2", "@highlightjs/cdn-assets": "^10.7.0", "@json-editor/json-editor": "^2.6.1", @@ -30,7 +31,6 @@ "markdown-it": "10.0.0", "moment": "2.29.1", "moment-timezone": "0.5.31", - "moment-timezone-names-translations": "https://github.com/discourse/moment-timezone-names-translations", "pikaday": "1.8.0", "workbox-cacheable-response": "^4.3.1", "workbox-core": "^4.3.1", diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js b/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js index 46dee48eee6..c2a2f5f6a4e 100644 --- a/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js +++ b/plugins/discourse-local-dates/assets/javascripts/discourse/components/discourse-local-dates-create-form.js @@ -205,7 +205,7 @@ export default Component.extend({ @computed("currentUserTimezone") formatedCurrentUserTimezone(timezone) { - return timezone.replace("_", " ").replace("Etc/", "").split("/"); + return timezone.replace("_", " ").replace("Etc/", "").replace("/", ", "); }, @computed("formats") @@ -398,8 +398,10 @@ export default Component.extend({ return new Promise((resolve) => { loadScript("/javascripts/pikaday.js").then(() => { const options = { - field: this.$(`.fake-input`)[0], - container: this.$(`#picker-container-${this.elementId}`)[0], + field: this.element.querySelector(".fake-input"), + container: this.element.querySelector( + `#picker-container-${this.elementId}` + ), bound: false, format: "YYYY-MM-DD", reposition: false, diff --git a/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs b/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs index 196fb791c96..847a3b31cdf 100644 --- a/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs +++ b/plugins/discourse-local-dates/assets/javascripts/discourse/templates/components/discourse-local-dates-create-form.hbs @@ -7,7 +7,8 @@ {{#if isValid}} {{#if timezoneIsDifferentFromUserTimezone}}
- {{formatedCurrentUserTimezone}} {{currentPreview}} + {{i18n "discourse_local_dates.create.form.current_timezone"}} + {{formatedCurrentUserTimezone}}{{currentPreview}}
{{/if}} {{else}} diff --git a/plugins/discourse-local-dates/assets/stylesheets/common/discourse-local-dates.scss b/plugins/discourse-local-dates/assets/stylesheets/common/discourse-local-dates.scss index 9f2543d22cc..ee45d9826e7 100644 --- a/plugins/discourse-local-dates/assets/stylesheets/common/discourse-local-dates.scss +++ b/plugins/discourse-local-dates/assets/stylesheets/common/discourse-local-dates.scss @@ -262,6 +262,7 @@ b { margin-right: 0.5em; + margin-left: 0.5em; } b + p { diff --git a/plugins/discourse-local-dates/config/locales/client.en.yml b/plugins/discourse-local-dates/config/locales/client.en.yml index a968b96f870..a18bddd9762 100644 --- a/plugins/discourse-local-dates/config/locales/client.en.yml +++ b/plugins/discourse-local-dates/config/locales/client.en.yml @@ -25,6 +25,7 @@ en: format_title: Date format timezone: Timezone until: Until... + current_timezone: "Current timezone:" recurring: every_day: "Every day" every_week: "Every week" diff --git a/yarn.lock b/yarn.lock index c7471bdcc01..8b99ee19ead 100644 --- a/yarn.lock +++ b/yarn.lock @@ -111,6 +111,11 @@ resolved "https://registry.yarnpkg.com/@discourse/itsatrap/-/itsatrap-2.0.10.tgz#c7e750eeb32b54e769e952c4ecc472213eb1385a" integrity sha512-Jn1gdiyHMGUsmUfLFf4Q7VnTAv0l7NePbegU6pKhKHEmbzV3FosGxq30fTOYgVyTS1bxqGjlA6LvQttJpv3ROw== +"@discourse/moment-timezone-names-translations@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@discourse/moment-timezone-names-translations/-/moment-timezone-names-translations-1.0.0.tgz#b22344456513d37c81baf384a41487b539b91534" + integrity sha512-4xr1QWQ0nzmFa2ZXQgWZA+dtE/BU2ePA+qkJWPFzNpq4ZnQi8MmMMAS2285t3rc2ySMBQqYaAArmcSUiufUgRA== + "@ember-data/rfc395-data@^0.0.4": version "0.0.4" resolved "https://registry.yarnpkg.com/@ember-data/rfc395-data/-/rfc395-data-0.0.4.tgz#ecb86efdf5d7733a76ff14ea651a1b0ed1f8a843" @@ -2933,10 +2938,6 @@ module-deps@^6.2.3: through2 "^2.0.0" xtend "^4.0.0" -"moment-timezone-names-translations@https://github.com/discourse/moment-timezone-names-translations": - version "0.0.0" - resolved "https://github.com/discourse/moment-timezone-names-translations#5f576fc6355d8e636783bfb7b0214a5d74a5399d" - moment-timezone@0.5.31: version "0.5.31" resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.31.tgz#9c40d8c5026f0c7ab46eda3d63e49c155148de05"