DEV: Use consistent interpolation key format in translations

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.

diff --git a/app/assets/javascripts/discourse/app/components/flag-action-type.js b/app/assets/javascripts/discourse/app/components/flag-action-type.js
index 93de11b..50f041d 100644
--- a/app/assets/javascripts/discourse/app/components/flag-action-type.js
+++ b/app/assets/javascripts/discourse/app/components/flag-action-type.js
@@ -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);
     }
diff --git a/app/assets/javascripts/discourse/app/components/reviewable-score.js b/app/assets/javascripts/discourse/app/components/reviewable-score.js
index ee36959..d9b1849 100644
--- a/app/assets/javascripts/discourse/app/components/reviewable-score.js
+++ b/app/assets/javascripts/discourse/app/components/reviewable-score.js
@@ -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;
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 95830e3..8d7d172 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -34,8 +34,8 @@ en:
             mb: MB
             tb: TB
       short:
-        thousands: "{{number}}k"
-        millions: "{{number}}M"
+        thousands: "%{number}k"
+        millions: "%{number}M"
     dates:
       # Use Moment.js format string: https://momentjs.com/docs/#/displaying/format/
       time: "HH:mm"
@@ -265,11 +265,11 @@ en:
     weekly: "weekly"
     every_month: "every month"
     every_six_months: "every six months"
-    max_of_count: "max of {{count}}"
+    max_of_count: "max of %{count}"
     alternation: "or"
     character_count:
-      one: "{{count}} character"
-      other: "{{count}} characters"
+      one: "%{count} character"
+      other: "%{count} characters"
 
     related_messages:
       title: "Related Messages"
@@ -352,16 +352,16 @@ en:
         no_value: "No, keep"
 
     topic_count_latest:
-      one: "See {{count}} new or updated topic"
-      other: "See {{count}} new or updated topics"
+      one: "See %{count} new or updated topic"
+      other: "See %{count} new or updated topics"
 
     topic_count_unread:
-      one: "See {{count}} unread topic"
-      other: "See {{count}} unread topics"
+      one: "See %{count} unread topic"
+      other: "See %{count} unread topics"
 
     topic_count_new:
-      one: "See {{count}} new topic"
-      other: "See {{count}} new topics"
+      one: "See %{count} new topic"
+      other: "See %{count} new topics"
 
     preview: "preview"
     cancel: "cancel"
@@ -372,7 +372,7 @@ en:
 
     upload: "Upload"
     uploading: "Uploading..."
-    uploading_filename: "Uploading: {{filename}}..."
+    uploading_filename: "Uploading: %{filename}..."
     clipboard: "clipboard"
     uploaded: "Uploaded!"
 
@@ -434,7 +434,7 @@ en:
         optional: "You can claim this item to prevent others from reviewing it."
         required: "You must claim items before you can review them."
         claimed_by_you: "You've claimed this item and can review it."
-        claimed_by_other: "This item can only be reviewed by <b>{{username}}</b>."
+        claimed_by_other: "This item can only be reviewed by <b>%{username}</b>."
       claim:
         title: "claim this topic"
       unclaim:
@@ -455,7 +455,7 @@ en:
       view_pending: "view pending"
       topic_has_pending:
         one: "This topic has <b>%{count}</b> post pending approval"
-        other: "This topic has <b>{{count}}</b> posts pending approval"
+        other: "This topic has <b>%{count}</b> posts pending approval"
       title: "Review"
       topic: "Topic:"
       filtered_topic: "You have filtered to reviewable content in a single topic."
@@ -473,17 +473,17 @@ en:
 
       user_percentage:
         summary:
-          one: "{{agreed}}, {{disagreed}}, {{ignored}} ({{count}} total flag)"
-          other: "{{agreed}}, {{disagreed}}, {{ignored}} ({{count}} total flags)"
+          one: "%{agreed}, %{disagreed}, %{ignored} (%{count} total flag)"
+          other: "%{agreed}, %{disagreed}, %{ignored} (%{count} total flags)"
         agreed:
-          one: "{{count}}% agree"
-          other: "{{count}}% agree"
+          one: "%{count}% agree"
+          other: "%{count}% agree"
         disagreed:
