Skip to content

Commit

Permalink
Improve range formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Sep 20, 2022
1 parent 7032a00 commit 4f16229
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/i18n/I18N.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ public function translate($category, $message, $params, $language)
}
}

// Normalize ranges to use thin spaces and en-dashes (see https://clagnut.com/blog/2419)
$translation = preg_replace('/(?<=\d) ?(?:-|–|—) ?(?=\d)/', ' – ', $translation);

if ($this->_shouldAddTranslationDebugOutput()) {
switch ($category) {
case 'site':
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/web/assets/cp/src/js/Craft.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ $.extend(Craft, {
}

if (params) {
return this.formatMessage(message, params);
message = this.formatMessage(message, params);
}

return message;
// Normalize ranges to use thin spaces and en-dashes (see https://clagnut.com/blog/2419)
return message.replace(/(\d) ?(?:-|–|—) ?(\d)/, '$1 – $2', message);
},

formatMessage: function (pattern, args) {
Expand Down

0 comments on commit 4f16229

Please sign in to comment.