international php2011_kore nordmann_designing multilingual applications

79
Designing Multilingual Applications International PHP Conference – Spring Edition Kore Nordmann <[email protected]> May 30, 2011 Designing Multilingual Applications 1 / 35

Upload: smuellersandsmedia

Post on 01-Jun-2015

346 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: international PHP2011_Kore Nordmann_Designing multilingual applications

Designing Multilingual ApplicationsInternational PHP Conference – Spring Edition

Kore Nordmann <[email protected]>

May 30, 2011

Designing Multilingual Applications 1 / 35

Page 2: international PHP2011_Kore Nordmann_Designing multilingual applications

About me

I Degree in computer sience

I More than 10 years ofprofessional PHP

I Open source enthusiasts

I Contributing to variousFLOSS projects

Qafoopassion for software quality

Designing Multilingual Applications 2 / 35

Page 3: international PHP2011_Kore Nordmann_Designing multilingual applications

About me

I Degree in computer sience

I More than 10 years ofprofessional PHP

I Open source enthusiasts

I Contributing to variousFLOSS projects

Qafoopassion for software quality

Designing Multilingual Applications 2 / 35

Page 4: international PHP2011_Kore Nordmann_Designing multilingual applications

About me

I Degree in computer sience

I More than 10 years ofprofessional PHP

I Open source enthusiasts

I Contributing to variousFLOSS projects

Qafoopassion for software quality

Designing Multilingual Applications 2 / 35

Page 5: international PHP2011_Kore Nordmann_Designing multilingual applications

About me

I Degree in computer sience

I More than 10 years ofprofessional PHP

I Open source enthusiasts

I Contributing to variousFLOSS projects

Co-founder of

Qafoopassion for software quality

Designing Multilingual Applications 2 / 35

Page 6: international PHP2011_Kore Nordmann_Designing multilingual applications

About me

I Degree in computer sience

I More than 10 years ofprofessional PHP

I Open source enthusiasts

I Contributing to variousFLOSS projects

Co-founder of

Qafoopassion for software quality

We help people to createhigh quality PHP

applications.

Designing Multilingual Applications 2 / 35

Page 7: international PHP2011_Kore Nordmann_Designing multilingual applications

About me

I Degree in computer sience

I More than 10 years ofprofessional PHP

I Open source enthusiasts

I Contributing to variousFLOSS projects

Co-founder of

Qafoopassion for software quality

We help people to createhigh quality PHP

applications.

http://qafoo.com

Designing Multilingual Applications 2 / 35

Page 8: international PHP2011_Kore Nordmann_Designing multilingual applications

Motivation

I Multilingual / Multicultural applications can be hardI Different types of applications:

I Single fixed languageI Consistent language per installationI Multilingual content

Designing Multilingual Applications 3 / 35

Page 9: international PHP2011_Kore Nordmann_Designing multilingual applications

Motivation

I Multilingual / Multicultural applications can be hardI Different types of applications:

I Single fixed languageI Consistent language per installationI Multilingual content

Designing Multilingual Applications 3 / 35

Page 10: international PHP2011_Kore Nordmann_Designing multilingual applications

Motivation

I Multilingual / Multicultural applications can be hardI Different types of applications:

I Single fixed languageI Consistent language per installationI Multilingual content

Designing Multilingual Applications 3 / 35

Page 11: international PHP2011_Kore Nordmann_Designing multilingual applications

Motivation

I Multilingual / Multicultural applications can be hardI Different types of applications:

I Single fixed languageI Consistent language per installationI Multilingual content

Designing Multilingual Applications 3 / 35

Page 12: international PHP2011_Kore Nordmann_Designing multilingual applications

Where are the problems?

View Model

Dispatcher Controller

Designing Multilingual Applications 4 / 35

Page 13: international PHP2011_Kore Nordmann_Designing multilingual applications

Outline

The Dispatcher

The Model

The View

Conclusion

Designing Multilingual Applications 5 / 35

