ICanBoogie/I18n master
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • I18n
      • Translator

Classes

  • Proxi
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 
<?php

/*
 * This file is part of the ICanBoogie package.
 *
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ICanBoogie\I18n\Translator;

use ICanBoogie\Object;

/**
 * The Proxi class creates translators, which can be used to easily translate string using
 * a same set of options.
 */
class Proxi extends Object
{
    protected $options = array();

    public function __construct(array $options=array())
    {
        $this->options = $options;

        if (isset($this->options['scope']))
        {
            $this->scope = $this->options['scope'];
        }
    }

    protected function set_scope($scope)
    {
        if (is_array($scope))
        {
            $scope = implode('.', $scope);
        }

        $this->options['scope'] = $scope;
    }

    protected function set_language($language)
    {
        $this->options['language'] = $language;
    }

    protected function set_default($default)
    {
        $this->options['default'] = $default;
    }

    public function __invoke($str, array $args=array(), array $options=array())
    {
        $options += $this->options;

        if (isset($options['scope']) && isset($this->options['scope']))
        {
            $scope = $options['scope'];

            if (is_array($scope))
            {
                $scope = implode('.', $scope);
            }

            if ($scope{0} == '.')
            {
                $options['scope'] = $this->options['scope'] . $scope;
            }
        }

        return \ICanBoogie\I18n\t($str, $args, $options);
    }
}
ICanBoogie/I18n master API documentation generated by ApiGen