Project

General

Profile

Actions

Feature #73234

open

The ability to use plural in xlf files

Added by Willi Martens over 8 years ago. Updated 4 months ago.

Status:
Under Review
Priority:
Must have
Assignee:
-
Category:
Localization
Target version:
-
Start date:
2016-02-11
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
xlf
Complexity:
Sprint Focus:

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

Related issues 1 (1 open0 closed)

Related to TYPO3 Core - Feature #83075: LanguageService should support placeholdersNew2017-11-24

Actions
Actions #1

Updated by Riccardo De Contardi almost 8 years ago

  • Category set to Localization
Actions #2

Updated by Armin Vieweg almost 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.

Actions #3

Updated by Armin Vieweg almost 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:

Actions #4

Updated by Armin Vieweg almost 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]
When the quantity given is e.g. 5:
  • "other" is used, if given
  • otherwise zero/default
When the quantity given is 1:
  • "one" is used, if given
  • otherwise zero/default
When the quantity given is 0:
  • "zero/default" is used

The key 0 is always given, also when a translation has no plural forms.

Actions #5

Updated by Armin Vieweg almost 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.

This implementation
  • 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
      }
    
Actions #6

Updated by Gerrit Code Review almost 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

Actions #7

Updated by Gerrit Code Review almost 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

Actions #8

Updated by Gerrit Code Review almost 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

Actions #9

Updated by Gerrit Code Review almost 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

Actions #10

Updated by Gerrit Code Review almost 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

Actions #11

Updated by Gerrit Code Review almost 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

Actions #12

Updated by Gerrit Code Review almost 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

Actions #13

Updated by Gerrit Code Review almost 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

Actions #14

Updated by Gerrit Code Review almost 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

Actions #15

Updated by Gerrit Code Review almost 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

Actions #16

Updated by Gerrit Code Review almost 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

Actions #17

Updated by Gerrit Code Review almost 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

Actions #18

Updated by Gerrit Code Review almost 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

Actions #19

Updated by Simon Schaufelberger over 2 years ago

  • Related to Feature #83075: LanguageService should support placeholders added
Actions #20

Updated by leon jänicke 10 months ago

  • Tags set to xlf
Actions #21

Updated by Simon Schaufelberger 4 months ago

  • Description updated (diff)
Actions

Also available in: Atom PDF