Page 14: international PHP2011_Kore Nordmann_Designing multilingual applications

Locate your user

I Parsing accept headers is not hardI Possbile to do by regular expression

I Never use geolocation for language selectionI Or I’ll get back at you!

I Result: de , en GB , cs CZ.UTF-8 , de AU@euro , . . .I Format: langauge[ territory][.codeset][@modifier]

Designing Multilingual Applications 6 / 35

Page 15: international PHP2011_Kore Nordmann_Designing multilingual applications

Locate your user

I Parsing accept headers is not hardI Possbile to do by regular expression

I Never use geolocation for language selectionI Or I’ll get back at you!

I Result: de , en GB , cs CZ.UTF-8 , de AU@euro , . . .I Format: langauge[ territory][.codeset][@modifier]

Designing Multilingual Applications 6 / 35

Page 16: international PHP2011_Kore Nordmann_Designing multilingual applications

Locate your user

I Parsing accept headers is not hardI Possbile to do by regular expression

I Never use geolocation for language selectionI Or I’ll get back at you!

I Result: de , en GB , cs CZ.UTF-8 , de AU@euro , . . .I Format: langauge[ territory][.codeset][@modifier]

Designing Multilingual Applications 6 / 35

Page 17: international PHP2011_Kore Nordmann_Designing multilingual applications

Locate your user

I Parsing accept headers is not hardI Possbile to do by regular expression

I Never use geolocation for language selectionI Or I’ll get back at you!

I Result: de , en GB , cs CZ.UTF-8 , de AU@euro , . . .I Format: langauge[ territory][.codeset][@modifier]

Designing Multilingual Applications 6 / 35

Page 18: international PHP2011_Kore Nordmann_Designing multilingual applications

Outline

The Dispatcher

The Model

The View

Conclusion

Designing Multilingual Applications 7 / 35

Page 19: international PHP2011_Kore Nordmann_Designing multilingual applications

The Model

I Translation of “user”-provided contentsI News, Articles, Products, Comments, . . .

Designing Multilingual Applications 8 / 35

Page 20: international PHP2011_Kore Nordmann_Designing multilingual applications

Outline

The ModelModel persistanceDomain-Problems

Designing Multilingual Applications 9 / 35

Page 21: international PHP2011_Kore Nordmann_Designing multilingual applications

One multilingual table

id

42

language

de

title

Dies ist ein Titel

42 en

...

...

This is a title

state

published

published

I Dublication of non-translated items

I De-normalized

Designing Multilingual Applications 10 / 35

Page 22: international PHP2011_Kore Nordmann_Designing multilingual applications

One multilingual table

id

42

language

de

title

Dies ist ein Titel

42 en

...

...

This is a title

state

published

published

I Dublication of non-translated items

I De-normalized

Designing Multilingual Applications 10 / 35

Page 23: international PHP2011_Kore Nordmann_Designing multilingual applications

Multiple columns

id

42

title_1

Dies ist ein Titel

...

...state

published

title_2

This is a title

I Limited number of translations

Designing Multilingual Applications 11 / 35

Page 24: international PHP2011_Kore Nordmann_Designing multilingual applications

Multiple columns

id

42

title_1

Dies ist ein Titel

...

...state

published

title_2

This is a title

I Limited number of translations

Designing Multilingual Applications 11 / 35

Page 25: international PHP2011_Kore Nordmann_Designing multilingual applications

Multiple tables

id

42

...

...state

published

id

42

language

de

title

Dies ist ein Titel

42 en

...

...

This is a title

I More complex queries

Designing Multilingual Applications 12 / 35

Page 26: international PHP2011_Kore Nordmann_Designing multilingual applications

Multiple tables

id

42

...

...state

published

id

42

language

de

title

Dies ist ein Titel

42 en

...

...

This is a title

I More complex queries

Designing Multilingual Applications 12 / 35

Page 27: international PHP2011_Kore Nordmann_Designing multilingual applications

Full mapping

content_class

idname

content_class_attribute

