mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
UX: respect current locale on topic map views date format (#28199)
* UX: respect current locale on topic map views date format * DEV: linting
This commit is contained in:
parent
e7f976a106
commit
48ac62dfef
@ -33,6 +33,10 @@ export class I18n {
|
|||||||
return this.locale || this.defaultLocale;
|
return this.locale || this.defaultLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get currentBcp47Locale() {
|
||||||
|
return this.currentLocale().replace("_", "-");
|
||||||
|
}
|
||||||
|
|
||||||
get pluralizationNormalizedLocale() {
|
get pluralizationNormalizedLocale() {
|
||||||
if (this.currentLocale() === "pt") {
|
if (this.currentLocale() === "pt") {
|
||||||
return "pt_PT";
|
return "pt_PT";
|
||||||
|
@ -161,7 +161,7 @@ export default class TopicViewsChart extends Component {
|
|||||||
maxTicksLimit: 15,
|
maxTicksLimit: 15,
|
||||||
callback: function (value) {
|
callback: function (value) {
|
||||||
const date = new Date(value + oneDay);
|
const date = new Date(value + oneDay);
|
||||||
return date.toLocaleDateString(undefined, {
|
return date.toLocaleDateString(I18n.currentBcp47Locale, {
|
||||||
month: "2-digit",
|
month: "2-digit",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
});
|
});
|
||||||
@ -189,7 +189,7 @@ export default class TopicViewsChart extends Component {
|
|||||||
const today = new Date();
|
const today = new Date();
|
||||||
date = today.getUTCDate();
|
date = today.getUTCDate();
|
||||||
}
|
}
|
||||||
return date.toLocaleDateString(undefined, {
|
return date.toLocaleDateString(I18n.currentBcp47Locale, {
|
||||||
month: "2-digit",
|
month: "2-digit",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Component from "@glimmer/component";
|
import Component from "@glimmer/component";
|
||||||
|
import I18n from "I18n";
|
||||||
|
|
||||||
export default class TopicViews extends Component {
|
export default class TopicViews extends Component {
|
||||||
adjustAggregatedData(stats) {
|
adjustAggregatedData(stats) {
|
||||||
@ -6,11 +7,14 @@ export default class TopicViews extends Component {
|
|||||||
|
|
||||||
stats.forEach((stat) => {
|
stats.forEach((stat) => {
|
||||||
const localDate = new Date(`${stat.viewed_at}T00:00:00Z`);
|
const localDate = new Date(`${stat.viewed_at}T00:00:00Z`);
|
||||||
const localDateStr = localDate.toLocaleDateString(undefined, {
|
const localDateStr = localDate.toLocaleDateString(
|
||||||
|
I18n.currentBcp47Locale,
|
||||||
|
{
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "2-digit",
|
month: "2-digit",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const existingStat = adjustedStats.find(
|
const existingStat = adjustedStats.find(
|
||||||
(s) => s.dateStr === localDateStr
|
(s) => s.dateStr === localDateStr
|
||||||
@ -34,7 +38,7 @@ export default class TopicViews extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
formatDate(date) {
|
formatDate(date) {
|
||||||
return date.toLocaleDateString(undefined, {
|
return date.toLocaleDateString(I18n.currentBcp47Locale, {
|
||||||
month: "2-digit",
|
month: "2-digit",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
});
|
});
|
||||||
|
@ -373,4 +373,22 @@ module("Unit | Utility | i18n", function (hooks) {
|
|||||||
"Degrades gracefully if MF definitions are not available."
|
"Degrades gracefully if MF definitions are not available."
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("currentBcp47Locale", function (assert) {
|
||||||
|
Object.entries({
|
||||||
|
pt_BR: "pt-BR",
|
||||||
|
en_GB: "en-GB",
|
||||||
|
bs_BA: "bs-BA",
|
||||||
|
en: "en",
|
||||||
|
it: "it",
|
||||||
|
es: "es",
|
||||||
|
}).forEach(([input, output]) => {
|
||||||
|
I18n.locale = input;
|
||||||
|
assert.strictEqual(
|
||||||
|
I18n.currentBcp47Locale,
|
||||||
|
output,
|
||||||
|
`returns '${output}' for '${input}'`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user