| [1977] | 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | class dcMaintenanceBuildtools extends dcMaintenanceTask |
|---|
| 5 | { |
|---|
| [2044] | 6 | protected $tab = 'dev'; |
|---|
| 7 | protected $group = 'l10n'; |
|---|
| [1977] | 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.'); |
|---|
| [2044] | 14 | $this->description = __('Generate a php file that contents strings to translate that are not be done with core tools.'); |
|---|
| [1977] | 15 | } |
|---|
| 16 | |
|---|
| 17 | public function execute() |
|---|
| 18 | { |
|---|
| 19 | global $core; |
|---|
| 20 | $widget = $this->core->plugins->getModules("widgets"); |
|---|
| 21 | include $widget['root'].'/_default_widgets.php'; |
|---|
| [2566] | 22 | |
|---|
| [1977] | 23 | $faker = new l10nFaker($GLOBALS['core']); |
|---|
| 24 | $faker->generate_file(); |
|---|
| 25 | return true; |
|---|
| 26 | } |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | class l10nFaker { |
|---|
| 30 | protected $core; |
|---|
| 31 | protected $bundled_plugins; |
|---|
| [2566] | 32 | |
|---|
| [1978] | 33 | public function __construct($core) { |
|---|
| [1977] | 34 | $this->core = $core; |
|---|
| [2286] | 35 | $this->bundled_plugins = explode(',', DC_DISTRIB_PLUGINS); |
|---|
| [1977] | 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; |
|---|
| [2566] | 45 | |
|---|
| [1977] | 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 | } |
|---|
| [2355] | 57 | $ws = $this->core->auth->user_prefs->favorites; // Favs old school ! |
|---|
| 58 | if ($ws) { |
|---|
| 59 | $main .= "\n# Favorites \n\n"; |
|---|
| 60 | foreach ($ws->dumpPrefs() as $k => $v) { |
|---|
| 61 | $fav = unserialize($v['value']); |
|---|
| 62 | $main .= $this->fake_l10n($fav['title']); |
|---|
| 63 | } |
|---|
| [1977] | 64 | } |
|---|
| 65 | file_put_contents(dirname($__autoload['dcCore']).'/_fake_l10n.php', $main); |
|---|
| 66 | $plugin .= "\n# Plugin names \n\n"; |
|---|
| 67 | foreach ($this->bundled_plugins as $id) { |
|---|
| 68 | $p = $this->core->plugins->getModules($id); |
|---|
| 69 | $plugin .= $this->fake_l10n($p['desc']); |
|---|
| 70 | } |
|---|
| 71 | $plugin .= "\n# Widget settings names \n\n"; |
|---|
| 72 | $widgets = $__widgets->elements(); |
|---|
| 73 | foreach ($widgets as $w) { |
|---|
| 74 | $plugin .= $this->fake_l10n($w->desc()); |
|---|
| 75 | } |
|---|
| 76 | mkdir(dirname(__FILE__)."/../_fake_plugin"); |
|---|
| 77 | file_put_contents(dirname(__FILE__).'/../_fake_plugin/_fake_l10n.php', $plugin); |
|---|
| 78 | } |
|---|
| 79 | } |
|---|