1 #!/usr/bin/php5
2 <?php
4 define ("LOCALE_DIR", "/home/cajus/Projekte/gosa/trunk/gosa-all/gosa/locale");
6 function print_usage()
7 {
8 ?>
9 update-gosa - class cache updated and plugin manager for GOsa
10 Usage: update-gosa Update the class cache
12 update-gosa install-plugin plugin Install the plugin named "plugin" in
13 the GOsa tree.
15 update-gosa remove-plugin plugin Remove the plugin named "plugin" from
16 the current configuration.
18 update-gosa list-plugins Lists installed plugins
20 update-gosa rescan-i18n Rebuilds the translations
22 <?php
23 exit (1);
24 }
27 function rescan_i18n()
28 {
29 $languages= array();
30 $size= strlen(LOCALE_DIR);
32 /* Get all available messages.po files, sort them for languages */
33 $dir= new RecursiveDirectoryIterator(LOCALE_DIR);
34 $all= new RecursiveIteratorIterator($dir);
35 foreach ( $all as $element ){
36 if ($element->isFile() && preg_match('/\/LC_MESSAGES\/messages.po$/', $element->getPathname())){
37 $lang= preg_replace('/^.*\/([^\/]+)\/LC_MESSAGES\/.*$/', '\1', $element);
38 if (!isset($languages[$lang])){
39 $languages[$lang]= array();
40 }
41 $languages[$lang][]= substr($element->getPathName(), $size+1);
42 }
43 }
45 /* For each language, merge the target .mo to the compiled directory. */
46 foreach ($languages as $language => $po_files){
47 if (!is_dir(LOCALE_DIR."/compiled/${language}/LC_MESSAGES")){
48 if (!mkdir (LOCALE_DIR."/compiled/${language}/LC_MESSAGES", 0755, TRUE)){
49 echo "Failed to create '".LOCALE_DIR."/compiled/${language}/LC_MESSAGES'- aborted";
50 exit (3);
51 }
52 }
54 /* Cat all these po files into one single file */
55 system ("(cd ".LOCALE_DIR." && msgcat ".implode(" ", $po_files)." > compiled/${language}/LC_MESSAGES/messages.po)", $val);
56 if ($val != 0){
57 echo "Merging of message files failed - aborted";
58 exit (4);
59 }
60 system ("(cd ".LOCALE_DIR."/compiled/${language}/LC_MESSAGES && msgfmt -o messages.mo messages.po && rm messages.po)", $val);
61 if ($val != 0){
62 echo "Compiling of message files failed - aborted";
63 exit (5);
64 }
65 }
66 }
69 /* Action specified? */
70 if ($argc < 2){
71 exit (0);
72 }
73 switch ($argv[1]){
74 case 'install-plugin':
75 echo "install\n";
76 break;
77 case 'list-plugins':
78 echo "list\n";
79 break;
80 case 'remove-plugin':
81 echo "remove\n";
82 break;
83 case 'rescan-i18n':
84 rescan_i18n();
85 break;
86 default:
87 echo "Error: Supplied command not known\n\n";
88 print_usage();
89 break;
90 }
93 ?>