123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
- }
- define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
- define('GNUSOCIAL', true);
- define('STATUSNET', true);
- require_once(INSTALLDIR . '/lib/common.php');
- $statusnet_pot = INSTALLDIR . '/locale/statusnet.pot';
- set_time_limit(60);
- $languages = get_all_languages();
- $codeMap = array(
- 'nb' => 'no',
- 'pt_BR' => 'pt-br',
- 'zh_CN' => 'zh-hans',
- 'zh_TW' => 'zh-hant'
- );
- $doneCodes = array();
- foreach ($languages as $language) {
- $code = $language['lang'];
-
-
- if( $code == 'en' || $code == 'no' ) {
- continue;
- }
-
- if( in_array( $code, $doneCodes ) ) {
- continue;
- } else {
- $doneCodes[] = $code;
- }
-
- if( isset( $codeMap[$code] ) ) {
- $twnCode = $codeMap[$code];
- } else {
- $twnCode = str_replace('_', '-', strtolower($code));
- }
-
- $file_url = 'http://translatewiki.net/w/i.php?' .
- http_build_query(array(
- 'title' => 'Special:Translate',
- 'task' => 'export-to-file',
- 'group' => 'out-statusnet-core',
- 'language' => $twnCode));
- $lcdir = INSTALLDIR . '/locale/' . $code;
- $msgdir = "$lcdir/LC_MESSAGES";
- $pofile = "$msgdir/statusnet.po";
- $mofile = "$msgdir/statusnet.mo";
-
- if (!is_dir($msgdir)) {
- mkdir($lcdir);
- mkdir($msgdir);
- $existingSHA1 = '';
- } else {
- $existingSHA1 = file_exists($pofile) ? sha1_file($pofile) : '';
- }
-
- $new_file = curl_get_file($file_url);
- if ($new_file === FALSE) {
- echo "Could not retrieve .po file for $code: $file_url\n";
- continue;
- }
-
-
- if (sha1($new_file) != $existingSHA1 || !file_exists($mofile)) {
- echo "Updating ".$code."\n";
- file_put_contents($pofile, $new_file);
-
- system(sprintf('msgmerge -U --backup=off %s %s', $pofile, $statusnet_pot));
-
- } else {
- echo "Unchanged - ".$code."\n";
- }
- }
- echo "Finished\n";
- function curl_get_file($url)
- {
- $c = curl_init();
- curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($c, CURLOPT_URL, $url);
- $contents = curl_exec($c);
- curl_close($c);
- if (!empty($contents)) {
- return $contents;
- }
- return FALSE;
- }
|