SlideShare a Scribd company logo
Drupal Site Translation and Translation Testing By James Andres For VANDUG, May 2011
Overview Background:  locale  module,  GetText ,  .po ,  .pot Choosing a translation approach, database versus files *Idea*! Translation "unit testing", and general .po file abuse Adding a language in the Drupal UI Using potx via CLI Exporting dynamic translations, using i18n Gotchya's, tips and tricks
Drupal translation ... is a bit limited //   These are valid GetText translatable strings  $string = t(“Hello world.”); $string = t(“Hi @name. How are you?”, array(‘@name’ => $user->name)); //   These are NOT valid  //  Only static strings allowed. No variables! $message = ($user->uid == 1) ? “Hello admin.” : “Hello user.”; $string = t($message); //  Only whole continuous strings allowed. No concatenation! $string = t(“Hello: ” . “admin”); //  Only static strings allowed. No variables! $string = t(“Hello: $user->name”);
Module's that pick up the slack i18n : Provides an API to translate dynamic strings i18nblocks : Implements the i18n API, allowing for multilingual Drupal blocks i18ntaxonomy : Implements the i18n API, allowing for multilingual vocabularies and taxonomy terms. i18nviews : ... you're getting the idea. potx : Simplifies the creation of .po and .pot files for your modules and themes. Other goodies:  languageicons ,  i18n_media  (*shameless plug here*)
Translating your Drupal project There are several different approaches.  They can each be categorised by where the data is stored (DB vs. FILES). Here are a few I've tried: DB: i18n_client and i18n_server DB: i18n's Search interface (painful..) FILES: i18n export and import, via .po files FILES: potx export to .po and import via i18n FILES: potx export to .po and import with custom script (my, current, preference)
Why use .po files? Version control of translations (is good) Ability to alter (fix) translations via script Keeps deployment reproducible and sane, helps me sleep at night Simplifies contributing translations back to localize.drupal.org
Translation "unit testing", plus potx crash course When translating large Drupal sites I often had the same problem:  how can I easily tell if the site is fully translated? That is, the locale module says the site is 100% translated, but what about bugs / poor code? drupal_set_title("Homepage"); // Hint, missing t()
Solution, make a visually scannable test language.  The "." language..
Adding a language
Making "test.po", for  (most of)  the whole site #   (1) cd into the root of a Drupal site  $> cd /var/www/mysite #   (2) create general.pot .. if potx-cli.php in $PATH  $>  potx-cli.php #   (3) create test.po from general.pot  $> msginit --no-translator \            --locale= test  \            --input=general.pot #   (4) Translate each string in test.po to "."  $> FIRST=$(grep -n 'msgstr ""' test.po \           | head -n 1 \           | awk -F ':' '{ print $1 }') $> FIRST=$((FIRST+1)) $> sed -i $FIRST',$  s/msgstr ""/msgstr "."/g ' test.po $> sed -i $FIRST',$  s/msgstr\[\([0-9]\)\] ""/msgstr[\1] "."/g '\            test.po
After import, 3 issues .. not bad!
Using i18nmenu, i18ntaxonomy, etc.
The translation "unit test" process in full Create a custom language called 'Test' (langcode 'test') Extract .po files for the site using potx Extract .po files for dynamic content using i18n Replace all   msgstr ""   with   msgstr "."  Import the .po files Test. and repeat.. The beauty is, it's exactly the same for real translation.  Replace step (4) with a translation team.
Translation gotchya's // Having $this = t(‘1 tomato’); // and $that = fomat_plural($num, ‘1 tomato’, ‘@count tomatoes’); // Can cause problems... // Drupal will refuse to import some HTML, like: t('<div></div>')   t('<br/>')   t('<img .. />');
Tips Some modules don't support translation, it's getting better but check issue queues first.  Even big modules like  apachesolr ,  panels  and  views  still have a few translation weak points. Drupal.org separated the translation effort out of standard version control with the switch to Git.  For management of custom module translations, however, I still recommend using  a &quot;mymodule/translation&quot; directory. For panels and views, it can be helpful to wrap the t() function around some of the strings inside &quot;in-code&quot; exports.  Example:
More tips &quot;Translatables&quot; arrays are a handy trick to get potx to generate a translation without affecting your code / execution. Example: GetText has many other useful utilities, check it out! Start with  msgmerge .

More Related Content

