Dotclear

source: plugins/buildtools/class.dc.maintenance.buildtools.php @ 3730:5c45a5df9a59

Revision 3730:5c45a5df9a59, 2.6 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Code formatting (PSR-2)

Line 
1<?php
2
3class dcMaintenanceBuildtools extends dcMaintenanceTask
4{
5    protected $tab   = 'dev';
6    protected $group = 'l10n';
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        $this->description = __('Generate a php file that contents strings to translate that are not be done with core tools.');
14    }
15
16    public function execute()
17    {
18        global $core;
19        $widget = $this->core->plugins->getModules("widgets");
20        include $widget['root'] . '/_default_widgets.php';
21
22        $faker = new l10nFaker($GLOBALS['core']);
23        $faker->generate_file();
24        return true;
25    }
26}
27
28class l10nFaker
29{
30    protected $core;
31    protected $bundled_plugins;
32
33    public function __construct($core)
34    {
35        $this->core            = $core;
36        $this->bundled_plugins = explode(',', DC_DISTRIB_PLUGINS);
37        $this->core->media     = new dcMedia($this->core);
38    }
39
40    protected function fake_l10n($str)
41    {
42        return sprintf('__("%s");' . "\n", str_replace('"', '\\"', $str));
43    }
44    public function generate_file()
45    {
46        global $__widgets;
47        global $__autoload;
48
49        $main   = "<?php\n";
50        $plugin = "<?php\n";
51        $main .= "# Media sizes\n\n";
52        foreach ($this->core->media->thumb_sizes as $k => $v) {
53            $main .= $this->fake_l10n($v[2]);
54        }
55        $post_types = $this->core->getPostTypes();
56        $main .= "\n# Post types \n\n";
57        foreach ($post_types as $k => $v) {
58            $main .= $this->fake_l10n($v['label']);
59        }
60        $ws = $this->core->auth->user_prefs->favorites; // Favs old school !
61        if ($ws) {
62            $main .= "\n# Favorites \n\n";
63            foreach ($ws->dumpPrefs() as $k => $v) {
64                $fav = unserialize($v['value']);
65                $main .= $this->fake_l10n($fav['title']);
66            }
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