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;
|
||||
}
|
||||
|
||||
get currentBcp47Locale() {
|
||||
return this.currentLocale().replace("_", "-");
|
||||
}
|
||||
|
||||
get pluralizationNormalizedLocale() {
|
||||
if (this.currentLocale() === "pt") {
|
||||
return "pt_PT";
|
||||
|
|
|
@ -161,7 +161,7 @@ export default class TopicViewsChart extends Component {
|
|||
maxTicksLimit: 15,
|
||||
callback: function (value) {
|
||||
const date = new Date(value + oneDay);
|
||||
return date.toLocaleDateString(undefined, {
|
||||
return date.toLocaleDateString(I18n.currentBcp47Locale, {
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
});
|
||||
|
@ -189,7 +189,7 @@ export default class TopicViewsChart extends Component {
|
|||
const today = new Date();
|
||||
date = today.getUTCDate();
|
||||
}
|
||||
return date.toLocaleDateString(undefined, {
|
||||
return date.toLocaleDateString(I18n.currentBcp47Locale, {
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
year: "numeric",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import Component from "@glimmer/component";
|
||||
import I18n from "I18n";
|
||||
|
||||
export default class TopicViews extends Component {
|
||||
adjustAggregatedData(stats) {
|
||||
|
@ -6,11 +7,14 @@ export default class TopicViews extends Component {
|
|||
|
||||
stats.forEach((stat) => {
|
||||
const localDate = new Date(`${stat.viewed_at}T00:00:00Z`);
|
||||
const localDateStr = localDate.toLocaleDateString(undefined, {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
});
|
||||
const localDateStr = localDate.toLocaleDateString(
|
||||
I18n.currentBcp47Locale,
|
||||
{
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
}
|
||||
);
|
||||
|
||||
const existingStat = adjustedStats.find(
|
||||
(s) => s.dateStr === localDateStr
|
||||
|
@ -34,7 +38,7 @@ export default class TopicViews extends Component {
|
|||
}
|
||||
|
||||
formatDate(date) {
|
||||
return date.toLocaleDateString(undefined, {
|
||||
return date.toLocaleDateString(I18n.currentBcp47Locale, {
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
});
|
||||
|
|
|
@ -373,4 +373,22 @@ module("Unit | Utility | i18n", function (hooks) {
|
|||
"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