idcontent_class_idattribute_type_idnamedescriptionconfigurationdefault_value

idnamedescriptionconfiguration

attribute_type

content_object

idcontent_class_idname

content_object_version

content_object_versioncontent_object_idlanguage_idstatus_idcreatorcreated

content_object_data

content_object_versioncontent_object_idlanguage_idattribute_iddata

language

idshortname

status

idnamedescription

Content class Instance Metadata

Designing Multilingual Applications 13 / 35

Page 28: international PHP2011_Kore Nordmann_Designing multilingual applications

Outline

The ModelModel persistanceDomain-Problems

Designing Multilingual Applications 14 / 35

Page 29: international PHP2011_Kore Nordmann_Designing multilingual applications

The Model

I There is a bunch of domain-specific problemsI CMS

I Different contents

I ShopI Tax calculationI Legal requirementsI Currency conversions

I OthersI Recipe aggregation

Designing Multilingual Applications 15 / 35

Page 30: international PHP2011_Kore Nordmann_Designing multilingual applications

The Model

I There is a bunch of domain-specific problemsI CMS

I Different contents

I ShopI Tax calculationI Legal requirementsI Currency conversions

I OthersI Recipe aggregation

Designing Multilingual Applications 15 / 35

Page 31: international PHP2011_Kore Nordmann_Designing multilingual applications

The Model

I There is a bunch of domain-specific problemsI CMS

I Different contents

I ShopI Tax calculationI Legal requirementsI Currency conversions

I OthersI Recipe aggregation

Designing Multilingual Applications 15 / 35

Page 32: international PHP2011_Kore Nordmann_Designing multilingual applications

The Model

I There is a bunch of domain-specific problemsI CMS

I Different contents

I ShopI Tax calculationI Legal requirementsI Currency conversions

I OthersI Recipe aggregation

Designing Multilingual Applications 15 / 35

Page 33: international PHP2011_Kore Nordmann_Designing multilingual applications

Content (CMS)

I Structure of content treeI Each item is translated into all languagesI Fallback languageI Display sub-tree for non-main languagesI Different contents per language

Designing Multilingual Applications 16 / 35

Page 34: international PHP2011_Kore Nordmann_Designing multilingual applications

Content (CMS)

I Structure of content treeI Each item is translated into all languagesI Fallback languageI Display sub-tree for non-main languagesI Different contents per language

Designing Multilingual Applications 16 / 35

Page 35: international PHP2011_Kore Nordmann_Designing multilingual applications

Content (CMS)

I Structure of content treeI Each item is translated into all languagesI Fallback languageI Display sub-tree for non-main languagesI Different contents per language

Designing Multilingual Applications 16 / 35

Page 36: international PHP2011_Kore Nordmann_Designing multilingual applications

Content (CMS)

I Structure of content treeI Each item is translated into all languagesI Fallback languageI Display sub-tree for non-main languagesI Different contents per language

Designing Multilingual Applications 16 / 35

Page 37: international PHP2011_Kore Nordmann_Designing multilingual applications

Calculations (Shop)

I Rule based systemsI Select calculation rules based on language / countryI IF (@COUNTRY = "us" AND @STATE = "New York") @TAX

= 23.43I IF (@COUNTRY = "de" AND @TYPE = "BOOK") @TAX =

7.00I DEFAULT: @TAX = 19.00

Designing Multilingual Applications 17 / 35

Page 38: international PHP2011_Kore Nordmann_Designing multilingual applications

Calculations (Shop)

I Rule based systemsI Select calculation rules based on language / countryI IF (@COUNTRY = "us" AND @STATE = "New York") @TAX

= 23.43I IF (@COUNTRY = "de" AND @TYPE = "BOOK") @TAX =

7.00I DEFAULT: @TAX = 19.00

Designing Multilingual Applications 17 / 35

Page 39: international PHP2011_Kore Nordmann_Designing multilingual applications

Calculations (Shop)

