4 * StatusNet - the distributed open-source microblogging tool
5 * Copyright (C) 2008, 2009, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero 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 * This program 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 Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // Abort if called from a web server
22 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
23 print "This script must be run from the command line\n";
27 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
28 define('STATUSNET', true);
29 define('LACONICA', true); // compatibility
31 require_once(INSTALLDIR . '/lib/common.php');
33 // Master StatusNet .pot file location (created by update_pot.sh)
34 $statusnet_pot = INSTALLDIR . '/locale/statusnet.po';
38 /* Languages to pull */
39 $languages = get_all_languages();
41 /* Update the languages */
43 foreach ($languages as $language) {
45 $code = $language['lang'];
46 $file_url = 'http://status.net/pootle/' . $code .
47 '/statusnet/LC_MESSAGES/statusnet.po';
48 $lcdir = INSTALLDIR . '/locale/' . $code;
49 $msgdir = "$lcdir/LC_MESSAGES";
50 $pofile = "$msgdir/statusnet.po";
51 $mofile = "$msgdir/statusnet.mo";
53 /* Check for an existing */
54 if (!is_dir($msgdir)) {
59 $existingSHA1 = file_exists($pofile) ? sha1_file($pofile) : '';
62 /* Get the remote one */
63 $new_file = curl_get_file($file_url);
65 if ($new_file === FALSE) {
66 echo "Couldn't retrieve .po file for $code: $file_url\n";
70 // Update if the local .po file is different to the one downloaded, or
71 // if the .mo file is not present.
72 if (sha1($new_file) != $existingSHA1 || !file_exists($mofile)) {
73 echo "Updating ".$code."\n";
74 file_put_contents($pofile, $new_file);
75 system(sprintf('msgmerge -U %s %s', $pofile, $statusnet_pot));
76 system(sprintf('msgfmt -f -o %s %s', $mofile, $pofile));
78 echo "Unchanged - ".$code."\n";
85 function curl_get_file($url)
88 curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
89 curl_setopt($c, CURLOPT_URL, $url);
90 $contents = curl_exec($c);
93 if (!empty($contents)) {