Travel to the Caribbean
Enjoy the skies, the water, the views.


Accommodation
and real estate:
from affordable to luxury

Caribation

Caribation. The sunny side of your life.

Bungalow for rent


Bookmark Caribation: Ctrl-D


National flag Dominican RepublicEmergency phones
Dominican Republic
Ambulance 809-532 0000
Fire Brigade:
Santo Domingo 809-682 2000
Boca Chica 809-523 4626
Puerto Plata 809-586 2312
Police:
Santo Domingo 809-682 2151
Puerto Plata 809-586 2331
National flag CubaEmergency phones Cuba
Ambulance (Havana)
838 1185
838 2185
Fire Brigade: 105
Police: 106
Drug Unit: 103




italy Hotel (italiano parlato)

italy Appartamento a Boca Chica




villa-ocean-view.caribation.com
seaview.caribation.com
punta-bonita.caribation.com
playa-bonita.caribation.com
beachapartment.caribation.com
altos-de-chavon.caribation.com
oceanview.caribation.com


Home | Mobile | About us | Link to us! | Contact Russian Русский Dominican Русский

Palma Real

Zend_Locale
A translation exercise

 

Caribation Labs reports


Caribation Service for Web Developers

Using Zend_Locale for web internationalization


Do you want a piece of cake from foreign markets? Zend_Locale() is a great help if you want to make your site speak any language you may think of or need.

In this exercise I will present you the power of the getTranslation() method.

Task: multi-language list of world territories

Let us imagine that for an eCommerce project (airline?) we need the list of all countries of the world in 5 languages:

  1. English (mainly for the web developer, who only speaks English and PHP ;-)
  2. original that is country name written in the language of that country, e.g. España for Spain or "Ελλάδα" for Greece
  3. Chinese - our new market
  4. Traditional Chinese (we care about Hong Kong and Taiwan, too)
  5. German (with an eye on investors?)

(Hong Kong and Taiwan speak the same language as mainland Chinese, but they write it differently)

Why would I need these country names? For the <SELECT> statements in my web forms, for example. Or to insert in email templates. As a result I want an array with all territories of the world (almost 300, more then UN members), each with a sub-array of 5 elements. If I take Greece as an example I will need the following five strings:

"Greece", "Ελλάδα", "希腊", "希臘", "Griechenland"

Question: how many lines of code do I need to get it from Zend?

I would squeeze in about 10, but as Zend coding style recommends 80 characters per line (did they ever notice how monitor sizes grew in the recent years?) I'll probably end up with 20

The coding starts:

        $locale = new Zend_Locale();
        $territoryList = $locale->getTranslationList('territory');
      

Nothing can be simpler. Initialized Zend_Locale and obtained the list with territories (in a similar way, you can get names of the months, curreny symbols and many other cute things). Please note that I didn't pass a locale ('de_CH' etc.) to the constructor. It could often be quite important, but not for this exercise.

It is time to create the array:

        foreach ($territoryList as $key => $value) {
          try {
            $aCountries[$key] = array(
                'english'   => $value,
                'original'  => $locale->getTranslation($key, 'territory', $key),
                'china'     => $locale->getTranslation($key, 'territory', 'zh_ZH'),
                'hong_kong' => $locale->getTranslation($key, 'territory', 'zh_HK'),
                'german'    => $locale->getTranslation($key, 'territory', 'de')

            );
          } catch (Exception $e) {
            continue;
          }
        }
        

That's it, folks.

Comments

the $key is 2-letter code for the territory, e.g. GR for Greece.

the $value is in English, our first array element

getTranslation() receives three parameters: (1) the territory code, (2) the data category, (3) locale, such as 'en_US', or even just the language ('en') of the string it is supposed to return.

Caution: The value in the second array element ('original') may sometimes deceive you. Here I wanted to obtain a country name written in the language of the country, which is no problem for Greece used as an example. For countries with more then one national language (Canada, Switzerland, etc.) Zend will make a decision for you. For the territory of Canada ($key == 'CA') Zend will return English and for the territory of Switzerland ($key == 'CH') will return Deutsch.

The reason is that in our example we pass territory as $key and not a locale (as fr_CH) or language (as fr). Please check Zend on-line documentation for the concept of locales and territories Zend Locale

Please note the power of the third parameter. If it is a locale, like 'zh_HK', it will automatically determine the language version (or dialect) spoken in the given territory. In this example: Hong-Kong Chinese

Echoing the final result: $aCountries

        ...
        ["GR"] =>
        array (
          ["english"] =>  "Greece",
          ["original"] => "Ελλάδα",
          ["china"] =>  "希腊",
          ["hong_kong"] =>  "希臘",
          ["german"] =>  "Griechenland"
        ),
        ["GS"] =>
        ...

Coming soon: Zend_Date() and Zend_Currency()



What do you think? Like Zend? Share your experience, remarks, questions...


Trying some mash-up on the topic...

Pictures from flickr (Yahoo): zend

Electron bladen
2012-11-29

remzi133 posted a photo:

Electron bladen

Profondità di campo
2012-06-24

Stefano_59 posted a photo:

Profondità di campo

Zend Framework on Wiki






Caribation Labs for the future of your web experience

House with ocean view in Dom Rep

House with ocean view $299 500

caribbean apartment with ocean view

Apartment with Ocean View for rent in a beach area

Advertisement

Learning IT on workshops in the Dominican Republic

IT courses in the Dom Rep
Half-day study, half-day beach
How about that?

National flag Dominican Republic
National flag Cuba
National flag Dominican RepublicNational flag Cuba
National flag Dominican Republic
no drugs no minors
 

December & January: only hotel bookings accepted (no apartments)

5.3.23