I Rule based systemsI Select calculation rules based on language / countryI IF (@COUNTRY = "us" AND @STATE = "New York") @TAX

= 23.43I IF (@COUNTRY = "de" AND @TYPE = "BOOK") @TAX =

7.00I DEFAULT: @TAX = 19.00

Designing Multilingual Applications 17 / 35

Page 40: international PHP2011_Kore Nordmann_Designing multilingual applications

Calculations (Shop)

I Rule based systemsI Select calculation rules based on language / countryI IF (@COUNTRY = "us" AND @STATE = "New York") @TAX

= 23.43I IF (@COUNTRY = "de" AND @TYPE = "BOOK") @TAX =

7.00I DEFAULT: @TAX = 19.00

Designing Multilingual Applications 17 / 35

Page 41: international PHP2011_Kore Nordmann_Designing multilingual applications

Outline

The Dispatcher

The Model

The View

Conclusion

Designing Multilingual Applications 18 / 35

Page 42: international PHP2011_Kore Nordmann_Designing multilingual applications

Translating strings

I gettext()I Depends on setlocale() , which is not thread-safe

I QT LinguistI XML based format used in QT

I PHP Arrays

I PHP ConstantsI PHP implementation for gettext files

I Should not depend on setlocale()I Will be slower

Designing Multilingual Applications 19 / 35

Page 43: international PHP2011_Kore Nordmann_Designing multilingual applications

Plural forms

I Most libraries somehow support plural formsI Support singularI Support simple plural formsI Support different plural forms depending on numberI Support multiple words with plural forms in one sentence

Designing Multilingual Applications 20 / 35

Page 44: international PHP2011_Kore Nordmann_Designing multilingual applications

Plural forms

I Most libraries somehow support plural formsI Support singularI Support simple plural formsI Support different plural forms depending on numberI Support multiple words with plural forms in one sentence

Designing Multilingual Applications 20 / 35

Page 45: international PHP2011_Kore Nordmann_Designing multilingual applications

Plural forms

I Most libraries somehow support plural formsI Support singularI Support simple plural formsI Support different plural forms depending on numberI Support multiple words with plural forms in one sentence

Designing Multilingual Applications 20 / 35

Page 46: international PHP2011_Kore Nordmann_Designing multilingual applications

Plural forms

I Most libraries somehow support plural formsI Support singularI Support simple plural formsI Support different plural forms depending on numberI Support multiple words with plural forms in one sentence

Designing Multilingual Applications 20 / 35

Page 47: international PHP2011_Kore Nordmann_Designing multilingual applications

Finding strings

I Locating untranslated stringsI Plain strings are “trivial” to findI Parameterized strings are possible to findI Error messages created in applications are impossible to find

I Handling untranslated stringsI Use proper message as identifier (not MY FOO ERRORMSG1 )

I Add “context”

I Append strings to storage as “untranslated”

Designing Multilingual Applications 21 / 35

Page 48: international PHP2011_Kore Nordmann_Designing multilingual applications

Finding strings

I Locating untranslated stringsI Plain strings are “trivial” to findI Parameterized strings are possible to findI Error messages created in applications are impossible to find

I Handling untranslated stringsI Use proper message as identifier (not MY FOO ERRORMSG1 )

I Add “context”

I Append strings to storage as “untranslated”

Designing Multilingual Applications 21 / 35

Page 49: international PHP2011_Kore Nordmann_Designing multilingual applications

Finding strings

I Locating untranslated stringsI Plain strings are “trivial” to findI Parameterized strings are possible to findI Error messages created in applications are impossible to find

I Handling untranslated stringsI Use proper message as identifier (not MY FOO ERRORMSG1 )

I Add “context”

I Append strings to storage as “untranslated”

Designing Multilingual Applications 21 / 35

Page 50: international PHP2011_Kore Nordmann_Designing multilingual applications

Finding strings

I Locating untranslated stringsI Plain strings are “trivial” to findI Parameterized strings are possible to findI Error messages created in applications are impossible to find

