From f8871657cef70eeeea1e627cf72a717ed74211f6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 13 Feb 2020 22:32:36 +0100 Subject: [PATCH] Add a note about plurals Signed-off-by: Joas Schilling --- developer_manual/app/view/l10n.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/developer_manual/app/view/l10n.rst b/developer_manual/app/view/l10n.rst index 146152a61..d6aa33f84 100644 --- a/developer_manual/app/view/l10n.rst +++ b/developer_manual/app/view/l10n.rst @@ -55,14 +55,17 @@ Strings can then be translated in the following way: } public sayHello() { + // Simple string return $this->l->t('Hello'); } public function getAuthorName($name) { + // String using a parameter return $this->l->t('Getting author %1$s', [$name]); } public function getAuthors($count, $city) { + // Translation with plural return $this->l->n( '%n author is currently in the city %1$s', // singular string '%n authors are currently in the city %1$s', // plural string @@ -72,6 +75,21 @@ Strings can then be translated in the following way: } } +Correct plurals +""""""""""""""" + +If you use a plural, you **must** also use the ``%n`` placeholder. The placeholder defines the plural and the word without the number preceding is wrong. If you don't know/have a number for your translation, e.g. because you don't know how many items are going to be selected, just use an undefined plural. They exist in every language and have one form. They do not follow the normal plural pattern. + +Example: + +.. code-block:: php + + // BAD: Plural without count + $title = $l->n('Import calendar', 'Import calendars', $selectionLength) + // BETTER: Plural has count, but disrupting to read and unnecessary information + $title = $l->n('Import %n calendar', 'Import %n calendars', $selectionLength) + // BEST: Simple string with undefined plural + $title = $l->t('Import calendars') Templates