$locales = array_keys($locales);
    } else {
        foreach ($locales as $i => $locale) {
            $files = glob($templates_dir . '*' . DIRECTORY_SEPARATOR . '*.po');
            if (count($files) == 0) {
                echo "WARNING: the locale {$locale} has no .po files   -- Skipping\n";
                unset($locales[$i]);
            }
        }
    }
}
if (count($locales) == 0) {
    usage("No valid locales specified");
}
I2CE::raiseError("Translating for locales:\n\t" . implode(',', $locales));
$templates = getTranslatableDocuments(false);
$configs = getTranslatableConfigs(false);
//http://www.i18nguy.com/temp/rtl.html
//http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
$RTLS = array('ar', 'ara', 'arc', 'aze', 'az', 'cmc', 'div', 'dv', 'fa', 'fas', 'he', 'jav', 'jv', 'jpr', 'jrb', 'kas', 'kaz', 'kk', 'ku', 'kur', 'ks', 'lad', 'ma', 'mal', 'may', 'ms', 'msa', 'pa', 'pal', 'pan', 'peo', 'per', 'ps', 'pus', 'sam', 'sd', 'so', 'som', 'snd', 'syc', 'syr', 'tmh', 'tk', 'tuk', 'ug', 'uig', 'ur', 'urd');
$first_time = true;
$changed_text = false;
ksort($found_modules);
foreach ($locales as $locale) {
    $locale_dashed = $locale;
    if (($dash_pos = strpos($locale_dashed, '-')) === false) {
        if (($pos = strpos($locale_dashed, '_')) !== false) {
            $two_letter = substr($locale, 0, $pos);
            $locale_dashed[$pos] = '-';
        } else {
            $two_letter = $locale;
    $template_dir = $args['template_dir'];
}
if (!is_dir($template_dir)) {
    if (!mkdir($template_dir, 0775, true)) {
        usage("Could not make {$template_dir}");
    }
}
//fixup permissions if set badly before
chmod($template_dir, 0775);
if (!is_writeable($template_dir)) {
    usage("The direcotory {$locales_dir} is not a readable directory");
}
$template_dir = realpath($template_dir);
$configs = getTranslatableConfigs(true);
//this will just create any en_US that we need to
$templates = getTranslatableDocuments();
function addString(&$strings, $text)
{
    if (!array_key_exists($text, $strings)) {
        $strings[$text] = array();
    }
}
function addPluralString(&$strings, $text, $text_plural)
{
    addString($strings, $text);
    $strings[$text]['msg_plural'] = $text_plural;
}
function setComment(&$strings, $text, $type, $comment)
{
    addString($strings, $text);
    if (!array_key_exists('comments', $strings[$text])) {