I Handling untranslated stringsI Use proper message as identifier (not MY FOO ERRORMSG1 )

I Add “context”

I Append strings to storage as “untranslated”

Designing Multilingual Applications 21 / 35

Page 51: international PHP2011_Kore Nordmann_Designing multilingual applications

Translations

I Standardized formats help TranslatorsI Make it easy for themI There are various websites which make collaboration easy

I Commonly support QT Linguist and gettext

I There is a GUI for QT Linguist translations

Designing Multilingual Applications 22 / 35

Page 52: international PHP2011_Kore Nordmann_Designing multilingual applications

Example: crowdin.net

I http://crowdin.net

Designing Multilingual Applications 23 / 35

Page 53: international PHP2011_Kore Nordmann_Designing multilingual applications

Example: QT3 Linguist

Designing Multilingual Applications 24 / 35

Page 54: international PHP2011_Kore Nordmann_Designing multilingual applications

Outline

The ViewData handling

Designing Multilingual Applications 25 / 35

Page 55: international PHP2011_Kore Nordmann_Designing multilingual applications

Number formatting

1 <?php23 var dump ( number format ( 42000 .23 , 2 ) ) ;4 // s t r i n g ( 9) ”42 ,000 .23”56 var dump ( number format ( 42000 .23 , 2 , ’ , ’ , ’ . ’ ) ) ;7 // s t r i n g ( 9) ”42 .000 ,23”

Designing Multilingual Applications 26 / 35

Page 56: international PHP2011_Kore Nordmann_Designing multilingual applications

Number formatting

1 <?php23 var dump ( number format ( 42000 .23 , 2 ) ) ;4 // s t r i n g ( 9) ”42 ,000 .23”56 var dump ( number format ( 42000 .23 , 2 , ’ , ’ , ’ . ’ ) ) ;7 // s t r i n g ( 9) ”42 .000 ,23”

Designing Multilingual Applications 26 / 35

Page 57: international PHP2011_Kore Nordmann_Designing multilingual applications

Number formatting

1 <?php23 var dump ( number format ( 42000 .23 , 2 ) ) ;4 // s t r i n g ( 9) ”42 ,000 .23”56 var dump ( number format ( 42000 .23 , 2 , ’ , ’ , ’ . ’ ) ) ;7 // s t r i n g ( 9) ”42 .000 ,23”

Designing Multilingual Applications 26 / 35

Page 58: international PHP2011_Kore Nordmann_Designing multilingual applications

Number formatting

1 <?php23 var dump ( number format ( 42000 .23 , 2 ) ) ;4 // s t r i n g ( 9) ”42 ,000 .23”56 var dump ( number format ( 42000 .23 , 2 , ’ , ’ , ’ . ’ ) ) ;7 // s t r i n g ( 9) ”42 .000 ,23”

Designing Multilingual Applications 26 / 35

Page 59: international PHP2011_Kore Nordmann_Designing multilingual applications

Number formatting (Intl)

1 <?php23 $ f o rma t t e r = new NumberFormatter ( ’ de DE ’ , NumberFormatter : : DECIMAL ) ;4 var dump ( $ fo rmat t e r−>fo rmat ( 42000.23 ) ) ;5 // s t r i n g (9 ) ”42 .000 ,23”67 $ f o rma t t e r = new NumberFormatter ( ’ en US ’ , NumberFormatter : : SPELLOUT ) ;8 var dump ( $ fo rmat t e r−>fo rmat ( 42000.23 ) ) ;9 // s t r i n g (34) ” f o r t y−two thousand po i n t two t h r e e ”

Designing Multilingual Applications 27 / 35

Page 60: international PHP2011_Kore Nordmann_Designing multilingual applications

Number formatting (Intl)

