Dotclear

source: plugins/buildtools/class.dc.maintenance.buildtools.php @ 2286:c14a5e07a2f7

Revision 2286:c14a5e07a2f7, 2.2 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Formalizes themes and plugins provided with the distribution

Line 
1<?php
2
3
4class dcMaintenanceBuildtools extends dcMaintenanceTask
5{
6     protected $tab = 'dev';
7     protected $group = 'l10n';
8
9     protected function init()
10     {
11          $this->task         = __('Generate fake l10n');
12          $this->success           = __('fake l10n file generated.');
13          $this->error        = __('Failed to generate fake l10n file.');
14          $this->description  = __('Generate a php file that contents strings to translate that are not be done with core tools.');
15     }
16
17     public function execute()
18     {
19          global $core;
20          $widget = $this->core->plugins->getModules("widgets");
21          include $widget['root'].'/_default_widgets.php';
22         
23          $faker = new l10nFaker($GLOBALS['core']);
24          $faker->generate_file();
25          return true;
26     }
27}
28
29class l10nFaker {
30     protected $core;
31     protected $bundled_plugins;
32     
33     public function __construct($core) {
34          $this->core = $core;
35          $this->bundled_plugins = explode(',', DC_DISTRIB_PLUGINS);
36          $this->core->media = new dcMedia($this->core);
37     }
38
39     protected function fake_l10n($str) {
40          return sprintf('__("%s");'."\n",str_replace('"','\\"',$str));
41     }
42     public function generate_file() {
43          global $__widgets;
44          global $__autoload;
45         
46          $main = "<?php\n";
47          $plugin = "<?php\n";
48          $main .= "# Media sizes\n\n";
49          foreach ($this->core->media->thumb_sizes as $k=> $v) {
50               $main .= $this->fake_l10n($v[2]);
51          }
52          $post_types = $this->core->getPostTypes();
53          $main .= "\n# Post types \n\n";
54          foreach ($post_types as $k => $v) {
55               $main .= $this->fake_l10n($v['label']);
56          }
57          $ws = $this->core->auth->user_prefs->favorites;
58          $main .= "\n# Favorites \n\n";
59          foreach ($ws->dumpPrefs() as $k => $v) {
60               $fav = unserialize($v['value']);
61               $main .= $this->fake_l10n($fav['title']);
62          }
63          file_put_contents(dirname($__autoload['dcCore']).'/_fake_l10n.php', $main);
64          $plugin .= "\n# Plugin names \n\n";
65          foreach ($this->bundled_plugins as $id) {
66               $p = $this->core->plugins->getModules($id);
67               $plugin .= $this->fake_l10n($p['desc']);
68          }
69          $plugin .= "\n# Widget settings names \n\n";
70          $widgets = $__widgets->elements();
71          foreach ($widgets as $w) {
72               $plugin .= $this->fake_l10n($w->desc());
73          }
74          mkdir(dirname(__FILE__)."/../_fake_plugin");
75          file_put_contents(dirname(__FILE__).'/../_fake_plugin/_fake_l10n.php', $plugin);
76     }
77}
Note: See TracBrowser for help on using the repository browser.

Sites map