Feature #6724

Internationalization, locale, multi-language ect.

Added by Arno Dudek over 5 years ago. Updated almost 5 years ago.

Status:Resolved Start date:
Priority:Should have Due date:
Assigned To:Karol Gusak % Done:

100%

Category:I18n
Target version:-
PHP Version: Complexity:
Has patch:

Description

Hi!

(first: sorry for my bad english ;)

I'm testing FLOW3 for my project with multi-language support. For that I needed a view helper which do that like the f:translate. In the attachment is my work now. It's an extended internationalization concept. I thought it's an good idea to put them all into a subpackage called "Internationalization". I could imagine to replace this with the current subpackage locale of FLOW3 (FLOW3/Locale/).

I hope you'll find it usefull or even inspired.

For now the package is just an application package. If you think its usefull and shoul be integrated, I will try to write a patch for the FLOW3/Locale/.

The package handles the current used locale and provide many cool features:
- extended locale class with seperatly validation by using the CLDR
- CLDR reader
- language fallback by configuration and/or by getting the accept language of the browser.
- loading of language files
- supported language files are XML (also TYPO3 files) and YAML (better for editing)
- and view helper for translated strings with more cool options

The language file handling is a little bit different to TYPO3. Every language get an own directory:
Resources/Privat/Languages/Standard/en_US or Resources/Privat/Languages/Standard/de_DE
I thought this would be better, if there are also images with text.

The view helper "localized.string" comes with new options "pluralValue" and "splitKey". More view helper, like localized.resource, can come.

= Examples =

Localized strings (e.g. in the YAML-file Standard/en_US/LocalizedStrings.yaml)

exampleString1: 'Firstname:'
exampleString2:
  1: 'My %sst %s String for {split: Me, You}'
  2: 'My %snd %s String for {split: Me, You}'
  4: 'My %sth %s String for {split: Me, You}'

Example 1
<lang:localized.string key="exampleString1"/> A name

Output:
Firstname: A name

Example 2: Replace strings, Plurals and split options
1: <lang:localized.string key="exampleString2" packageName="AnotherPackage" controllerName="AnotherController" replaceStrings="{0: 1, 1: 'replaced'}" pluralValue="1" splitKey="0"/>
2: <lang:localized.string key="exampleString2" packageName="AnotherPackage" controllerName="AnotherController" replaceStrings="{0: 2, 1: 'replaced'}" pluralValue="2" splitKey="1"/>
3: <lang:localized.string key="exampleString2" packageName="AnotherPackage" controllerName="AnotherController" replaceStrings="{0: 3, 1: 'replaced'}" pluralValue="3" splitKey="0"/>
4: <lang:localized.string key="exampleString2" packageName="AnotherPackage" controllerName="AnotherController" replaceStrings="{0: 4, 1: 'replaced'}" pluralValue="4" splitKey="1"/>
5: <lang:localized.string key="exampleString2" packageName="AnotherPackage" controllerName="AnotherController" replaceStrings="{0: 5, 1: 'replaced'}" pluralValue="5" splitKey="0"/>

Output:
1: My 1st replaced String for Me
2: My 2nd replaced String for You
3: My 3nd replaced String for Me  // Here you can see "3nd" cause this is missing in the language file.
4: My 4th replaced String for You
5: My 5th replaced String for Me  // Plural values greater than or equal to the current value takes the last matching.

Nevermore "1 Records found" !!! :D

lg ad

Core.zip (26.5 kB) Arno Dudek, 2010-03-06 18:22


Related issues

related to TYPO3.Flow - Feature #7721: Implement locale-aware resource management subsystem Resolved
related to TYPO3.Flow - Feature #7722: Implement CLDR data reader Resolved
related to TYPO3.Flow - Feature #7723: Implement message resources support (XLIFF, plural forms) Resolved
related to TYPO3.Flow - Feature #7724: Implement Message Formatter subsystem Resolved
related to TYPO3.Flow - Feature #7720: Implement automatic locale detection Resolved

History

#1 Updated by Robert Lemke over 5 years ago

  • Target version deleted (1.0 alpha 9)
  • Start date deleted (2010-03-06)

#2 Updated by Karsten Dambekalns about 5 years ago

  • Assigned To set to Karol Gusak

#3 Updated by Karol Gusak about 5 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Thank you Arno Dudek for this code - I found inspiration here in various aspects!

All the features mentioned in the issue's description will be implemented in Locale subpackage, but some of them will be different. Main differences:
  • Locale validation isn't done in Locale class itself, but external methods are used (see issue #6628)
  • XLIFF file format is used for language files
  • Resources are locale-agnostic; there can exist many resources with the same name, except the locale tag appended on the end of the name, in order to provide transparent locale support for resources (see issue #7721)
  • No splitKey in view helper for plural rules

#4 Updated by Arno Dudek about 5 years ago

Glad to help you.

In my documentation the use of the splitKey could be misleading. The idee behind is to use it for personal pronoun. So you can make gender related messages, e.g for the salutations, and don't need many if-else-statements in your template:

Dear {split: "Mr.", "Mrs."} {assress.name}

But it could be also done if the localized string automatically (or with an attribute to activate) send through the Fluid engine.

lg ad

Also available in: Atom PDF