21
Parler en plusieurs langues avec Drupal Bogdan Herea Zsolt Tasnadi

Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Embed Size (px)

DESCRIPTION

Parler en plusieurs langues avec Drupal Speak multiple languages with Drupal

Citation preview

Page 1: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Parler en plusieurs langues avec Drupal

Bogdan Herea Zsolt Tasnadi

Page 2: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

l About us l Before we start building a site l Translating code l Variables and settings l Translating user entered content l Translating taxonomies l Translating media l Other tips and tricks l Conclusions

Summary

Page 3: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

About me

Bogdan Herea- Founder & CEO

- 18 years of professional IT experience in France, Belgium & Romania - Obtained in 1998 his Engineering Degree at INSA Lyon, France - 8 years of IT Management, prior to founding PITECH+PLUS - Commercial & strategic spearhead, and mentor for middle & top-management

Page 4: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

PITECH+PLUS is a European software business started in Cluj-Napoca, Romania

Key Facts - Founded in 2005

- 120 Employees

- 12 spoken languages

- Offices: Berlin, Paris, Brussels,

Bucharest, Prague.

Strategic Markets - Healthcare

- Governmental (incl. International)

- Advertising agencies

- Public Companies

- Start-ups

Page 5: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Our expertise contributed to the success of famous brands – Part 1

Page 6: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Our expertise contributed to the success of famous brands – Part 2

Page 7: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

TECH OVERVIEW

Page 8: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Before we start a site

l How many languages will the site have? l Enable the languages l Decide which to use:

l  content translation vs entity translation l Download, install the core and contribution modules for translations

Page 9: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Before we start the site

!TIP: Use the default English language only as source! To be changed in Drupal 8

Install en-us or en-gb for English and use those for displaying content. Use string overrides module only if you are sure you will not have to many exceptions (Hard to maintain, eating lot of resources)

Page 10: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Before we start the site

Content translation: l  In core l  Use it only if you migrating your site from Drupal 6 l  The old way of translation content (a node

for each language)

Entity translation: l  Supposed to be on core, wasn't finished on time,

core contributors are working on it. l  Stores the translations in fields l  You can't translate entity properties with it l  This is the future, Drupal 8 will have

something similar

Page 11: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Translating code The t function: $text = t("@name is presenting a session.", array('@name' => format_username($account))); The st function: $text = st("@name is installing Drupal for a session.", array('@name' => format_username($account))); The get_t function: Use it when can't decide to use t() or st() $t = get_t(); $text = $t('text to translate.');

Page 12: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Translating code

Context (new from Drupal 7): print t('Order', array(), array('context' => 'non-commerce-page'));

Because of context, $conf translations shall be declared:

$conf['locale_custom_strings_en'][''] = array( 'ORIGINAL STRING' => 'YOUR STRING', );

TIP: Don't use variables in t(); Don't: echo t($text_to_translate); Workaround! Do like views is exporting labels in features!

Page 13: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Translating code

Format plurals format_plural($count, '1 category', '@count categories'); Variables placeholder @variable – check plain applied to the variable !variable – output the value without filtering it %variable – Escaped to HTML and formatted using drupal_placeholder()

Page 14: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Variables and settings

Transliteration module (chars/path) – a must have Translating variables with i18n_variable (site title) Translating custom variables (hook_variables_info) (Variables Table) Translating custom content with i18n submodules:

l  Block translation l  Path translation l  Menu translation l  Views translation (independent module)

Page 15: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Translating content

Use entity translation for translating nodes or custom entities. !TIP: use the title module for nodes, else node's titles won't be translatable. Use Title Module

Page 16: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Translating taxonomies

Taxonomy i18n translation – the old way Taxonomies translated as entities:

l  Use name as machine name l  Create translatable title field !!!

Page 17: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Translating media?

Don't! Files are referenced by fields, use translation on the entity reference field. If you are using entity translation for files:

l  Problems with field_get_items and entity metadata wrappers;

l  Workaround (not recommended): /** * Implements hook_entity_TYPE_load(). */ function mymodule_entity_file_load($entities) foreach ($entities as $entity) { $entity->language = language_default('language'); } }

Page 18: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Other tips and tricks

Other useful modules: l  Contact translation l  Translation overview l  Translation management tool

Other tips:

l  Localization update – synchronizes the translations automatically instead of downloading the po files manually

Page 19: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Other tips and tricks

Other tips

Redirect localization update to custom translation server

/** * Implements hook_l10n_update_projects_alter(). */ function mymodule_l10n_update_projects_alter(&$projects) { $projects['contrib_module]['info'] = array_merge( $projects['contrib_module']['info'], array( 'l10n server' => $custom_l10n_server', 'l10n url' => $custom_l10n_url, 'l10n path' => $custom_l10n_path, ) ); }

Page 20: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

Conclusions

Translations UI and translation implementation improved a lot from Drupal 6. Still lot of work (entity translation in core, entity properties translation, etc.) Drupal 8 will get in lots of good stuff, check Drupal 8 multilingual initiative (D8MI).

Page 21: Parler en plusieurs langues avec Drupal - Drupalcamp Paris 2013

             

Questions?