DEV: Convert count-i18n to gjs (#26888)

This commit is contained in:
Jarek Radosz 2024-05-06 21:03:39 +02:00 committed by GitHub
parent 79870d3a1e
commit 16cd098de9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 24 deletions

View File

@ -0,0 +1,26 @@
import Component from "@glimmer/component";
import { service } from "@ember/service";
import { htmlSafe } from "@ember/template";
import i18n from "discourse-common/helpers/i18n";
export default class CountI18n extends Component {
@service currentUser;
get fullKey() {
let key = this.args.key;
if (this.args.suffix) {
key += this.args.suffix;
}
if (this.currentUser?.new_new_view_enabled && key === "topic_count_new") {
key = "topic_count_latest";
}
return key;
}
<template>
<span>{{htmlSafe (i18n this.fullKey count=@count)}}</span>
</template>
}

View File

@ -1 +0,0 @@
{{this.i18nCount}}

View File

@ -1,21 +0,0 @@
import Component from "@ember/component";
import { htmlSafe } from "@ember/template";
import I18n from "discourse-i18n";
export default Component.extend({
tagName: "span",
i18nCount: null,
didReceiveAttrs() {
this._super(...arguments);
let fullKey = this.key + (this.suffix || "");
if (
this.currentUser?.new_new_view_enabled &&
fullKey === "topic_count_new"
) {
fullKey = "topic_count_latest";
}
this.set("i18nCount", htmlSafe(I18n.t(fullKey, { count: this.count })));
},
});

View File

@ -36,8 +36,7 @@
{{if this.model.loadingBefore 'loading'}}"
>
<CountI18n
@key="topic_count_"
@suffix="latest"
@key="topic_count_latest"
@count={{or this.model.loadingBefore this.incomingCount}}
/>
{{#if @model.loadingBefore}}