DEV: Use consistent interpolation key format in translations

From now on client strings can easily be reused on the server and you don’t have to think about choosing the right format anymore.
This commit is contained in:
Gerhard Schlager 2020-06-02 18:41:23 +02:00
parent b3c8d36412
commit 0cf297725f
7 changed files with 248 additions and 233 deletions

View File

@ -20,7 +20,7 @@ export default Component.extend({
)
formattedName(name, nameKey, isCustomFlag, username) {
if (isCustomFlag) {
return name.replace("{{username}}", username);
return name.replace(/{{username}}|%{username}/, username);
} else {
return I18n.t("flagging.formatted_name." + nameKey);
}

View File

@ -10,7 +10,10 @@ export default Component.extend({
@discourseComputed("rs.score_type.title", "reviewable.target_created_by")
title(title, targetCreatedBy) {
if (title && targetCreatedBy) {
return title.replace("{{username}}", targetCreatedBy.username);
return title.replace(
/{{username}}|%{username}/,
targetCreatedBy.username
);
}
return title;

File diff suppressed because it is too large Load Diff

View File

@ -899,7 +899,7 @@ en:
short_description: 'A violation of <a href="%{base_path}/guidelines">our community guidelines</a>'
long_form: "flagged this as inappropriate"
notify_user:
title: "Send @{{username}} a message"
title: "Send @%{username} a message"
description: "I want to talk to this person directly and personally about their post."
short_description: "I want to talk to this person directly and personally about their post."
long_form: "messaged user"
@ -4826,9 +4826,9 @@ en:
title: "Reminder about old credentials"
body: |
Hello! This is a routine yearly security reminder from your Discourse instance.
As a courtesy, we wanted to let you know that the following credentials used on your Discourse instance have not been updated in more than two years:
%{keys}
No action is required at this time, however, it is considered good security practice to cycle all your important credentials every few years.

View File

@ -141,13 +141,20 @@ describe "i18n integrity checks" do
context "valid translations" do
invalid_relative_links = {}
invalid_relative_image_sources = {}
invalid_interpolation_key_format = {}
each_translation(english_yaml) do |key, value|
if value.match?(/href\s*=\s*["']\/[^\/]|\]\(\/[^\/]/i)
invalid_relative_links[key] = value
elsif value.match?(/src\s*=\s*["']\/[^\/]/i)
end
if value.match?(/src\s*=\s*["']\/[^\/]/i)
invalid_relative_image_sources[key] = value
end
if value.match?(/\{\{.+?}}/)
invalid_interpolation_key_format[key] = value
end
end
it "uses %{base_url} or %{base_path} for relative links" do
@ -159,6 +166,11 @@ describe "i18n integrity checks" do
keys = invalid_relative_image_sources.keys.join("\n")
expect(invalid_relative_image_sources).to be_empty, "The following keys have relative image sources, but do not start with %{base_url} or %{base_path}:\n\n#{keys}"
end
it "uses the %{key} as interpolation key format" do
keys = invalid_interpolation_key_format.keys.join("\n")
expect(invalid_interpolation_key_format).to be_empty, "The following keys use {{key}} instead of %{key} for interpolation keys:\n\n#{keys}"
end
end
end

View File

@ -490,7 +490,7 @@ export default {
},
{
name_key: "notify_user",
name: "Notify {{username}}",
name: "Notify %{username}",
description:
"This post contains something I want to talk to this person directly and privately about. Does not cast a flag.",
short_description:

View File

@ -320,7 +320,7 @@ PreloadStore.store("site", {
},
{
name_key: "notify_user",
name: "Notify {{username}}",
name: "Notify %{username}",
description:
"This post contains something I want to talk to this person directly and privately about.",
long_form: "notified user",