parler en plusieurs langues avec drupal - drupalcamp paris 2013
DESCRIPTION
Parler en plusieurs langues avec Drupal Speak multiple languages with DrupalTRANSCRIPT
Parler en plusieurs langues avec Drupal
Bogdan Herea Zsolt Tasnadi
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
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
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
Our expertise contributed to the success of famous brands – Part 1
Our expertise contributed to the success of famous brands – Part 2
TECH OVERVIEW
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
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)
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
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.');
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!
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()
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)
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
Translating taxonomies
Taxonomy i18n translation – the old way Taxonomies translated as entities:
l Use name as machine name l Create translatable title field !!!
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'); } }
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
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, ) ); }
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).
Questions?