-          one: "{{count}}% disagree"
-          other: "{{count}}% disagree"
+          one: "%{count}% disagree"
+          other: "%{count}% disagree"
         ignored:
-          one: "{{count}}% ignore"
-          other: "{{count}}% ignore"
+          one: "%{count}% ignore"
+          other: "%{count}% ignore"
       topics:
         topic: "Topic"
         reviewable_count: "Count"
@@ -493,10 +493,10 @@ en:
         details: "details"
         unique_users:
           one: "%{count} user"
-          other: "{{count}} users"
+          other: "%{count} users"
       replies:
         one: "%{count} reply"
-        other: "{{count}} replies"
+        other: "%{count} replies"
       edit: "Edit"
       save: "Save"
       cancel: "Cancel"
@@ -565,25 +565,25 @@ en:
         description: "We've received your new post but it needs to be approved by a moderator before it will appear. Please be patient."
         pending_posts:
           one: "You have <strong>%{count}</strong> post pending."
-          other: "You have <strong>{{count}}</strong> posts pending."
+          other: "You have <strong>%{count}</strong> posts pending."
         ok: "OK"
 
     user_action:
-      user_posted_topic: "<a href='{{userUrl}}'>{{user}}</a> posted <a href='{{topicUrl}}'>the topic</a>"
-      you_posted_topic: "<a href='{{userUrl}}'>You</a> posted <a href='{{topicUrl}}'>the topic</a>"
-      user_replied_to_post: "<a href='{{userUrl}}'>{{user}}</a> replied to <a href='{{postUrl}}'>{{post_number}}</a>"
-      you_replied_to_post: "<a href='{{userUrl}}'>You</a> replied to <a href='{{postUrl}}'>{{post_number}}</a>"
-      user_replied_to_topic: "<a href='{{userUrl}}'>{{user}}</a> replied to <a href='{{topicUrl}}'>the topic</a>"
-      you_replied_to_topic: "<a href='{{userUrl}}'>You</a> replied to <a href='{{topicUrl}}'>the topic</a>"
-
-      user_mentioned_user: "<a href='{{user1Url}}'>{{user}}</a> mentioned <a href='{{user2Url}}'>{{another_user}}</a>"
-      user_mentioned_you: "<a href='{{user1Url}}'>{{user}}</a> mentioned <a href='{{user2Url}}'>you</a>"
-      you_mentioned_user: "<a href='{{user1Url}}'>You</a> mentioned <a href='{{user2Url}}'>{{another_user}}</a>"
-
-      posted_by_user: "Posted by <a href='{{userUrl}}'>{{user}}</a>"
-      posted_by_you: "Posted by <a href='{{userUrl}}'>you</a>"
-      sent_by_user: "Sent by <a href='{{userUrl}}'>{{user}}</a>"
-      sent_by_you: "Sent by <a href='{{userUrl}}'>you</a>"
+      user_posted_topic: "<a href='%{userUrl}'>%{user}</a> posted <a href='%{topicUrl}'>the topic</a>"
+      you_posted_topic: "<a href='%{userUrl}'>You</a> posted <a href='%{topicUrl}'>the topic</a>"
+      user_replied_to_post: "<a href='%{userUrl}'>%{user}</a> replied to <a href='%{postUrl}'>%{post_number}</a>"
+      you_replied_to_post: "<a href='%{userUrl}'>You</a> replied to <a href='%{postUrl}'>%{post_number}</a>"
+      user_replied_to_topic: "<a href='%{userUrl}'>%{user}</a> replied to <a href='%{topicUrl}'>the topic</a>"
+      you_replied_to_topic: "<a href='%{userUrl}'>You</a> replied to <a href='%{topicUrl}'>the topic</a>"
+
+      user_mentioned_user: "<a href='%{user1Url}'>%{user}</a> mentioned <a href='%{user2Url}'>%{another_user}</a>"

[... diff too long, it was truncated ...]

GitHub sha: 0cf29772

1 Like

This commit appears in #9963 which was approved by eviltrout. It was merged by gschlager.