diff --git a/framework/core/js/lib/Translator.js b/framework/core/js/lib/Translator.js index 82e65a11c..3a1d0970d 100644 --- a/framework/core/js/lib/Translator.js +++ b/framework/core/js/lib/Translator.js @@ -78,7 +78,7 @@ export default class Translator { } }); - return translation; + return translation.filter(part => part); } return fallback || [key]; diff --git a/framework/core/js/lib/helpers/punctuate.js b/framework/core/js/lib/helpers/punctuate.js deleted file mode 100644 index 92899afc1..000000000 --- a/framework/core/js/lib/helpers/punctuate.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * The `punctuate` helper formats a list of strings (e.g. names) to read - * fluently in the application's locale. - * - * @example - * punctuate(['Toby', 'Franz', 'Dominion']) - * // Toby, Franz, and Dominion - * - * @param {Array} items - * @return {Array} - */ -export default function punctuate(items) { - const punctuated = []; - - // FIXME: update to use translation - items.forEach((item, i) => { - punctuated.push(item); - - // If this item is not the last one, then we will follow it with some - // punctuation. If the list is more than 2 items long, we'll add a comma. - // And if this is the second-to-last item, we'll add 'and'. - if (i < items.length - 1) { - punctuated.push((items.length > 2 ? ', ' : '') + (i === items.length - 2 ? ' and ' : '')); - } - }); - - return punctuated; -}; diff --git a/framework/core/js/lib/helpers/punctuateSeries.js b/framework/core/js/lib/helpers/punctuateSeries.js new file mode 100644 index 000000000..eff9c64a2 --- /dev/null +++ b/framework/core/js/lib/helpers/punctuateSeries.js @@ -0,0 +1,35 @@ +/** + * The `punctuateSeries` helper formats a list of strings (e.g. names) to read + * fluently in the application's locale. + * + * ```js + * punctuateSeries(['Toby', 'Franz', 'Dominion']) // Toby, Franz, and Dominion + * ``` + * + * @param {Array} items + * @return {VirtualElement} + */ +export default function punctuateSeries(items) { + if (items.length === 2) { + return app.trans('core.lib.series_two_text', { + first: items[0], + second: items[1] + }); + } else if (items.length >= 3) { + // If there are three or more items, we will join all of the items up until + // the second-to-last one with the equivalent of a comma, and then we will + // feed that into the translator along with the last two items. + const first = items + .slice(0, items.length - 2) + .reduce((list, item) => list.concat([item, app.trans('core.lib.series_glue_text')]), []) + .slice(0, -1); + + return app.trans('core.lib.series_three_text', { + first, + second: items[items.length - 2], + third: items[items.length - 1] + }); + } + + return items; +} diff --git a/framework/core/src/Admin/Controller/ClientController.php b/framework/core/src/Admin/Controller/ClientController.php index fe2ecd192..aa3eb3c89 100644 --- a/framework/core/src/Admin/Controller/ClientController.php +++ b/framework/core/src/Admin/Controller/ClientController.php @@ -31,7 +31,7 @@ class ClientController extends BaseClientController /** * {@inheritdoc} */ - protected $translationKeys = ['core.admin']; + protected $translationKeys = ['core.admin', 'core.lib']; /** * @var ExtensionManager diff --git a/framework/core/src/Forum/Controller/ClientController.php b/framework/core/src/Forum/Controller/ClientController.php index 7260cc155..ef3bf8fef 100644 --- a/framework/core/src/Forum/Controller/ClientController.php +++ b/framework/core/src/Forum/Controller/ClientController.php @@ -27,7 +27,7 @@ class ClientController extends AbstractClientController /** * {@inheritdoc} */ - protected $translationKeys = ['core.forum']; + protected $translationKeys = ['core.forum', 'core.lib']; /** * {@inheritdoc}