Feature #73234
openThe ability to use plural in xlf files
Added by Willi Martens almost 9 years ago. Updated 10 months ago.
0%
Description
<group id="day" restype="x-gettext-plurals">
<trans-unit id="day[0]">
<source>{0} day</source>
<target>{0} Tag</target>
</trans-unit>
<trans-unit id="day[1]">
<source>{0} days</source>
<target>{0} Tage</target>
</trans-unit>
</group>
I have not found any possibility to use this feature.
Files
Anmerkung 2020-06-18 115608.png (9.31 KB) Anmerkung 2020-06-18 115608.png | Armin Vieweg, 2020-06-18 11:56 |
Updated by Armin Vieweg over 4 years ago
Indeed. Actually the Xliff parser is respecting the pluralize in this format:
<group restype="x-gettext-plurals"> <trans-unit id="label.pollsFound[0]"> <source>Found %d polls.</source> </trans-unit> <trans-unit id="label.pollsFound[1]"> <source>Found one poll.</source> </trans-unit> </group>
But the LocalizationUtility in Extbase does not take the numeric arguments into account, when identifying the label.
Instead the [0]
is hardcoded.
It's about these lines of code in \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate
:
// The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG if (!empty(self::$LOCAL_LANG[$languageFilePath][$languageKey][$key][0]['target']) || isset(self::$LOCAL_LANG_UNSET[$languageFilePath][$languageKey][$key]) ) { // Local language translation for key exists $value = self::$LOCAL_LANG[$languageFilePath][$languageKey][$key][0]['target']; } elseif
Before this if-condition, we could check the first item in $arguments
. If it's numeric apply Xliff pluralization.
I'm not sure how complex this pluralization is to implement. But even if we would just differ between "1" and "n" entries, it would fit for most languages.
Updated by Armin Vieweg over 4 years ago
A very simple implementation of pluralize support could look like this:
$index = 0; if (is_array($arguments)) { $firstArgument = (int) reset($arguments); if ($firstArgument === 1) { $index = 1; } }
Now we pass $index
instead of 0
:
if (!empty(self::$LOCAL_LANG[$languageFilePath][$languageKey][$key][$index]['target']) || isset(self::$LOCAL_LANG_UNSET[$languageFilePath][$languageKey][$key]) ) { // Local language translation for key exists $value = self::$LOCAL_LANG[$languageFilePath][$languageKey][$key][$index]['target']; } // ...
And that's it:
Updated by Armin Vieweg over 4 years ago
According to this document http://cldr.unicode.org/index/cldr-spec/plural-rules we should at least implement:
- zero/default [0]
- one [1]
- other [2]
- "other" is used, if given
- otherwise zero/default
- "one" is used, if given
- otherwise zero/default
- "zero/default" is used
The key 0 is always given, also when a translation has no plural forms.
Updated by Armin Vieweg over 4 years ago
Here, I've copied the LocalizationUtility and added a few changes:
https://bitbucket.org/t--3/t3oodle/commits/e2d628861684804067570fcab715350a97c0db4e#chg-Classes/Utility/LocalizationUtility.php
The changes are wrapped with // TODO: START MODIFICATION
and // TODO: END MODIFICATION
to make it easier to spot.
- supports the plural forms "zero", "one" and "many".
- makes it possible to get overwritten by typoscript, with additional keyword "_pluralize":
plugin.tx_myext._LOCAL_LANG.de.label.itemsFound._pluralize { 0 = Nothing to see 1 = Just one item found 2 = %i items found }
Updated by Gerrit Code Review over 4 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Gerrit Code Review over 4 years ago
Patch set 13 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64911
Updated by Simon Schaufelberger almost 3 years ago
- Related to Feature #83075: LanguageService should support placeholders added
Updated by Georg Ringer 4 months ago
- Has duplicate Feature #104546: Support plural forms in language files added