mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 01:44:02 +08:00
a16faa27cd
When searching for site texts for admin using the english version of the text, previously we would show the english version in the results _even if_ there was another locale translated version available when a locale was selected from the dropdown. This commit adds a "Only show results in selected locale" checkbox option which will instead make it so the results shown are in the target locale, making it easier for translators to tell when there is actually translations vs. missing tranlsations.
64 lines
1.6 KiB
Plaintext
64 lines
1.6 KiB
Plaintext
import Component from "@glimmer/component";
|
|
import { fn } from "@ember/helper";
|
|
import { action } from "@ember/object";
|
|
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
|
import DButton from "discourse/components/d-button";
|
|
import concatClass from "discourse/helpers/concat-class";
|
|
import highlightHTML from "discourse/lib/highlight-html";
|
|
import { bind } from "discourse-common/utils/decorators";
|
|
|
|
export default class SiteTextSummary extends Component {
|
|
@action
|
|
highlightSearchTerm(element) {
|
|
const term = this.#searchTerm();
|
|
|
|
if (term) {
|
|
highlightHTML(
|
|
element.querySelector(".site-text-id, .site-text-value"),
|
|
term,
|
|
{
|
|
className: "text-highlight",
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
@action
|
|
onClick() {
|
|
this.args.editAction(this.siteText);
|
|
}
|
|
|
|
@bind
|
|
#searchTerm() {
|
|
const regex = this.args.searchRegex;
|
|
const siteText = this.args.siteText;
|
|
|
|
if (regex && siteText) {
|
|
const matches = siteText.value.match(new RegExp(regex, "i"));
|
|
if (matches) {
|
|
return matches[0];
|
|
}
|
|
}
|
|
|
|
return this.args.term;
|
|
}
|
|
|
|
<template>
|
|
<div
|
|
class={{concatClass "site-text" (if @siteText.overridden "overridden")}}
|
|
{{didInsert this.highlightSearchTerm}}
|
|
data-site-text-id={{@siteText.id}}
|
|
>
|
|
<DButton
|
|
@label="admin.site_text.edit"
|
|
@action={{fn @editAction @siteText}}
|
|
class="btn-default site-text-edit"
|
|
/>
|
|
<h3 class="site-text-id">{{@siteText.id}}</h3>
|
|
<div class="site-text-value">{{@siteText.value}}</div>
|
|
|
|
<div class="clearfix"></div>
|
|
</div>
|
|
</template>
|
|
}
|