Multilingual Sites in Craft 3

0f99e17a33cec3966f5a3751b05b5fbb?s=47 Zoltan Varady
September 27, 2018

Multilingual Sites in Craft 3

The challenges of multilingual sites in general, and how to implement them using Craft CMS version 3

0f99e17a33cec3966f5a3751b05b5fbb?s=128

Zoltan Varady

September 27, 2018
Tweet

Transcript

  1. 5.
  2. 6.
  3. 7.
  4. 9.
  5. 10.
  6. 11.
  7. 13.
  8. 14.
  9. 18.
  10. 19.
  11. 21.
  12. 23.

    Who will do the translation? Internally, by the content team

    By the developers Outsourced to a translation agency via an API? Automated translation
  13. 24.

    Translation workflow Do you need to publish all languages at

    once? Proofreading / approval Translation management tools

  14. 26.

    To borrow from Drupal Content translation (entries, categories, etc) Interface

    translation (static messages, Craft::t, twig’s | t filter) Configuration translation (settings, email templates…)
  15. 28.

    Belgian Site Group Swiss Site Group Schwiizerdütch de-CH Swiss French

    fr-CH Swiss Italian it-CH Flemish nl-BE Belgian French fr-BE Belgian German de-BE
  16. 29.

    Not So Fancy Fancy Shoes en-GB Shirts en-GB Pants en-GB

    Shoes en-GB Shirts en-GB Pants en-GB
  17. 32.

    Multi-valued fields Matrix Categories, tags Related entries Assets but not

    Tables (use Matrix or Super Table instead if you need it)
  18. 33.

    pizza dough tomatoes mozzarella ham pineapple pizzatészta paradicsom mozzarella kolbász

    pizza dough tomatoes mozzarella pizzatészta paradicsom mozzarella
  19. 34.
  20. 36.

    Localization is more than words 05/06/2018 vs 06/05/2018 vs 2018.

    06. 05. 2,100.99 vs 2 100,99 $100 vs 100 EUR GMT UTC DST CET PST 1 hour, 2 hours vs نابْح ُ ص باح ْ صَأ بِحاص
  21. 37.

    Yii 2 + INTL = FTW {{ 'Hello {name}!' |

    t({ name: 'Zoltan' }) }} => Hello Zoltan {{ 'Hello {0}!' | t([‘Zoltan’]) }} => Hello Zoltan {{ 'Total: {amt,number}' | t({amt: 2510.99}) }} => 2,510.99 {{ 'You are the {n,spellout,%spellout-ordinal} in line' | t({n: 47}) }} => You are the forty-seventh in line {{ 'Eres {n,ordinal,%digits-ordinal-feminine}' | t({n: 1}) }} => Eres 1.ª
  22. 38.

    {{ '{d,date,short}' | t({d: date().timestamp}) }} => 9/18/18 {{ 'Today

    is {d,date,long}' | t({d: date().timestamp}) }} => September 18, 2018 {{ 'Today is {d,date,yyyy-MM-dd}' | t({d: date().timestamp}) }} => 2018-09-18 {{ 'Last updated: {0, duration,%with-words} ago' | t([15024]) }} => Last updated: 4 hours, 10 minutes, 24 seconds ago
  23. 40.

    {{ 'You {likeCount,plural, offset: 1 =0{did not like this} =1{liked

    this} one{and one other person liked this} other{and # others liked this} } ' | t ({likeCount: 2}) }} => You and one other person liked this
  24. 41.

    Configuration translation No standardized way of storing or displaying translations

    Plugins need to take care of it themselves Drupal does it via a configuration schema
  25. 44.

    Site aliases general.php 'aliases' => [ '@webHu' => getenv('HU_BASE_URL'), '@webEn'

    => getenv('EN_BASE_URL'), '@assetBaseUrl' => getenv('ASSET_BASE_URL'), '@assetBasePath' => getenv('ASSET_BASE_PATH'), ], .env HU_BASE_URL="https://designhet.hu/2018/" EN_BASE_URL="https://designweek.hu/2018/" ASSET_BASE_URL="https://designhet.hu/2018/" ASSET_BASE_PATH=“/home/asdf/2018/“ <ul class="language"> <li><a href="{{ alias('@webHu') }}">Magyar</a></li> <li><a href="{{ alias('@webEn') }}">English</a></li> </ul> <script src="{{ alias('@assetBaseUrl') }}/js/jquery-3.3.1.min.js"></script>
  26. 45.

    Routes return [ 'hirek' => ['template' => 'news/index'], 'esemenyek' =>

    ['template' => 'events/index'], ]; Section settings config/routes.php Route settings
  27. 46.

    Per-site templates “create a new sub-folder in your templates folder,

    named after your site's handle, and place the templates in there”
  28. 47.

    Per-site configuration not directly possible - general.php is loaded early

    in the bootstrap process Craft has no idea about the current site or language at the time workarounds: use environment vars, seperate index.php entry points, or arrays keyed by site handle
  29. 48.

    currentSite currentSite.name => English currentSite.handle => default currentSite.language => en-GB

    currentSite.baseUrl => @web/ {{ alias(currentSite.baseUrl) }} => https://designhet.hu/
  30. 49.

    Twig craft.app.sites => all sites currentSite.group.sites => sites in current

    group entry.getSupportedSites => sites that entry is active for
  31. 51.
  32. 53.
  33. 54.

    Names Zoltan Várady Várady Zoltán Várady Zoltánné Pablo Diego José

    Francisco de Paula Juan Nepomuceno María de los Remedios Cipriano de laSantísima Trinidad Ruiz y Picasso validation and sorting can be challenging https://www.w3.org/International/questions/qa-personal-names
  34. 57.

    Challenges in Craft Configuration translation Structure entries always propagate Collaborative

    translation of core and plugins transifex, localize.drupal.org
  35. 58.

    Summary consider your audience what needs to be translated translation

    is not just words; see culture, colors, images… who are the translators, what is the workflow once you have this, use the tips given to map it onto a Craft site