Skip to content

Instantly share code, notes, and snippets.

@erickok
Last active February 10, 2021 09:36
Show Gist options
  • Save erickok/6339183 to your computer and use it in GitHub Desktop.
Save erickok/6339183 to your computer and use it in GitHub Desktop.
Set of simple shell/php scripts to send the base translation and retrieve updated translations from a PASTT (https://github.com/erickok/pastt) installation. FTP (using ncftp) and SSH (using scp) versions are given. All scripts should be *run in a separate directory*, for example if your application 'myapp' resides in /home/myusername/dev/myapp/m…
echo 'Get remote translation files from the server.'
rm -rf res
ncftpget -u myusername -R -F mydomain.org . www/translate/res
rm -rf res/values
php diff-online-translations.php
echo 'Copy new translation files to our local working copy.'
cp -rf res /home/myusername/dev/myapp/myandroidapp/
echo 'Get remote translation files from the server.'
rm -rf res
scp -r [email protected]:/var/www/translate/res/ .
rm -rf res/values
php diff-online-translations.php
echo 'Copy new translation files to our local working copy.'
cp -rf res /home/myusername/dev/myapp/myandroidapp/
<?php
$resourcesroot = 'res';
// Look in the directories for new translations
if ($open = @opendir($resourcesroot)) {
while (false !== ($file = readdir($open))) {
if (substr($file, 0, 7) == 'values-') {
$langcode = substr($file, 7, 2);
$langpath = $resourcesroot . '/values-' . $langcode;
echo 'Language found: ' . $langcode."\n";
// Look all strings.[timestamp].xml files in this resource directory
unset($found);
if ($openv = opendir($langpath)) {
while (false !== ($xml = readdir($openv))) {
if (is_file($langpath . '/' . $xml) && ($xml != 'strings.xml') && substr($xml, 0, 7) == 'strings') {
$found[] = $langpath . '/' . $xml;
}
}
}
// If new translations exist
if (isset($found)) {
// Sort all xml files
rsort($found);
// Copy the newest translation to be the new 'strings.xml'
if (copy($found[0], $langpath . '/strings.xml')) {
echo 'New translation file copied.'."\n";
} else {
echo 'Error copying the new translation ' . $found[0] . ' to ' . $langpath . '/strings.xml!'."\n";
}
// Remove the temporary translation files
foreach ($found as $rm) {
exec('rm ' . $rm);
}
} else {
echo 'No new translations found for ' . $langcode . '.'."\n";
}
}
}
} else {
echo 'Cannot find the resources directory \'' . $resourcesroot . '\'. Did the FTP session fail?'."\n";
}
?>
echo 'Send base strings.xml file from our local working copy.'
ncftpput -u myusername -F mydomain.org www/translate/res/values /home/myusername/dev/myapp/myandroidapp/res/values/strings.xml
echo 'Send base strings.xml file from our SVN working copy.'
scp /home/myusername/dev/myapp/myandroidapp/res/values/strings.xml [email protected]:/var/www/translate/res/values/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment