Let's take over the world with Zend Framework

Post on 09-May-2015

2,724 views 4 download

description

Many people use Zend Framework for it's MVC implementation, but it has a lot of hidden gems. Internationalization (i18n) is one of them. We will look how you can create an application that will have the right languages, currencies, dates and times all based on the location of the visiting user. This session will take away a lot of headaches in international projects and will improve the quality in overall.

transcript

Dutch PHP Conference 2011Martin de Keijzer

Let’s take over the world with Zend Framework

Monday, 23 May 2011

Introduction

2Monday, 23 May 2011

Introduction

Martin de Keijzer

Software engineer at IbuildingsBoard member of PHPBeneluxPHP 5 Zend Certified Engineer

Twitter: Martin1982Joind.in: http://joind.in/3253Blog: www.martindekeijzer.nl

3Monday, 23 May 2011

DISCLAIMER

DISCLAIMER: ALL EXAMPLE CODE IS WRITTEN IN THE CONTROLLER BY

EXAMPLE! USE MODELS!!!!

4Monday, 23 May 2011

Monday, 23 May 2011

The case

6

What do we need to take over the world?

Monday, 23 May 2011

The case

✓Location (Country and region)

✓Language

✓Date and time

✓Currency

✓Measuring

7Monday, 23 May 2011

“Location! Location! Location!”Quote from Achmed (2009)

8Monday, 23 May 2011

Zend Locale

Monday, 23 May 2011

A locale defines a country (territory) and a language to bind the various localized information to it.

Zend Locale

10Monday, 23 May 2011

Zend Locale

nl_NL

de_BE

fr_BE

nl_BE

11Monday, 23 May 2011

CLDRCommon Locale Data Repository

http://cldr.unicode.org

Zend Locale

12Monday, 23 May 2011

Zend Locale

13Monday, 23 May 2011

Zend Locale

The current locale is is: nlThe browser's locale is is: nlThe environment's locale is is: de_DEThe set locale is is: en_US

14Monday, 23 May 2011

Zend Locale

15Monday, 23 May 2011

Zend Locale

16Monday, 23 May 2011

Zend Locale

17

In FR people speak fr

Monday, 23 May 2011

Zend Locale

18

In FR people speak fr. In France people speak French.

Monday, 23 May 2011

Zend Locale

19Monday, 23 May 2011

Zend Locale

20Monday, 23 May 2011

Zend Locale

array(6) { ["yes"]=> string(2) "ja" ["no"]=> string(3) "nee"}

21Monday, 23 May 2011

Zend Locale

["yesarray"]=> array(2) { [0]=>string(2) "ja" [1]=>string(1) "j" } ["noarray"]=> array(2) { [0]=>string(3) "nee" [1]=>string(1) "n" }

22Monday, 23 May 2011

Zend Locale

["yesexpr"]=> string(20) "^([jJ][aA]?)|([jJ]?)" ["noexpr"]=> string(26) "^([nN]([eE][eE])?)|([nN]?)"

23Monday, 23 May 2011

Zend Locale

Utilized by:

Zend_Controller_RouterZend_CurrencyZend_DateZend_FilterZend_MeasureZend_Service_TechnoratiZend_TimesyncZend_TranslateZend_Validate

25Monday, 23 May 2011

Speaking the languageZend_Translate

26Monday, 23 May 2011

Zend Translate

Operates using adapters:Array

Csv

Gettext

Tbx

Tmx

Qt

Xliff

Xmltm

27Monday, 23 May 2011

Zend Translate

28Monday, 23 May 2011

Zend Translate

29Monday, 23 May 2011

Zend Translate

30

nl.php

fr.php

Monday, 23 May 2011

Zend Translate

31

my-view.phtml

Monday, 23 May 2011

Zend Locale

32Monday, 23 May 2011

Zend Locale

Quick hint: Google uses locales too!Zend Framework is your gateway to more power!

33Monday, 23 May 2011

Monday, 23 May 2011

Do not get lost in timeZend_Date

35Monday, 23 May 2011

Zend Date

The date is May 2, 2011 9:13:41 PM. The date is 2 mei 2011 21:13:41.

36Monday, 23 May 2011

Zend Timesync

37

2 mai 2011 21:25:09

Monday, 23 May 2011

Zend_Locale revisited

38

You can use Zend_Locale_Format to overridedate and number formatting.

I never had any use for it though.....

Monday, 23 May 2011

Show me the money!Zend_Currency

39Monday, 23 May 2011

Zend Currency

40Monday, 23 May 2011

Zend Currency

In the Netherlands you pay with Euro (€).And in the UK you pay with British Pound

Sterling (£).

41Monday, 23 May 2011

Zend Currency

42Monday, 23 May 2011

Zend Currency

43

Please hand me 10.00 US Dollar for food and

shelter.

Monday, 23 May 2011

Zend Currency

44

Got lost in locales?getCurrencyList()getRegionList()

getLocale()

Monday, 23 May 2011

Never trust a user!Zend_Validate

45Monday, 23 May 2011

Zend Validate

46Monday, 23 May 2011

Zend Validate

47Monday, 23 May 2011

Measures please?Zend_Measure

48Monday, 23 May 2011

Zend Measure

49Monday, 23 May 2011

Zend Measure

50

A Big Mac’s weight is 200,05 g in the Netherlands.

In the USA this would be 0.441034755500847600236309 lbs

Monday, 23 May 2011

Zend Measure

Zend_Measure doesn’t utilize locales to give you the correct units, but only the correct number

formats.

51Monday, 23 May 2011

Conclusion

52Monday, 23 May 2011

Questions ?

54Monday, 23 May 2011

Thank you!

Contact details:

Twitter: @Martin1982Blog: http://www.martindekeijzer.nl

Please give feedback on Joind.in!http://joind.in/3253

Monday, 23 May 2011