]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/update_translations.php
0af0810ac63b958725153a298625e7bd6f46c1c5
[quix0rs-gnu-social.git] / scripts / update_translations.php
1 <?php
2
3 set_time_limit(60);
4 chdir(dirname(__FILE__) . '/..');
5
6 /* Languages to pull */
7 $languages = array(
8         'da_DK' => 'http://laconi.ca/translate/download.php?file_id=23',
9         'nl_NL' => 'http://laconi.ca/translate/download.php?file_id=39',
10         'en_NZ' => 'http://laconi.ca/translate/download.php?file_id=15',
11         'eo'    => 'http://laconi.ca/translate/download.php?file_id=10',
12         'fr_FR' => 'http://laconi.ca/translate/download.php?file_id=19',
13         'de_DE' => 'http://laconi.ca/translate/download.php?file_id=18',
14         'it_IT' => 'http://laconi.ca/translate/download.php?file_id=21',
15         'ko'    => 'http://laconi.ca/translate/download.php?file_id=33',
16         'no_NB' => 'http://laconi.ca/translate/download.php?file_id=31',
17         'pt'    => 'http://laconi.ca/translate/download.php?file_id=8',
18         'pt_BR' => 'http://laconi.ca/translate/download.php?file_id=11',
19         'ru_RU' => 'http://laconi.ca/translate/download.php?file_id=26',
20         'es'    => 'http://laconi.ca/translate/download.php?file_id=9',
21         'tr_TR' => 'http://laconi.ca/translate/download.php?file_id=37',
22         'uk_UA' => 'http://laconi.ca/translate/download.php?file_id=44',
23         'he_IL' => 'http://laconi.ca/translate/download.php?file_id=71',
24 );
25
26 /* Update the languages */
27 foreach ($languages as $code => $file) {
28
29         $lcdir='locale/'.$code;
30         $msgdir=$lcdir.'/LC_MESSAGES';
31         $pofile=$msgdir.'/laconica.po';
32         $mofile=$msgdir.'/laconica.mo';
33
34         /* Check for an existing */
35         if (!is_dir($msgdir)) {
36                 mkdir($lcdir);
37                 mkdir($msgdir);
38                 $existingSHA1 = '';
39         } else {
40                 $existingSHA1 = file_exists($pofile) ? sha1_file($pofile) : '';
41         }
42
43         /* Get the remote one */
44         $newFile = file_get_contents($file);
45
46         // Update if the local .po file is different to the one downloaded, or
47         // if the .mo file is not present.
48         if(sha1($newFile)!=$existingSHA1 || !file_exists($mofile)) {
49                 echo "Updating ".$code."\n";
50                 file_put_contents($pofile, $newFile);
51                 $prevdir = getcwd();
52                 chdir($msgdir);
53                 system('msgmerge -U laconica.po ../../laconica.pot');
54                 system('msgfmt -f -o laconica.mo laconica.po');
55                 chdir($prevdir);
56         } else {
57                 echo "Unchanged - ".$code."\n";
58         }
59 }
60 echo "Finished\n";