cvs: pear /I18Nv2 I18Nv2.php

From: Date: Sun, 14 Mar 2004 16:58:27 +0000
Subject: cvs: pear /I18Nv2 I18Nv2.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-17409@lists.php.net to get a copy of this message
mike Sun Mar 14 11:58:27 2004 EDT Modified files: /pear/I18Nv2 I18Nv2.php Log: * added helper methods for traversing language and locale ids http://cvs.php.net/diff.php/pear/I18Nv2/I18Nv2.php?r1=1.3&r2=1.4&ty=u Index: pear/I18Nv2/I18Nv2.php diff -u pear/I18Nv2/I18Nv2.php:1.3 pear/I18Nv2/I18Nv2.php:1.4 --- pear/I18Nv2/I18Nv2.php:1.3 Sun Mar 14 10:00:27 2004 +++ pear/I18Nv2/I18Nv2.php Sun Mar 14 11:58:27 2004 @@ -16,7 +16,7 @@ // | Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: I18Nv2.php,v 1.3 2004/03/14 15:00:27 mike Exp $ +// $Id: I18Nv2.php,v 1.4 2004/03/14 16:58:27 mike Exp $ /** * I18Nv2 @@ -34,7 +34,7 @@ * I18Nv2 - Internationalization v2 * * @author Michael Wallner <mike@php.net> -* @version $Revision: 1.3 $ +* @version $Revision: 1.4 $ * @access public * @package I18Nv2 */ @@ -192,6 +192,56 @@ } /** + * Traverse locales to languages + * + * Returns en-US, de-DE from en_US and de_DE + * + * @static + * @access public + * @return array + * @param array $locales + */ + function locales2langs($locales) + { + return I18Nv2::_traverseLL($locales, '_', '-'); + } + + /** + * Traverse languages to locales + * + * Returns en_US, de_DE from en-US and de-DE + * + * @static + * @access public + * @return array + * @param array $languages + */ + function langs2locales($languages) + { + return I18Nv2::_traverseLL($languages, '-', '_'); + } + + /** + * Helper for traversing locales and languages + * + * @static + * @access private + * @return array + * @param array $array + * @param string $from + * @param string $to + */ + function _traverseLL($array, $from, $to) + { + setType($array, 'array'); + foreach ($array as $key => $entry) { + $array[$key] = str_replace($from, $to, $entry); + } + return $array; + } + + + /** * Get access to static property * * @static

« previous php.pear.cvs (#17409) next »