$30 off During Our Annual Pro Sale. View Details »

i18n and L10n in TYPO3 Flow

i18n and L10n in TYPO3 Flow

Karsten Dambekalns

October 06, 2012
Tweet

More Decks by Karsten Dambekalns

Other Decks in Programming

Transcript

  1. Inspiring people to
    share
    i18n and L10n in
    TYPO3 Flow
    Karsten Dambekalns

    View Slide

  2. Inspiring people to
    share
    co-lead of TYPO3 Neos and Flow
    35 years old
    lives in Lübeck, Germany
    1 wife, 3 sons, 1 espresso machine
    likes canoeing and climbing
    Karsten Dambekalns

    View Slide

  3. Inspiring people to
    share
    Basics
    i18n is the process of making software localizable
    L10n means actually
    • formatting dates, numbers, …
    • translating text
    • adjusting other things (images, …)

    View Slide

  4. Inspiring people to
    share
    Locale
    Locale instances encapsulate a locale identifier
    Locales define the language and formats to use
    Locales form a hierarchy
    • en is a parent of en_US which is a parent of
    en_US_POSIX
    • Thus items for the en_US locale that do not
    exist, will be used from the en locale if available

    View Slide

  5. Inspiring people to
    share
    What you need
    A way to translate in templates
    A way to store translations of labels
    Formatters for dates, numbers, …
    An API for use in PHP

    View Slide

  6. Inspiring people to
    share
    f:translate
    the way of translating you will use most

    {f:translate(id: 'my.label.1')}
    translation by label is possible, but discouraged
    • less reliable than id-based translation
    • prohibits changes to the original label

    View Slide

  7. Inspiring people to
    share
    f:translate
    source="Registration"
    package="Acme.Demo"/>
    arguments="{0: 'hi'}" quantity="2"/>

    View Slide

  8. Inspiring people to
    share
    f:form.select
    has translation support built in
    translate="{by: 'id'}" />
    translate="{by: 'id', prefix: 'payment.options.',
    package: 'Acme.Demo.Translations'}" />

    View Slide

  9. Inspiring people to
    share
    Message catalogs
    XML Localisation Interchange File Format is the
    standard we use
    Looked up in well-known location
    Resources/
    Private/
    Translations/
    /
    .xlf

    View Slide

  10. Inspiring people to
    share
    XLIFF basics
    An XLIFF file can hold translations for one locale
    It contains one or more elements
    corresponding to a source
    Localizable data is stored in
    elements which contain a
    element to store the source text and a
    (non-mandatory) element to store the
    translated text

    View Slide

  11. Inspiring people to
    share
    Text
    Text



    <file original="" product-name="Acme.Demo" source-
    language="en" datatype="plaintext">











    My Label 1








    file>

    View Slide

  12. Inspiring people to
    share



    <file original="" product-name="Acme.Demo" source-
    language="en" datatype="plaintext">











    My Label 1




    Mein Aufkleber 1








    file>

    View Slide

  13. Inspiring people to
    share
    i18n configuration
    Default locale can be set in Settings.yaml
    Locale fallback rules are configurable
    TYPO3:
    Flow:
    i18n:
    defaultLocale: de
    fallbackRule:
    strict: FALSE
    order: [lv, en]

    View Slide

  14. Inspiring people to
    share
    i18n configuration
    Default locale can be set in Settings.yaml
    Locale fallback rules are configurable
    TYPO3:
    Flow:
    i18n:
    defaultLocale: de
    fallbackRule:
    strict: FALSE
    order: [lv, en]

    View Slide

  15. Inspiring people to
    share
    Placeholder use
    $this->view->assign('foo', 'QUUX');
    $this->view->assign('bar', 'BAZ');


    I have {0} and {1}

    {1} habe ich und {0} habe ich auch


    View Slide

  16. Inspiring people to
    share
    String placeholders
    $this->view->assign('foo', 'QUUX');
    $this->view->assign('bar', 'BAZ');


    I have {some} and {thing}

    {thing} habe ich und {some} habe ich auch


    * will be available with Flow 2.0

    View Slide

  17. Inspiring people to
    share
    Using formatters
    $this->view->assign('currentDateAndTime', new \DateTime());
    $this->view->assign('currentCost', 1.25);

    At {0,datetime} it costs {1,number} monetary units


    View Slide

  18. Inspiring people to
    share
    Plural forms
    The CLDR defines six plural forms
    • zero, one, two, few, many, other
    Different languages use more or less forms
    • singular and plurals for English
    • one, few and other for Polish
    • only other for Japanese

    View Slide

  19. Inspiring people to
    share




    There is this quark






    There are these quarks



    Plural forms

    View Slide

  20. Inspiring people to
    share
    L10n of resources
    Resources can be localized as well
    The locale is part of the name
    • Image.png
    • Image.de.png
    • Image.lv.png
    Usable for all resources
    • Images, templates, …

    View Slide

  21. Inspiring people to
    share
    f:resource
    * see Known issues


    uses localized resources by default*

    View Slide

  22. Inspiring people to
    share
    i18n in PHP code
    TYPO3\Flow\I18n\Translator
    • translateById()
    • translateByOriginalLabel()
    TYPO3\Flow\I18n\Service
    • getConfiguration()
    • getLocalizedFilename()
    TYPO3\Flow\I18n\Formatter\*

    View Slide

  23. Inspiring people to
    share
    /**
    * @param string $locale
    * @return void
    */
    public function selectAction($locale = NULL) {

    if ($locale !== NULL) {


    $this->i18nService->getConfiguration()->setCurrentLocale(


    new \TYPO3\Flow\I18n\Locale($locale)


    );

    }

    $this->forward('index');
    }
    Setting current locale
    WARNING:
    Stupid example

    View Slide

  24. Inspiring people to
    share
    Tips & Tricks
    Split catalogs at logical points
    Try to use.a.clever.id.system
    Avoid hardcoded labels from the start
    To change "original" labels simply translate to
    "original" language

    View Slide

  25. Inspiring people to
    share
    Known issues
    L10n support in f:resource VH pending in review
    Fallback per label is missing, currently only done
    per catalog
    Overriding parts of catalogs is missing
    Model translation still missing

    View Slide

  26. Inspiring people to
    share
    Thank You!
    These slides can be found at:
    http://speakerdeck.com/kdambekalns
    http://slideshare.net/kfish
    Give me feedback:
    [email protected] | [email protected]
    Download Flow: http://flow.typo3.org
    Follow me on twitter: @kdambekalns
    Support me using

    View Slide

  27. View Slide