Development

/branches/1.2/lib/helper/I18NHelper.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/helper/I18NHelper.php

Revision 11700, 1.8 kB (checked in by fabien, 6 years ago)

[1.1, 1.2] changed internal classes to always use the sfCultureInfo singleton

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * I18NHelper.
13  *
14  * @package    symfony
15  * @subpackage helper
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19
20 function __($text, $args = array(), $catalogue = 'messages')
21 {
22   if (sfConfig::get('sf_i18n'))
23   {
24     return sfContext::getInstance()->getI18N()->__($text, $args, $catalogue);
25   }
26   else
27   {
28     if (empty($args))
29     {
30       $args = array();
31     }
32
33     // replace object with strings
34     foreach ($args as $key => $value)
35     {
36       if (is_object($value) && method_exists($value, '__toString'))
37       {
38         $args[$key] = $value->__toString();
39       }
40     }
41
42     return strtr($text, $args);
43   }
44 }
45
46 function format_number_choice($text, $args = array(), $number, $catalogue = 'messages')
47 {
48   $translated = __($text, $args, $catalogue);
49
50   $choice = new sfChoiceFormat();
51
52   $retval = $choice->format($translated, $number);
53
54   if ($retval === false)
55   {
56     throw new sfException(sprintf('Unable to parse your choice "%s".', $translated));
57   }
58
59   return $retval;
60 }
61
62 function format_country($country_iso, $culture = null)
63 {
64   $c = sfCultureInfo::getInstance($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
65   $countries = $c->getCountries();
66
67   return isset($countries[$country_iso]) ? $countries[$country_iso] : '';
68 }
69
70 function format_language($language_iso, $culture = null)
71 {
72   $c = sfCultureInfo::getInstance($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
73   $languages = $c->getLanguages();
74
75   return isset($languages[$language_iso]) ? $languages[$language_iso] : '';
76 }
77
Note: See TracBrowser for help on using the browser.