Updates to the update_translations script

darcs-hash:20080925092854-f6e2c-b1b73a1f01e8541cd354edfd9b879447a52b928e.gz
This commit is contained in:
CiaranG 2008-09-25 05:28:54 -04:00
parent 3ea4a46f06
commit d582985c42
1 changed files with 49 additions and 39 deletions

View File

@ -19,32 +19,42 @@ $languages = array(
'ru_RU' => 'http://laconi.ca/translate/download.php?file_id=26', 'ru_RU' => 'http://laconi.ca/translate/download.php?file_id=26',
'es' => 'http://laconi.ca/translate/download.php?file_id=9', 'es' => 'http://laconi.ca/translate/download.php?file_id=9',
'tr_TR' => 'http://laconi.ca/translate/download.php?file_id=37', 'tr_TR' => 'http://laconi.ca/translate/download.php?file_id=37',
'uk_UA' => 'http://laconi.ca/translate/download.php?file_id=27', 'uk_UA' => 'http://laconi.ca/translate/download.php?file_id=44',
'he_IL' => 'http://laconi.ca/translate/download.php?file_id=71',
); );
/* Update the languages */ /* Update the languages */
foreach ($languages as $code => $file) { foreach ($languages as $code => $file) {
$lcdir='locale/'.$code;
$msgdir=$lcdir.'/LC_MESSAGES';
$pofile=$msgdir.'/laconica.po';
$mofile=$msgdir.'/laconica.mo';
/* Check for an existing */ /* Check for an existing */
if (!is_dir('locale/' . $code)) { if (!is_dir($msgdir)) {
mkdir('locale/' . $code); mkdir($lcdir);
mkdir('locale/' . $code . '/LC_MESSAGES'); mkdir($msgdir);
$existingSHA1 = ''; $existingSHA1 = '';
} else { } else {
$existingSHA1 = file_exists('locale/' . $code . '/LC_MESSAGES/laconica.po') ? sha1_file('locale/' . $code . '/LC_MESSAGES/laconica.po') : ''; $existingSHA1 = file_exists($pofile) ? sha1_file($pofile) : '';
} }
/* Get the remote one */ /* Get the remote one */
$newFile = file_get_contents($file); $newFile = file_get_contents($file);
/* Are the different? */ // Update if the local .po file is different to the one downloaded, or
if (sha1($newFile) != $existingSHA1) { // if the .mo file is not present.
/* Yes, update */ if(sha1($newFile)!=$existingSHA1 || !file_exists($mofile)) {
file_put_contents('locale/' . $code . '/LC_MESSAGES/laconica.po', $newFile); echo "Updating ".$code."\n";
file_put_contents($pofile, $newFile);
$prevdir = getcwd(); $prevdir = getcwd();
chdir('locale/' . $code . '/LC_MESSAGES/'); chdir($msgdir);
system('msgmerge -U laconica.po ../../laconica.pot'); system('msgmerge -U laconica.po ../../laconica.pot');
system('msgfmt -f -o laconica.mo laconica.po'); system('msgfmt -f -o laconica.mo laconica.po');
chdir($prevdir); chdir($prevdir);
} else {
echo "Unchanged - ".$code."\n";
} }
} }
echo "Finished\n";