1 <?php23 $ f o rma t t e r = new NumberFormatter ( ’ de DE ’ , NumberFormatter : : DECIMAL ) ;4 var dump ( $ fo rmat t e r−>fo rmat ( 42000.23 ) ) ;5 // s t r i n g (9 ) ”42 .000 ,23”67 $ f o rma t t e r = new NumberFormatter ( ’ en US ’ , NumberFormatter : : SPELLOUT ) ;8 var dump ( $ fo rmat t e r−>fo rmat ( 42000.23 ) ) ;9 // s t r i n g (34) ” f o r t y−two thousand po i n t two t h r e e ”

Designing Multilingual Applications 27 / 35

Page 61: international PHP2011_Kore Nordmann_Designing multilingual applications

Number formatting (Intl)

1 <?php23 $ f o rma t t e r = new NumberFormatter ( ’ de DE ’ , NumberFormatter : : DECIMAL ) ;4 var dump ( $ fo rmat t e r−>fo rmat ( 42000.23 ) ) ;5 // s t r i n g (9 ) ”42 .000 ,23”67 $ f o rma t t e r = new NumberFormatter ( ’ en US ’ , NumberFormatter : : SPELLOUT ) ;8 var dump ( $ fo rmat t e r−>fo rmat ( 42000.23 ) ) ;9 // s t r i n g (34) ” f o r t y−two thousand po i n t two t h r e e ”

Designing Multilingual Applications 27 / 35

Page 62: international PHP2011_Kore Nordmann_Designing multilingual applications

Number formatting (Intl)

1 <?php23 $ f o rma t t e r = new NumberFormatter ( ’ de DE ’ , NumberFormatter : : DECIMAL ) ;4 var dump ( $ fo rmat t e r−>fo rmat ( 42000.23 ) ) ;5 // s t r i n g (9 ) ”42 .000 ,23”67 $ f o rma t t e r = new NumberFormatter ( ’ en US ’ , NumberFormatter : : SPELLOUT ) ;8 var dump ( $ fo rmat t e r−>fo rmat ( 42000.23 ) ) ;9 // s t r i n g (34) ” f o r t y−two thousand po i n t two t h r e e ”

Designing Multilingual Applications 27 / 35

Page 63: international PHP2011_Kore Nordmann_Designing multilingual applications

Date formatting

1 <?php23 $t ime = 1234567890;45 var dump ( s t r f t i m e ( ’%A, %e . %B %G − %I :%M %P ’ , $t ime ) ) ;6 // s t r i n g (38) ” Saturday , 14 . Feb rua ry 2009 − 12 :31 am”78 s e t l o c a l e ( LC TIME , ’ de ’ , ’ de DE ’ , ’ de DE .UTF−8 ’ , ’ deu ’ ) ;9 var dump ( s t r f t i m e ( ’%A, %e . %B %G − %H:%M’ , $t ime ) ) ;

10 // s t r i n g (33) ”Samstag , 14 . Februa r 2009 − 00 :31”

Designing Multilingual Applications 28 / 35

Page 64: international PHP2011_Kore Nordmann_Designing multilingual applications

Date formatting

1 <?php23 $t ime = 1234567890;45 var dump ( s t r f t i m e ( ’%A, %e . %B %G − %I :%M %P ’ , $t ime ) ) ;6 // s t r i n g (38) ” Saturday , 14 . Feb rua ry 2009 − 12 :31 am”78 s e t l o c a l e ( LC TIME , ’ de ’ , ’ de DE ’ , ’ de DE .UTF−8 ’ , ’ deu ’ ) ;9 var dump ( s t r f t i m e ( ’%A, %e . %B %G − %H:%M’ , $t ime ) ) ;

10 // s t r i n g (33) ”Samstag , 14 . Februa r 2009 − 00 :31”

Designing Multilingual Applications 28 / 35

Page 65: international PHP2011_Kore Nordmann_Designing multilingual applications

Date formatting

1 <?php23 $t ime = 1234567890;45 var dump ( s t r f t i m e ( ’%A, %e . %B %G − %I :%M %P ’ , $t ime ) ) ;6 // s t r i n g (38) ” Saturday , 14 . Feb rua ry 2009 − 12 :31 am”78 s e t l o c a l e ( LC TIME , ’ de ’ , ’ de DE ’ , ’ de DE .UTF−8 ’ , ’ deu ’ ) ;9 var dump ( s t r f t i m e ( ’%A, %e . %B %G − %H:%M’ , $t ime ) ) ;

