Dotclear

source: plugins/buildtools/class.dc.maintenance.buildtools.php @ 2044:4a3330bc8bd5

Revision 2044:4a3330bc8bd5, 2.4 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Revamp plugin maintenance, final setp (perhaps still some typo), addresses #1484, fixes #1208, fixes #999

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 = array(
36               "aboutConfig","akismet","antispam","attachments","blogroll",
37               "blowupConfig","daInstaller","fairTrackbacks","importExport",
38               "maintenance","pages","pings","simpleMenu","tags","themeEditor",
39               "userPref","widgets"
40          );
41          $this->core->media = new dcMedia($this->core);
42     }
43
44     protected function fake_l10n($str) {
45          return sprintf('__("%s");'."\n",str_replace('"','\\"',$str));
46     }
47     public function generate_file() {
48          global $__widgets;
49          global $__autoload;
50         
51          $main = "<?php\n";
52          $plugin = "<?php\n";
53          $main .= "# Media sizes\n\n";
54          foreach ($this->core->media->thumb_sizes as $k=> $v) {
55               $main .= $this->fake_l10n($v[2]);
56          }
57          $post_types = $this->core->getPostTypes();
58          $main .= "\n# Post types \n\n";
59          foreach ($post_types as $k => $v) {
60               $main .= $this->fake_l10n($v['label']);
61          }
62          $ws = $this->core->auth->user_prefs->favorites;
63          $main .= "\n# Favorites \n\n";
64          foreach ($ws->dumpPrefs() as $k => $v) {
65               $fav = unserialize($v['value']);
66               $main .= $this->fake_l10n($fav['title']);
67          }
68          file_put_contents(dirname($__autoload['dcCore']).'/_fake_l10n.php', $main);
69          $plugin .= "\n# Plugin names \n\n";
70          foreach ($this->bundled_plugins as $id) {
71               $p = $this->core->plugins->getModules($id);
72               $plugin .= $this->fake_l10n($p['desc']);
73          }
74          $plugin .= "\n# Widget settings names \n\n";
75          $widgets = $__widgets->elements();
76          foreach ($widgets as $w) {
77               $plugin .= $this->fake_l10n($w->desc());
78          }
79          mkdir(dirname(__FILE__)."/../_fake_plugin");
80          file_put_contents(dirname(__FILE__).'/../_fake_plugin/_fake_l10n.php', $plugin);
81     }
82}
Note: See TracBrowser for help on using the repository browser.

Sites map