Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • AlterColumnsEvent
  • AlterQueryEvent
  • AlterRenderedCellsEvent
  • BooleanCellRenderer
  • BooleanColumn
  • CellRenderer
  • Column
  • DateColumn
  • DateTimeColumn
  • EditColumn
  • EditDecorator
  • FilterDecorator
  • HeaderRenderer
  • KeyColumn
  • Options
  • RegisterColumnsEvent
  • SizeColumn
  • Translator
 1 <?php
 2 
 3 /*
 4  * This file is part of the Icybee package.
 5  *
 6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
 7  *
 8  * For the full copyright and license information, please view the LICENSE
 9  * file that was distributed with this source code.
10  */
11 
12 namespace Icybee\ManageBlock;
13 
14 use ICanBoogie\I18n;
15 use ICanBoogie\Module;
16 
17 /**
18  * A translator that leverages module inheritance to translate strings.
19  */
20 class Translator
21 {
22     protected $module;
23 
24     public function __construct(Module $module)
25     {
26         $this->module = $module;
27     }
28 
29     public function __invoke($native, array $args=array(), array $options=array())
30     {
31         $module = $this->module;
32 
33         $user_scope = isset($options['scope']) ? $options['scope'] : null;
34         $user_scope_dotted = $user_scope ? "{$user_scope}." : '';
35         $user_default = isset($options['default']) ? $options['default'] : null;
36 
37         $options['scope'] = "{$this->module->flat_id}.manage" . ($user_scope ? ".$user_scope" : '');
38 
39         $options['default'] = function(\ICanBoogie\I18n\Translator $translator, $native) use($module, $user_scope_dotted, $user_default) {
40 
41             while ($module = $module->parent)
42             {
43                 $try = "$module->flat_id.manage.{$user_scope_dotted}$native";
44                 $translated = $translator[$try];
45 
46                 if ($translated)
47                 {
48                     return $translated;
49                 }
50             }
51 
52             return $translator["manage.{$user_scope_dotted}$native"]
53             ?: $translator["{$user_scope_dotted}$native"]
54             ?: ($user_default instanceof \Closure ? $user_default($translator, $native) : $translator[$user_default])
55             ?: $user_default;
56         };
57 
58         return I18n\t($native, $args, $options);
59     }
60 }
Autodoc API documentation generated by ApiGen 2.8.0