kartik\helpers\Enum::initI18N PHP Method

initI18N() public static method

Initialize translations
public static initI18N ( )
    public static function initI18N()
    {
        if (!empty(Yii::$app->i18n->translations['kvenum'])) {
            return;
        }
        Yii::setAlias("@kvenum", __DIR__);
        Yii::$app->i18n->translations['kvenum*'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => "@kvenum/messages", 'forceTranslation' => true];
    }

Usage Example

Esempio n. 1
0
 /**
  * Generates an address block.
  *
  * @param string $name the addressee name
  * @param array $lines the lines of address information
  * @param array $phone the list of phone numbers - passed as $key => $value, where:
  *    - $key is the phone type could be 'Res', 'Off', 'Cell', 'Fax'
  *    - $value is the phone number
  * @param array $email the list of email addresses - passed as $key => $value, where:
  *    - $key is the email type could be 'Res', 'Off'
  *    - $value is the email address
  * @param array $options html options for the address
  * @param string $phoneLabel the prefix label for each phone - defaults to '(P)'
  * @param string $emailLabel the prefix label for each email - defaults to '(E)'
  *
  * Example(s):
  * ~~~
  * echo Html::address(
  *      'Twitter, Inc.',
  *      ['795 Folsom Ave, Suite 600', 'San Francisco, CA 94107'],
  *      ['Res' => '(123) 456-7890', 'Off'=> '(456) 789-0123'],
  *      ['Res' => '*****@*****.**', 'Off' => '*****@*****.**']
  * );
  * $address = Html::address(
  *      'Twitter, Inc.',
  *      ['795 Folsom Ave, Suite 600', 'San Francisco, CA 94107'],
  *      ['Res' => '(123) 456-7890', 'Off'=> '(456) 789-0123'],
  *      ['Res' => '*****@*****.**', 'Off' => '*****@*****.**'],
  *      Html::icon('phone'),
  *      Html::icon('envelope')
  * );
  * echo Html::well($address, Html::SIZE_TINY);
  * ~~~
  *
  * @see http://getbootstrap.com/css/#type-addresses
  */
 public static function address($name, $lines = [], $phone = [], $email = [], $options = [], $phoneLabel = '(P)', $emailLabel = '(E)')
 {
     Enum::initI18N();
     $addresses = '';
     if (!empty($lines)) {
         $addresses = implode('<br>', $lines) . "<br>\n";
     }
     $phones = '';
     foreach ($phone as $type => $number) {
         if (is_numeric($type)) {
             // no keys were passed to the phone array
             $type = static::tag('abbr', $phoneLabel, ['title' => Yii::t('kvenum', 'Phone')]) . ': ';
         } else {
             $type = static::tag('abbr', $phoneLabel . ' ' . $type, ['title' => Yii::t('kvenum', 'Phone')]) . ': ';
         }
         $phones .= "{$type}{$number}<br>\n";
     }
     $emails = '';
     foreach ($email as $type => $addr) {
         if (is_numeric($type)) {
             // no keys were passed to the email array
             $type = Html::tag('abbr', $emailLabel, ['title' => Yii::t('kvenum', 'Email')]) . ': ';
         } else {
             $type = Html::tag('abbr', $emailLabel . ' ' . $type, ['title' => Yii::t('kvenum', 'Email')]) . ': ';
         }
         $emails .= $type . static::mailto($addr, $addr) . "<br>\n";
     }
     return static::tag('address', "<strong>{$name}</strong><br>\n" . $addresses . $phones . $emails, $options);
 }