10 // s t r i n g (33) ”Samstag , 14 . Februa r 2009 − 00 :31”

Designing Multilingual Applications 28 / 35

Page 66: international PHP2011_Kore Nordmann_Designing multilingual applications

Date formatting

1 <?php23 $t ime = 1234567890;45 var dump ( s t r f t i m e ( ’%A, %e . %B %G − %I :%M %P ’ , $t ime ) ) ;6 // s t r i n g (38) ” Saturday , 14 . Feb rua ry 2009 − 12 :31 am”78 s e t l o c a l e ( LC TIME , ’ de ’ , ’ de DE ’ , ’ de DE .UTF−8 ’ , ’ deu ’ ) ;9 var dump ( s t r f t i m e ( ’%A, %e . %B %G − %H:%M’ , $t ime ) ) ;

10 // s t r i n g (33) ”Samstag , 14 . Februa r 2009 − 00 :31”

Designing Multilingual Applications 28 / 35

Page 67: international PHP2011_Kore Nordmann_Designing multilingual applications

Date formatting (Intl)

1 <?php23 $t ime = 1234567890;45 $ f o rma t t e r = new I n t lDa t eFo rma t t e r (6 ’ en ’ ,7 I n t lDa t eFo rma t t e r : : FULL , // date8 I n t lDa t eFo rma t t e r : : SHORT // t ime9 ) ;

10 var dump ( $ fo rmat t e r−>fo rmat ( $t ime ) ) ;11 // s t r i n g (36) ” Saturday , Feb rua ry 14 , 2009 12 :31 AM”1213 $ f o rma t t e r = new I n t lDa t eFo rma t t e r (14 ’ de DE ’ ,15 I n t lDa t eFo rma t t e r : : FULL , // date16 I n t lDa t eFo rma t t e r : : SHORT // t ime17 ) ;18 var dump ( $ fo rmat t e r−>fo rmat ( $t ime ) ) ;19 // s t r i n g (31) ”Samstag , 14 . Februa r 2009 00 :31”

Designing Multilingual Applications 29 / 35

Page 68: international PHP2011_Kore Nordmann_Designing multilingual applications

Date formatting (Intl)

1 <?php23 $t ime = 1234567890;45 $ f o rma t t e r = new I n t lDa t eFo rma t t e r (6 ’ en ’ ,7 I n t lDa t eFo rma t t e r : : FULL , // date8 I n t lDa t eFo rma t t e r : : SHORT // t ime9 ) ;

10 var dump ( $ fo rmat t e r−>fo rmat ( $t ime ) ) ;11 // s t r i n g (36) ” Saturday , Feb rua ry 14 , 2009 12 :31 AM”1213 $ f o rma t t e r = new I n t lDa t eFo rma t t e r (14 ’ de DE ’ ,15 I n t lDa t eFo rma t t e r : : FULL , // date16 I n t lDa t eFo rma t t e r : : SHORT // t ime17 ) ;18 var dump ( $ fo rmat t e r−>fo rmat ( $t ime ) ) ;19 // s t r i n g (31) ”Samstag , 14 . Februa r 2009 00 :31”

Designing Multilingual Applications 29 / 35

Page 69: international PHP2011_Kore Nordmann_Designing multilingual applications

Date formatting (Intl)

1 <?php23 $t ime = 1234567890;45 $ f o rma t t e r = new I n t lDa t eFo rma t t e r (6 ’ en ’ ,7 I n t lDa t eFo rma t t e r : : FULL , // date8 I n t lDa t eFo rma t t e r : : SHORT // t ime9 ) ;

10 var dump ( $ fo rmat t e r−>fo rmat ( $t ime ) ) ;11 // s t r i n g (36) ” Saturday , Feb rua ry 14 , 2009 12 :31 AM”1213 $ f o rma t t e r = new I n t lDa t eFo rma t t e r (14 ’ de DE ’ ,15 I n t lDa t eFo rma t t e r : : FULL , // date16 I n t lDa t eFo rma t t e r : : SHORT // t ime17 ) ;18 var dump ( $ fo rmat t e r−>fo rmat ( $t ime ) ) ;19 // s t r i n g (31) ”Samstag , 14 . Februa r 2009 00 :31”

Designing Multilingual Applications 29 / 35

Page 70: international PHP2011_Kore Nordmann_Designing multilingual applications

Date formatting (Intl)

1 <?php23 $t ime = 1234567890;45 $ f o rma t t e r = new I n t lDa t eFo rma t t e r (6 ’ en ’ ,7 I n t lDa t eFo rma t t e r : : FULL , // date8 I n t lDa t eFo rma t t e r : : SHORT // t ime9 ) ;

10 var dump ( $ fo rmat t e r−>fo rmat ( $t ime ) ) ;11 // s t r i n g (36) ” Saturday , Feb rua ry 14 , 2009 12 :31 AM”1213 $ f o rma t t e r = new I n t lDa t eFo rma t t e r (14 ’ de DE ’ ,15 I n t lDa t eFo rma t t e r : : FULL , // date16 I n t lDa t eFo rma t t e r : : SHORT // t ime17 ) ;18 var dump ( $ fo rmat t e r−>fo rmat ( $t ime ) ) ;19 // s t r i n g (31) ”Samstag , 14 . Februa r 2009 00 :31”

Designing Multilingual Applications 29 / 35

Page 71: international PHP2011_Kore Nordmann_Designing multilingual applications

Alternatives

I Zend Date

I Symfony

I arbitDateFormatter

Designing Multilingual Applications 30 / 35

Page 72: international PHP2011_Kore Nordmann_Designing multilingual applications

Intl gems

I Collator

I Normalizer

I Locale

I MessageFormatter

I NumberFormatter

I IntlDateFormatter

Designing Multilingual Applications 31 / 35

Page 73: international PHP2011_Kore Nordmann_Designing multilingual applications

Charsets & Encodings

I Use UTF-8

I Also see: http://www.kore-nordmann.de/blog/php_

charset_encoding_FAQ.html

Designing Multilingual Applications 32 / 35

Page 74: international PHP2011_Kore Nordmann_Designing multilingual applications

Charsets & Encodings

I Use UTF-8

I Also see: http://www.kore-nordmann.de/blog/php_

charset_encoding_FAQ.html

Designing Multilingual Applications 32 / 35

Page 75: international PHP2011_Kore Nordmann_Designing multilingual applications

Outline

The Dispatcher

The Model

The View

Conclusion

Designing Multilingual Applications 33 / 35

Page 76: international PHP2011_Kore Nordmann_Designing multilingual applications

Conclusion

I There are really tricky domain specific problems

I Use solutions not depending on setlocale()

I Use intl extension if possible

Designing Multilingual Applications 34 / 35

Page 77: international PHP2011_Kore Nordmann_Designing multilingual applications

Thanks for listening

Please rate this talk athttp://joind.in/3491

and (optionally) give us some feedback right now

Designing Multilingual Applications 35 / 35

Page 78: international PHP2011_Kore Nordmann_Designing multilingual applications

Thanks for listening

Please rate this talk athttp://joind.in/3491

and (optionally) give us some feedback right now

This is very important for . . .

I Speakers

I Organizers

I You!

Designing Multilingual Applications 35 / 35

Page 79: international PHP2011_Kore Nordmann_Designing multilingual applications

Thanks for listening

Please rate this talk athttp://joind.in/3491

and (optionally) give us some feedback right now

Stay in touch

I Kore Nordmann

I [email protected]

I @koredn / @qafoo

Rent a PHP quality expert:http://qafoo.com

Designing Multilingual Applications 35 / 35