translation update
[dokuwiki.git] / bin / striplangs.php
blob82d27d4627a9e80a26c64d04241ba41c1a3b0ec1
1 #!/usr/bin/php
2 <?php
3 if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/');
4 define('NOSESSION', 1);
5 require_once(DOKU_INC.'inc/init.php');
8 /**
9 * Remove unwanted languages from a DokuWiki install
11 class StripLangsCLI extends DokuCLI {
13 /**
14 * Register options and arguments on the given $options object
16 * @param DokuCLI_Options $options
17 * @return void
19 protected function setup(DokuCLI_Options $options) {
21 $options->setHelp(
22 'Remove all languages from the installation, besides the ones specified. English language '.
23 'is never removed!'
26 $options->registerOption(
27 'keep',
28 'Comma separated list of languages to keep in addition to English.',
29 'k',
30 'langcodes'
32 $options->registerOption(
33 'english-only',
34 'Remove all languages except English',
35 'e'
39 /**
40 * Your main program
42 * Arguments and options have been parsed when this is run
44 * @param DokuCLI_Options $options
45 * @return void
47 protected function main(DokuCLI_Options $options) {
48 if($options->getOpt('keep')) {
49 $keep = explode(',', $options->getOpt('keep'));
50 if(!in_array('en', $keep)) $keep[] = 'en';
51 } elseif($options->getOpt('english-only')) {
52 $keep = array('en');
53 } else {
54 echo $options->help();
55 exit(0);
58 // Kill all language directories in /inc/lang and /lib/plugins besides those in $langs array
59 $this->stripDirLangs(realpath(dirname(__FILE__).'/../inc/lang'), $keep);
60 $this->processExtensions(realpath(dirname(__FILE__).'/../lib/plugins'), $keep);
61 $this->processExtensions(realpath(dirname(__FILE__).'/../lib/tpl'), $keep);
64 /**
65 * Strip languages from extensions
67 * @param string $path path to plugin or template dir
68 * @param array $keep_langs languages to keep
70 protected function processExtensions($path, $keep_langs) {
71 if(is_dir($path)) {
72 $entries = scandir($path);
74 foreach($entries as $entry) {
75 if($entry != "." && $entry != "..") {
76 if(is_dir($path.'/'.$entry)) {
78 $plugin_langs = $path.'/'.$entry.'/lang';
80 if(is_dir($plugin_langs)) {
81 $this->stripDirLangs($plugin_langs, $keep_langs);
89 /**
90 * Strip languages from path
92 * @param string $path path to lang dir
93 * @param array $keep_langs languages to keep
95 protected function stripDirLangs($path, $keep_langs) {
96 $dir = dir($path);
98 while(($cur_dir = $dir->read()) !== false) {
99 if($cur_dir != '.' and $cur_dir != '..' and is_dir($path.'/'.$cur_dir)) {
101 if(!in_array($cur_dir, $keep_langs, true)) {
102 io_rmdir($path.'/'.$cur_dir, true);
106 $dir->close();
110 $cli = new StripLangsCLI();
111 $cli->run();