Adrian World Design
  • Services
    • Website Consulting
    • Startup Consulting
    • Zend Development
  • Portfolio
    • My Framework
  • Knowledge
    • Web Standards
    • PHP bare-bones
    • Zend Framework
    • Zend Framework 2
    • Git - Github
    • Search Engine Optimization
    • Web Hosting
    • Linux
    • Microsoft Windows
    • Web Browsers
    • Mobile Devices
  • About
    • Business
    • Professionally
    • Personally
  • Contact
    • Contact Form
    • Phone
    • Email
    • Messaging

Knowledge Base Overview

Array List with Languages

Knowledge ⇒ Zend Framework ⇒ Helpful Tips ⇒ Array List with Languages
Tweet
Share on Tumblr

Created: Oct 9, 2011, 3:45:22 PM CDTLast updated: Feb 21, 2012, 8:25:25 AM CDT

Are you looking for a list with some data about languages? Preferably in a PHP array and even with the translations in all these languages?

The power of Zend_Locale

If you don't know Zend Framework then a hearty welcome to Zend Framework and especially the power of Zend_Locale. If you feel comfortable with a large and somewhat complex application framework you will love Zend_Locale and what it can do for you in terms of a language list. Especially when you need the list in exactly these different languages. In this little tutorial I will show you how to work with Zend_Locale and get a list with almost all the languages in this world in almost all these languages.

First some background

According to the documentation "Zend_Locale is the Frameworks answer to the question, "How can the same application be used around the whole world?" ... and some more. Besides all the main purposes in Zend_Locale there is this little hidden treasure which might be overlooked by most people. Zend_Locale uses an impressive amount of XML lists with all sorts of data and you are basically able to pull aggregated lists of this data. Including a list of all languages but also continents, territories and countries. Check out my other page about the Countries Lists.

As with all Zend classes you don't need a full installation and implementation of the framework. You just need to make sure you get the path right. The Zend_Locale class can be used independently and most methods are implemented as static methods, i.e. you don't even have to create an object of the class. Check out ZF classes as stand alone objects for more info.

The easy solution

To get a list from Zend_Locale you will use a method named "getTranslationList". You can pass three arguments:

$type - This is the name for the list you want [required]
$locale - The language you want [optional] - default is your browser/system default
$value - Some types allow detailed lists which can be selected with this [optional]

This is almost all you need to know to get your list with all languages in the world. So, what are the values we need for the arguments? First is the type where we say that we like to get the languages. Second you set a locale to get the list in the language you want or leave it empty to get it in the browser's default language. No value is require for the value argument.

// just use a different locale to get different languages
$languageArray = Zend_Locale::getTranslationList('language','en_US');
That's basically all you need to get your language list. Easy as pie.

A list with all the supported types for Zend_Locale can be found in the official documentation; search the page for getTranslationList.

Download a list

Unfortunately at this time I don't have a list yet ready for download. I have plans to create a web site similar to the Countries List website where you can generate your own language lists. Once that is complete I will have a link here to that site.

As for now you need Zend_Locale and what this page is all about. This page will show you how to create a languages list.

blog comments powered by Disqus
Prev
Next

Powered by FeedBurner Load our "Knowledge Base" feed in your RSS feeder

Follow us on Twitter
Follow us on Facebook
Follow us on LinkedIn
Follow us on Google+

All rights reserved, Adrian World Design ©2009–2022 Powered by Wejas Framework

Jump to Top