PPT
Choosing a Templating System
PDF
第1回PHP拡張勉強会
PDF
Power of Puppet 4
DOC
Php tutorial
PDF
Running a Plone product on Substance D
PDF
Php 5.5
ODP
Glance rebol
PDF
Welcome to Swift (CocoaCoder 6/12/14)
Choosing a Templating System
第1回PHP拡張勉強会
Power of Puppet 4
Php tutorial
Running a Plone product on Substance D
Php 5.5
Glance rebol
Welcome to Swift (CocoaCoder 6/12/14)

What's hot (20)

PDF
Ansible Callback Plugins
PDF
Php tutorial
PPTX
php basics
PDF
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
PDF
Code rippa
PDF
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
PPTX
Flask vs. Django
PDF
Functional Programming for Busy Object Oriented Programmers
PPTX
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)
PPT
Beginners PHP Tutorial
PDF
Php introduction
PDF
Fighting Fear-Driven-Development With PHPUnit
PPTX
Introduction to PHP
PDF
Ancient To Modern: Upgrading nearly a decade of Plone in public radio
PDF
Php tutorial(w3schools)
PDF
Happy hacking with Plone
PPT
Php hypertext pre-processor
PPT
Chapter 02 php basic syntax
Ansible Callback Plugins
Php tutorial
php basics
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
Code rippa
Can you upgrade to Puppet 4.x? (Beginner) Can you upgrade to Puppet 4.x? (Beg...
Flask vs. Django
Functional Programming for Busy Object Oriented Programmers
Enjoying the Journey from Puppet 3.x to Puppet 4.x (PuppetConf 2016)
Beginners PHP Tutorial
Php introduction
Fighting Fear-Driven-Development With PHPUnit
Introduction to PHP
Ancient To Modern: Upgrading nearly a decade of Plone in public radio
Php tutorial(w3schools)
Happy hacking with Plone
Php hypertext pre-processor
Chapter 02 php basic syntax
Ad

Similar to Drupal site translation and translation testing (20)

PPT
ODP
Programming Under Linux In Python
PDF
Introduction to Go language
PDF
Ext 0523
PPTX
The GO Language : From Beginners to Gophers
PPT
The Ruby On Rails I18n Core Api
PPT
course slides -- powerpoint
PPTX
Modern javascript localization with c-3po and the good old gettext
PPT
Adventures in infrastructure as code
ODP
Smolder Introduction
PPT
Node.js: CAMTA Presentation
PDF
Writing multi-language documentation using Sphinx
PDF
Lecture8
PPT
Phpwebdevelping
ODP
Python Presentation
PPT
Demystifying Maven
PDF
Golang workshop
ODP
Phing - A PHP Build Tool (An Introduction)
PDF
Living With Legacy Code
ODP
Continuous integration with Git & CI Joe
Programming Under Linux In Python
Introduction to Go language
Ext 0523
The GO Language : From Beginners to Gophers
The Ruby On Rails I18n Core Api
course slides -- powerpoint
Modern javascript localization with c-3po and the good old gettext
Adventures in infrastructure as code
Smolder Introduction
Node.js: CAMTA Presentation
Writing multi-language documentation using Sphinx
Lecture8
Phpwebdevelping
Python Presentation
Demystifying Maven
Golang workshop
Phing - A PHP Build Tool (An Introduction)
Living With Legacy Code
Continuous integration with Git & CI Joe
Ad

Recently uploaded (20)

PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
A Presentation on Touch Screen Technology
PPTX
A Presentation on Artificial Intelligence
PDF
Hybrid model detection and classification of lung cancer
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Tartificialntelligence_presentation.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
project resource management chapter-09.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Enhancing emotion recognition model for a student engagement use case through...
A Presentation on Touch Screen Technology
A Presentation on Artificial Intelligence
Hybrid model detection and classification of lung cancer
TLE Review Electricity (Electricity).pptx
Unlocking AI with Model Context Protocol (MCP)
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
1. Introduction to Computer Programming.pptx
Programs and apps: productivity, graphics, security and other tools
1 - Historical Antecedents, Social Consideration.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Tartificialntelligence_presentation.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
OMC Textile Division Presentation 2021.pptx
SOPHOS-XG Firewall Administrator PPT.pptx
project resource management chapter-09.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...

Drupal site translation and translation testing

  • 1. Drupal Site Translation and Translation Testing By James Andres For VANDUG, May 2011
  • 2. Overview Background: locale module, GetText , .po , .pot Choosing a translation approach, database versus files *Idea*! Translation &quot;unit testing&quot;, and general .po file abuse Adding a language in the Drupal UI Using potx via CLI Exporting dynamic translations, using i18n Gotchya's, tips and tricks
  • 3. Drupal translation ... is a bit limited //  These are valid GetText translatable strings  $string = t(“Hello world.”); $string = t(“Hi @name. How are you?”, array(‘@name’ => $user->name)); //  These are NOT valid  // Only static strings allowed. No variables! $message = ($user->uid == 1) ? “Hello admin.” : “Hello user.”; $string = t($message); // Only whole continuous strings allowed. No concatenation! $string = t(“Hello: ” . “admin”); // Only static strings allowed. No variables! $string = t(“Hello: $user->name”);
  • 4. Module's that pick up the slack i18n : Provides an API to translate dynamic strings i18nblocks : Implements the i18n API, allowing for multilingual Drupal blocks i18ntaxonomy : Implements the i18n API, allowing for multilingual vocabularies and taxonomy terms. i18nviews : ... you're getting the idea. potx : Simplifies the creation of .po and .pot files for your modules and themes. Other goodies:  languageicons , i18n_media (*shameless plug here*)
  • 5. Translating your Drupal project There are several different approaches.  They can each be categorised by where the data is stored (DB vs. FILES). Here are a few I've tried: DB: i18n_client and i18n_server DB: i18n's Search interface (painful..) FILES: i18n export and import, via .po files FILES: potx export to .po and import via i18n FILES: potx export to .po and import with custom script (my, current, preference)
  • 6. Why use .po files? Version control of translations (is good) Ability to alter (fix) translations via script Keeps deployment reproducible and sane, helps me sleep at night Simplifies contributing translations back to localize.drupal.org
  • 7. Translation &quot;unit testing&quot;, plus potx crash course When translating large Drupal sites I often had the same problem: how can I easily tell if the site is fully translated? That is, the locale module says the site is 100% translated, but what about bugs / poor code? drupal_set_title(&quot;Homepage&quot;); // Hint, missing t()
  • 8. Solution, make a visually scannable test language.  The &quot;.&quot; language..
  • 10. Making &quot;test.po&quot;, for (most of)  the whole site #  (1) cd into the root of a Drupal site  $> cd /var/www/mysite #   (2) create general.pot .. if potx-cli.php in $PATH  $> potx-cli.php #   (3) create test.po from general.pot  $> msginit --no-translator \            --locale= test \            --input=general.pot #   (4) Translate each string in test.po to &quot;.&quot;  $> FIRST=$(grep -n 'msgstr &quot;&quot;' test.po \          | head -n 1 \          | awk -F ':' '{ print $1 }') $> FIRST=$((FIRST+1)) $> sed -i $FIRST',$ s/msgstr &quot;&quot;/msgstr &quot;.&quot;/g ' test.po $> sed -i $FIRST',$ s/msgstr\[\([0-9]\)\] &quot;&quot;/msgstr[\1] &quot;.&quot;/g '\            test.po
  • 11. After import, 3 issues .. not bad!
  • 13. The translation &quot;unit test&quot; process in full Create a custom language called 'Test' (langcode 'test') Extract .po files for the site using potx Extract .po files for dynamic content using i18n Replace all  msgstr &quot;&quot;  with  msgstr &quot;.&quot;  Import the .po files Test. and repeat.. The beauty is, it's exactly the same for real translation.  Replace step (4) with a translation team.
  • 14. Translation gotchya's // Having $this = t(‘1 tomato’); // and $that = fomat_plural($num, ‘1 tomato’, ‘@count tomatoes’); // Can cause problems... // Drupal will refuse to import some HTML, like: t('<div></div>')   t('<br/>')   t('<img .. />');
  • 15. Tips Some modules don't support translation, it's getting better but check issue queues first.  Even big modules like apachesolr , panels and views still have a few translation weak points. Drupal.org separated the translation effort out of standard version control with the switch to Git.  For management of custom module translations, however, I still recommend using  a &quot;mymodule/translation&quot; directory. For panels and views, it can be helpful to wrap the t() function around some of the strings inside &quot;in-code&quot; exports.  Example:
  • 16. More tips &quot;Translatables&quot; arrays are a handy trick to get potx to generate a translation without affecting your code / execution. Example: GetText has many other useful utilities, check it out! Start with msgmerge .