Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
© All rights reserved. Zend Technologies, Inc.
Introduction
35 years old, austrian (not australian)
Developer since more than 17 years
ZF since 2006
I18n Team Leader
Thomas Weidner
3 Introduction
© All rights reserved. Zend Technologies, Inc.
Overview
• Internationalization (I18n)
Generic overview
Zend Framework and I18n
• Translation
What is translation about?
Creating and working with translation
Let’s view it
Future improvements
5 Overview
© All rights reserved. Zend Technologies, Inc.
Generic overview – I18n vs L10n
• Internationalization versus Localization:
I18n => Support other regions without changing code
L10n => Adopt your project for a specific region
• Zend Framework supports them all
Not all people are native English!
7 Internationalization
© All rights reserved. Zend Technologies, Inc.
Generic overview – What’s a locale
• Locale
Locale, the working horse for L10n
Language + Region
Region vs Country
Additional informations (charset, encoding)
8 Internationalization
en_US = english language + region USAde_AT = german language + region Austria
© All rights reserved. Zend Technologies, Inc.
Zend Framework and I18n – Classes
• Zend_Locale
Locale handling (independend from PHP and OS)
Pre-translated informations
Formatting
9 Internationalization
Zend_Locale
Zend_Currency Zend_Date Zend_Translate
Zend FrameworkZF I18n core
© All rights reserved. Zend Technologies, Inc.
Zend Framework and I18n – Classes
• Zend_Currency
Localized currency handling
• Zend_Date
Localized date and time handling
• Zend_Translate
Generic translation handling
10 Internationalization
© All rights reserved. Zend Technologies, Inc.
Overview
• How does translation work
Concept and workflow
• Source files
Creation and handling
• Translate me
Usage
• Specials
Caching, Performance
12 Translation within Zend Framework
© All rights reserved. Zend Technologies, Inc.
How does translation work
• Languages are different
Provide your user with a language he understands
Most browsers send their wished languages
Translation is just one part to a multilingual site
13 Translation within Zend Framework
User accessingSite
Detectlanguage
Selecttranslation
Settranslation
© All rights reserved. Zend Technologies, Inc.
Source files – Adapters Concept
• Adapter concept
Multiple source types supported
Easy to implement own adapters
• Select your adapter based on your usage
Usage may grow… switching to other adapter is just 1 codeline
14 Translation within Zend Framework
© All rights reserved. Zend Technologies, Inc.
Source files – Adapters
Array
Csv
Gettext
Ini
Qt
Tbx
Tmx
Xliff
XmlTm
your own…
15 Translation within Zend Framework
© All rights reserved. Zend Technologies, Inc.
Source files – Array adapter
• Pro
Fast, Faster, Fastest
Human readable
return array(‘Original content’ => ‘Translated content’‘Another content’ => ‘Also translated’
);
16 Translation within Zend Framework
• Con
No editor tools
Not customer friendly
• Usage
During development
Small to medium sites
© All rights reserved. Zend Technologies, Inc.
Source files – CSV adapter
• ProFast
Human readable
Customer editable
“Original content”;”Translated content”“Another content”;“Also translated”
17 Translation within Zend Framework
• Con
No creation tools
• Usage
Translations by customer
Small to medium sites
© All rights reserved. Zend Technologies, Inc.
Source files – INI adapter
• Pro
Fast
Human readable
Original_content = “Translated content”Another_content = “Also translated”
18 Translation within Zend Framework
• Con
No creation tools
Not customer friendly
Key limitations• Usage
Small to medium sites
Mixing translation with configuration
© All rights reserved. Zend Technologies, Inc.
Source files – Gettext adapter
• ProEncrypted for customer
Free Tools
Professional translation
BINARY FORMAT (*.mo files)… *.po is NOT Gettext
19 Translation within Zend Framework
• Con
Fixed for customers
Not human readable
• Usage
Small to enterprise sites
Many sources available
© All rights reserved. Zend Technologies, Inc.
Source files – TMX adapter
• Pro
Professional translation tools
Supports HTML tags
** XML HEADERS **<tu tuid='Message 1'>
<tuv xml:lang="en"><seg>Message 1 (en)</seg></tuv><tuv xml:lang="fr"><seg>Message 1 (fr)</seg></tuv>
</tu>
20 Translation within Zend Framework
• Con
No free good tools
Difficult for customer
Must use caching• Usage
With professional translation services
Medium to Enterprise sites
HINT: TMX is said to be “Industry standard” butBEWARE it’s very huge & bloated format
© All rights reserved. Zend Technologies, Inc.
Translate me – Manual usage
$trans = new Zend_Translate(‘array’,‘/www/lang/’,‘de_AT’,array(‘scan’ => Zend_Translate::LOCALE_DIRECTORY)
);$trans->translate(‘I said hello’);
22 Working examples
© All rights reserved. Zend Technologies, Inc.
Translate me – Manual usage
$trans = new Zend_Translate(‘array’,‘/www/lang/’,‘de_AT’,array(‘scan’ => Zend_Translate::LOCALE_DIRECTORY)
);$trans->translate(‘I said hello’);
23 Working examples
Select your Adapter
Switch your working adapter within a single line
© All rights reserved. Zend Technologies, Inc.
Translate me – Manual usage
$trans = new Zend_Translate(‘array’,‘/www/lang/’,‘de_AT’,array(‘scan’ => Zend_Translate::LOCALE_DIRECTORY)
);$trans->translate(‘I said hello’);
24 Working examples
Where are your translations?
Directory or
Single file
© All rights reserved. Zend Technologies, Inc.
Translate me – Manual usage
$trans = new Zend_Translate(‘array’,‘/www/lang/’,‘de_AT’,array(‘scan’ => Zend_Translate::LOCALE_DIRECTORY)
);$trans->translate(‘I said hello’);
25 Working examples
Which language ?
Automatic detection (‘auto’, ‘browser’)
Manual declaration (‘de_AT’, ‘en_US’)
Use application wide settings (Zend_Application)
© All rights reserved. Zend Technologies, Inc.
Translate me – Manual usage
$trans = new Zend_Translate(‘array’,‘/www/lang/’,‘de_AT’,array(‘scan’ => Zend_Translate::LOCALE_DIRECTORY)
);$trans->translate(‘I said hello’);
26 Working examples
Several options
Scan: search for translations
• LOCALE-DIRECTORY : /www/lang/en/file.php
• LOCALE-FILE: /www/lang/file-en.php
© All rights reserved. Zend Technologies, Inc.
Translate me – Manual usage
$trans = new Zend_Translate(‘array’,‘/www/lang/’,‘de_AT’,array(‘scan’ => Zend_Translate::LOCALE_DIRECTORY)
);$trans->translate(‘I said hello’);
27 Working examples
It’s alive!
Returns: “Ich habe Hallo gesagt”
© All rights reserved. Zend Technologies, Inc.
Translate me – Manual usage
/language
/language/en_GB/language/en_GB/file1.xxx
/language/de_CH/language/de_CH/file1.xxx
28 Working examples
Zend_Translate::LOCALE_DIRECTORY:
Locale within the directory
Also partitial recognised like:
• /language/App1-en_US/xxx
• /language/Something_en_GB_different/xxx
© All rights reserved. Zend Technologies, Inc.
Translate me – Manual usage
/language
/language/dir//language/dir/file1-en_GB.xxx
/language/dir2/language/dir2/file2-de_CH.xxx
29 Working examples
Zend_Translate::LOCALE_FILE:
Locale within the filename
Also partitial recognised like:
• file1.en.tmx
• file_en-GB.php
• file_de-something.mo
© All rights reserved. Zend Technologies, Inc.
Translate me – View helper
30 Working examples
Translation view helper (in your view script)
Simpler
Smaller
$this->translate(‘I said hello’);
$this->translate(‘Company Name’, ‘en’);
© All rights reserved. Zend Technologies, Inc.
Translate me – Dynamic translations
31 Working examples
Add parameters to your translation
sprintf Syntax
Multiple parameters possible
Other languages may change order
$this->translate(“Pay %1\$s euro”, $money);
$this->translate(“Pay %1\$s euro until %2\$s”, $money, $date);
© All rights reserved. Zend Technologies, Inc.
Other components – Registry
32 Working examples
Registry
Application wide usage
• Zend_Form
• Zend_Validate
• Zend_View
• others
$translate = new Zend_Translate(……);
Zend_Registry::set(‘Zend_Translate’, $translate);
© All rights reserved. Zend Technologies, Inc.
Other components – Application
33 Working examples
Application
Application wide recognised
Configurable
resources.translate.adapter = “array“;resources.translate.locale = “de_AT”;resources.translate.data = “/www/lang/”;
© All rights reserved. Zend Technologies, Inc.
Special – Plural translation
34 Working examples
$translate->plural(‘Car’, ‘Cars’, 2);$translate->translate(array(‘Car’, ‘Cars’, 2));
$this->translate(array(‘Car’, ‘Cars’, 2));
Singular / Plural
Car (one item) / Singular
Cars (multiple items) / Plural
Same method for singular & plural
© All rights reserved. Zend Technologies, Inc.
Special – Plural translation 2
35 Working examples
$this->translate(array(‘%1\$s Car’, ‘%1\$s Cars’, $nr), $nr);
Don’t forget your parameters
1 Car
3 Cars
Plural rules for all languages implemented
© All rights reserved. Zend Technologies, Inc.
Special – Plural translation 3
36 Working examples
$this->translate(array(‘Singular’, ‘Plural1’, ‘Plural2’, 2));
Prepared for PHP 6
Several languages define more than 1 plural
Allows to write the source code in YOUR language
© All rights reserved. Zend Technologies, Inc.
Special – Plural translation 4
Plural rules supported by:
Array
CSV
Gettext
Not supported by:
Ini
Qt
Tmx
Tbx
Xliff
XmlTm
37 Working examples
© All rights reserved. Zend Technologies, Inc.
Special – Performance
38 Working examples
Caching… caching… caching
• Rule1: Use a cache !!!
© All rights reserved. Zend Technologies, Inc.
Special – Performance
39 Working examples
Caching… caching… caching
• Rule1: Use a cache !!!
• Rule2: Always use a cache!
© All rights reserved. Zend Technologies, Inc.
Special – Performance
40 Working examples
Caching… caching… caching
• Rule1: Use a cache !!!
• Rule2: Always use a cache!!
• Rule3: You must really use a cache!
© All rights reserved. Zend Technologies, Inc.
Special – Performance
41 Working examples
Caching… caching… caching
• Rule1: Use a cache !!!
• Rule2: Always use a cache!!
• Rule3: You must really use a cache!
All adapters have SAME SPEED
• Only initial reading differs
© All rights reserved. Zend Technologies, Inc.
Summary
Translation with Zend_Translate is
Simple to use
Quickly implemented
Integrated in many other ZF components
For more information
Read the manual
Subscribe by blog: http://www.thomasweidner.com
42 Working examples