let's take over the world with zend framework

55
Dutch PHP Conference 2011 Martin de Keijzer Let’s take over the world with Zend Framework Monday, 23 May 2011

Upload: ibuildings

Post on 28-Jan-2015

108 views

Category:

Technology


1 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

Page 1: Let's take over the world with Zend Framework

Dutch PHP Conference 2011Martin de Keijzer

Let’s take over the world with Zend Framework

Monday, 23 May 2011

Page 2: Let's take over the world with Zend Framework

Introduction

2Monday, 23 May 2011

Page 3: Let's take over the world with Zend Framework

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

Page 4: Let's take over the world with Zend Framework

DISCLAIMER

DISCLAIMER: ALL EXAMPLE CODE IS WRITTEN IN THE CONTROLLER BY

EXAMPLE! USE MODELS!!!!

4Monday, 23 May 2011

Page 5: Let's take over the world with Zend Framework

Monday, 23 May 2011

Page 6: Let's take over the world with Zend Framework

The case

6

What do we need to take over the world?

Monday, 23 May 2011

Page 7: Let's take over the world with Zend Framework

The case

✓Location (Country and region)

✓Language

✓Date and time

✓Currency

✓Measuring

7Monday, 23 May 2011

Page 8: Let's take over the world with Zend Framework

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

8Monday, 23 May 2011

Page 9: Let's take over the world with Zend Framework

Zend Locale

Monday, 23 May 2011

Page 10: Let's take over the world with Zend Framework

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

Zend Locale

10Monday, 23 May 2011

Page 11: Let's take over the world with Zend Framework

Zend Locale

nl_NL

de_BE

fr_BE

nl_BE

11Monday, 23 May 2011

Page 12: Let's take over the world with Zend Framework

CLDRCommon Locale Data Repository

http://cldr.unicode.org

Zend Locale

12Monday, 23 May 2011

Page 13: Let's take over the world with Zend Framework

Zend Locale

13Monday, 23 May 2011

Page 14: Let's take over the world with Zend Framework

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

Page 15: Let's take over the world with Zend Framework

Zend Locale

15Monday, 23 May 2011

Page 16: Let's take over the world with Zend Framework

Zend Locale

16Monday, 23 May 2011

Page 17: Let's take over the world with Zend Framework

Zend Locale

17

In FR people speak fr

Monday, 23 May 2011

Page 18: Let's take over the world with Zend Framework

Zend Locale

18

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

Monday, 23 May 2011

Page 19: Let's take over the world with Zend Framework

Zend Locale

19Monday, 23 May 2011

Page 20: Let's take over the world with Zend Framework

Zend Locale

20Monday, 23 May 2011

Page 21: Let's take over the world with Zend Framework

Zend Locale

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

21Monday, 23 May 2011

Page 22: Let's take over the world with Zend Framework

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

Page 23: Let's take over the world with Zend Framework

Zend Locale

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

23Monday, 23 May 2011

Page 25: Let's take over the world with Zend Framework

Zend Locale

Utilized by:

Zend_Controller_RouterZend_CurrencyZend_DateZend_FilterZend_MeasureZend_Service_TechnoratiZend_TimesyncZend_TranslateZend_Validate

25Monday, 23 May 2011

Page 26: Let's take over the world with Zend Framework

Speaking the languageZend_Translate

26Monday, 23 May 2011

Page 27: Let's take over the world with Zend Framework

Zend Translate

Operates using adapters:Array

Csv

Gettext

Tbx

Tmx

Qt

Xliff

Xmltm

27Monday, 23 May 2011

Page 28: Let's take over the world with Zend Framework

Zend Translate

28Monday, 23 May 2011

Page 29: Let's take over the world with Zend Framework

Zend Translate

29Monday, 23 May 2011

Page 30: Let's take over the world with Zend Framework

Zend Translate

30

nl.php

fr.php

Monday, 23 May 2011

Page 31: Let's take over the world with Zend Framework

Zend Translate

31

my-view.phtml

Monday, 23 May 2011

Page 32: Let's take over the world with Zend Framework

Zend Locale

32Monday, 23 May 2011

Page 33: Let's take over the world with Zend Framework

Zend Locale

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

33Monday, 23 May 2011

Page 34: Let's take over the world with Zend Framework

Monday, 23 May 2011

Page 35: Let's take over the world with Zend Framework

Do not get lost in timeZend_Date

35Monday, 23 May 2011

Page 36: Let's take over the world with Zend Framework

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

Page 37: Let's take over the world with Zend Framework

Zend Timesync

37

2 mai 2011 21:25:09

Monday, 23 May 2011

Page 38: Let's take over the world with Zend Framework

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

Page 39: Let's take over the world with Zend Framework

Show me the money!Zend_Currency

39Monday, 23 May 2011

Page 40: Let's take over the world with Zend Framework

Zend Currency

40Monday, 23 May 2011

Page 41: Let's take over the world with Zend Framework

Zend Currency

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

Sterling (£).

41Monday, 23 May 2011

Page 42: Let's take over the world with Zend Framework

Zend Currency

42Monday, 23 May 2011

Page 43: Let's take over the world with Zend Framework

Zend Currency

43

Please hand me 10.00 US Dollar for food and

shelter.

Monday, 23 May 2011

Page 44: Let's take over the world with Zend Framework

Zend Currency

44

Got lost in locales?getCurrencyList()getRegionList()

getLocale()

Monday, 23 May 2011

Page 45: Let's take over the world with Zend Framework

Never trust a user!Zend_Validate

45Monday, 23 May 2011

Page 46: Let's take over the world with Zend Framework

Zend Validate

46Monday, 23 May 2011

Page 47: Let's take over the world with Zend Framework

Zend Validate

47Monday, 23 May 2011

Page 48: Let's take over the world with Zend Framework

Measures please?Zend_Measure

48Monday, 23 May 2011

Page 49: Let's take over the world with Zend Framework

Zend Measure

49Monday, 23 May 2011

Page 50: Let's take over the world with Zend Framework

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

Page 51: Let's take over the world with Zend Framework

Zend Measure

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

formats.

51Monday, 23 May 2011

Page 52: Let's take over the world with Zend Framework

Conclusion

52Monday, 23 May 2011

Page 54: Let's take over the world with Zend Framework

Questions ?

54Monday, 23 May 2011

Page 55: Let's take over the world with Zend Framework

Thank you!

Contact details:

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

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

Monday, 23 May 2011