dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


advertisement
 

Base Concepts of Internationalization in PHP : Page 2

Discover how to use internationalized numbers, currencies and dates/times with the I18N PEAR package.


advertisement

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Using the I18N_Country Class
You use the I18N_Country class to determine the country name from a country code. The class has these two methods:

  • void getName([: $code = '']): Returns the name of the country using the country code passed by the string argument $code.
  • void isValidCode(mixed $code): Check whether the country code passed by the $code argument is valid.
Here's a simple example that shows how to use the methods of the I18N_Country class:

<?php require_once 'I18N/Country.php'; $countries_codes = array('AF','AQ','BD', 'MB','DE','FR','HR','JP','IS','IT','MU', 'RO','US','JA'); print '<font face style="Arial" color="000076">'; print '<h4><u>Countries codes</u></h4>'; foreach( $countries_codes as $code ) { //Create an instance of the I18N_Country class $country = new I18N_Country (); print '<font face style="Arial" color="000076" size="3"><b>'.$code.'</b> -->'; //Check if $code is a valid code if($country->isValidCode($code)) { //Return name of the country for country code passed print ( $country->getName($code) ).'<br />'; } else { print '<font face style="Arial" color="red" size="3">'; print ( '<b> This is not a valid code!!! </b><br />' ); } } ?>

The output of this example is:

Countries codes AF -->AFGHANISTAN AQ -->ANTARCTICA BD -->BANGLADESH MB --> <font color=red>This is not a valid code!!!</font> DE -->GERMANY FR -->FRANCE HR -->CROATIA (local name: Hrvatska) JP -->JAPAN IS -->ICELAND IT -->ITALY MU -->MAURITIUS RO -->ROMANIA US -->UNITED STATES JA --> <font color=red>This is not a valid code!!! </font>

Using the I18N_Language Class
You use the I18N_Language class to determine the language name from a specified language code using the getName method:

  • void getName([: $code = ''], : 1): Returns the name of the language using the language code passed by the string argument $code. The 1 parameter represents the string language code.
Here's a simple application that uses the I18N_Language class:



<?php require_once 'I18N/Language.php'; $language_codes = array('af','da','es','de','fr','ja', 'it','mn','ro','en'); print '<font face style="Arial" color="000076">'; print '<h4><u>Language codes</u></h4>'; foreach( $language_codes as $code ) { //Create an instance of the I18N_Language class $language = new I18N_Language (); print '<font face style="Arial" color="000076" size="3"><b>'. $code.'</b> -->'; //Return name of the language for language code passed print ($language->getName($code)).'<br />'; } ?>

The output of this example is:

Language codes af -->Afrikaans da -->Danish es -->Spanish de -->German fr -->French ja -->Japanese it -->Italian mn -->Mongolian ro -->Romanian en -->English

The combination of the user's country and language give you the locale.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date