Development

/branches/1.0/lib/helper/I18NHelper.php

You must first sign up to be able to contribute.

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

Revision 5141, 1.9 kB (checked in by fabien, 7 years ago)

fixed consistent syntax of i18n helper function when i18n is off (closes #1851)

  • 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   static $i18n;
23
24   if (sfConfig::get('sf_i18n'))
25   {
26     if (!isset($i18n))
27     {
28       $i18n = sfContext::getInstance()->getI18N();
29     }
30
31     return $i18n->__($text, $args, $catalogue);
32   }
33   else
34   {
35     if (empty($args))
36     {
37       $args = array();
38     }
39
40     // replace object with strings
41     foreach ($args as $key => $value)
42     {
43       if (is_object($value) && method_exists($value, '__toString'))
44       {
45         $args[$key] = $value->__toString();
46       }
47     }
48
49     return strtr($text, $args);
50   }
51 }
52
53 function format_number_choice($text, $args = array(), $number, $catalogue = 'messages')
54 {
55   $translated = __($text, $args, $catalogue);
56
57   $choice = new sfChoiceFormat();
58
59   $retval = $choice->format($translated, $number);
60
61   if ($retval === false)
62   {
63     $error = sprintf('Unable to parse your choice "%s"', $translated);
64     throw new sfException($error);
65   }
66
67   return $retval;
68 }
69
70 function format_country($country_iso, $culture = null)
71 {
72   $c = new sfCultureInfo($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
73   $countries = $c->getCountries();
74
75   return isset($countries[$country_iso]) ? $countries[$country_iso] : '';
76 }
77
78 function format_language($language_iso, $culture = null)
79 {
80   $c = new sfCultureInfo($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
81   $languages = $c->getLanguages();
82
83   return isset($languages[$language_iso]) ? $languages[$language_iso] : '';
84 }
85
Note: See TracBrowser for help on using the browser.