Further work on Moodle 1.9 integration.
[moodle/mihaisucan.git] / lib / paintweb / ext / moodle / gen_paintweblang.php
blobe5ece22be8d721daad721e477a73c4725c2fd23f
1 <?php
2 /*
3 * Copyright (C) 2009 Mihai Şucan
5 * This file is part of PaintWeb.
7 * PaintWeb is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * PaintWeb is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
20 * $URL: http://code.google.com/p/paintweb $
21 * $Date: 2009-08-10 15:58:48 +0300 $
24 // This script allows you to convert a Moodle PHP language file into a PaintWeb
25 // JSON language file.
27 // In a typical setup, Moodle holds PaintWeb in lib/paintweb.
29 // When you execute this script you must provide one argument with the language
30 // code you want. For example "en", "ro", "fr" or some other code.
32 // Warning: running this script will overwrite the JSON language file from the
33 // PaintWeb language folder.
35 // This script works with Moodle 1.9 and Moodle 2.0.
37 $paintweblangdir = '../../build/lang';
38 $moodlelangdir = '../../../../lang';
39 $moodlelangfile = 'paintweb.php';
41 if (!is_dir($paintweblangdir)) {
42 echo "The PaintWeb folder could not be found: $paintweblangdir\n";
43 return 1;
46 if (!is_dir($moodlelangdir)) {
47 echo "The Moodle folder could not be found: $moodlelangdir\n";
48 return 1;
51 if (!isset($_SERVER['argv'][1])) {
52 echo 'This script requires one argument, the language code for which you ' .
53 "want this script to perform the conversion.\n";
54 return 1;
57 $lang = $_SERVER['argv'][1];
59 $inputfolder = $moodlelangdir . '/' . ($lang === 'en' ? 'en_utf8' : $lang);
61 if (!is_dir($inputfolder)) {
62 echo "The following folder was not found: $inputfolder\n";
63 return 1;
66 $inputfile = $inputfolder . '/' . $moodlelangfile;
68 if (!file_exists($inputfile)) {
69 echo "The following file was not found: $inputfile\n";
70 return 1;
73 require_once($inputfile);
75 $outputarray = array();
77 foreach ($string as $key => $val) {
78 $keyarr = explode(':', $key);
79 $langprop = array_pop($keyarr);
80 $langgroup = &$outputarray;
82 foreach ($keyarr as $prop) {
83 if (!isset($langgroup[$prop])) {
84 $langgroup[$prop] = array();
87 $langgroup = &$langgroup[$prop];
90 $langgroup[$langprop] = $val;
93 $output = json_encode($outputarray);
94 $outputfile = $paintweblangdir . '/' . $lang . '.json';
96 if (file_put_contents($outputfile, $output)) {
97 echo "Updated file $outputfile\n";
98 } else {
99 echo "Failed to update $outputfile\n";
100 return 1;
103 // vim:set spell spl=en fo=tanqrowcb tw=80 ts=4 sw=4 sts=4 sta et noai nocin fenc=utf-8 ff=unix: