Dotclear

source: plugins/buildtools/class.dc.maintenance.buildtools.php @ 1977:0e8863856b51

Revision 1977:0e8863856b51, 2.3 KB checked in by Dsls, 12 years ago (diff)

Introducing buildtools fake plugin (not to be included in releases).

Resync l10n .po/.pot files

Line 
1<?php
2
3
4class dcMaintenanceBuildtools extends dcMaintenanceTask
5{
6     protected $group = 'other';
7
8     protected function init()
9     {
10          $this->task         = __('Generate fake l10n');
11          $this->success           = __('fake l10n file generated.');
12          $this->error        = __('Failed to generate fake l10n file.');
13     }
14
15     public function execute()
16     {
17          global $core;
18          $widget = $this->core->plugins->getModules("widgets");
19          include $widget['root'].'/_default_widgets.php';
20         
21          $faker = new l10nFaker($GLOBALS['core']);
22          $faker->generate_file();
23          return true;
24     }
25}
26
27class l10nFaker {
28     protected $core;
29     protected $dest;
30     protected $bundled_plugins;
31     
32     public function __construct($core,$dest) {
33          $this->core = $core;
34          $this->dest = $dest;
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