GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Midgard Components Framework 3rd generation
Homepage: http://www.midgard-project.org
Clone URL: git://github.com/bergie/midcom.git
Added support for gettext inside TAL templates. TAL initialization need 
refactoring
Tero Heikkinen (author)
Thu Jul 17 00:39:31 -0700 2008
commit  42b9d406d35633c8494ec506de50e8d6492f0e6a
tree    3b62d23591ee825a2c4ce5dcb6262997021b1341
parent  9caf72c0aa06e5c3230696cb5911a9fcff5f6ef8
...
19
20
21
 
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
24
25
...
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
0
@@ -19,7 +19,34 @@ abstract class midcom_core_component_baseclass implements midcom_core_component_
0
     
0
     public function __construct($configuration)
0
     {
0
+ require_once('PHPTAL.php'); // FIXME: Better place required
0
+ require_once 'PHPTAL/GetTextTranslator.php'; // FIXME: Better place required
0
         $this->configuration = $configuration;
0
+ try {
0
+ $tr = new PHPTAL_GetTextTranslator();
0
+ $component = $configuration->get_component();
0
+
0
+ // set language to use for this session (first valid language will
0
+ // be used)
0
+ $lang = $_MIDCOM->configuration->get('default_language');
0
+ $tr->setLanguage($lang.'.utf8', $lang);
0
+
0
+ // register gettext domain to use
0
+ $path = MIDCOM_ROOT . "/{$component}/locale/";
0
+
0
+ $tr->addDomain($component, $path);
0
+
0
+ // specify current domain
0
+ $tr->useDomain($component);
0
+
0
+ // tell PHPTAL to use our translator
0
+ $_MIDCOM->templating->set_gettext_translator($tr);
0
+ }
0
+ catch (Exception $e)
0
+ {
0
+ echo $e;
0
+ }
0
+
0
     }
0
 
0
     public function initialize()
...
20
21
22
 
 
23
24
25
...
411
412
413
414
415
416
 
 
417
418
419
...
471
472
473
474
 
475
476
477
...
479
480
481
 
482
483
484
...
514
515
516
 
 
 
 
 
 
 
 
 
 
 
 
517
518
519
...
20
21
22
23
24
25
26
27
...
413
414
415
 
416
 
417
418
419
420
421
...
473
474
475
 
476
477
478
479
...
481
482
483
484
485
486
487
...
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
0
@@ -20,6 +20,8 @@ class midcom_core_services_templating_midgard implements midcom_core_services_te
0
 
0
     private $elements_shown = array();
0
 
0
+ private $gettext_translator = array();
0
+
0
     public function __construct()
0
     {
0
         $this->stacks[0] = array();
0
@@ -411,9 +413,9 @@ class midcom_core_services_templating_midgard implements midcom_core_services_te
0
                 if (!class_exists('PHPTAL'))
0
                 {
0
                     require('PHPTAL.php');
0
- include_once('TAL/modifiers.php');
0
                 }
0
-
0
+ include_once('TAL/modifiers.php');
0
+
0
                 if ($_MIDCOM->timer)
0
                 {
0
                     $_MIDCOM->timer->setMarker('post-require');
0
@@ -471,7 +473,7 @@ class midcom_core_services_templating_midgard implements midcom_core_services_te
0
                         $_MIDCOM->timer->setMarker("post-set-{$key}");
0
                     }
0
                 }
0
-
0
+
0
                 $tal->setSource($content);
0
                 
0
                 if ($_MIDCOM->timer)
0
@@ -479,6 +481,7 @@ class midcom_core_services_templating_midgard implements midcom_core_services_te
0
                     $_MIDCOM->timer->setMarker('post-source');
0
                 }
0
                 
0
+ $tal->setTranslator($this->gettext_translator[$data['component']]);
0
                 $content = $tal->execute();
0
                 
0
                 if ($_MIDCOM->timer)
0
@@ -514,5 +517,17 @@ class midcom_core_services_templating_midgard implements midcom_core_services_te
0
         ///TODO: Connect this to some signal that tells the MidCOM execution has ended.
0
         $_MIDCOM->uimessages->store();
0
     }
0
+
0
+ /**
0
+ * Setting gettext translator for TAL.
0
+ * This uses context to determine the component in use
0
+ * It enables the possibility to keep translations per component
0
+ */
0
+ function set_gettext_translator($tr)
0
+ {
0
+ $context = $_MIDCOM->context->get();
0
+ $this->gettext_translator[$context['component']] = $tr;
0
+ }
0
+
0
 }
0
 ?>
0
\ No newline at end of file

Comments

    No one has commented yet.