Example #1
0
 /**
  * Return an array of strings for a locale from a repository
  * @param  string $locale     Locale we want to have strings for
  * @param  string $repository string repository such as gaia_1_3, central...
  * @return array  Localized strings or empty array if no match
  */
 public static function getRepoStrings($locale, $repository)
 {
     $locale = Project::getLocaleInContext($locale, $repository);
     $file = TMX . "{$locale}/cache_{$locale}_{$repository}.php";
     if (!($tmx = Cache::getKey($file))) {
         if (is_file($file)) {
             include $file;
             Cache::setKey($file, $tmx);
         }
     }
     return isset($tmx) ? $tmx : [];
 }
Example #2
0
 /**
  * Return an array of strings for a locale from a repository
  * @param  string $locale     Locale we want to have strings for
  * @param  string $repository string repository such as gaia_2_0, central...
  * @return array  Localized strings or empty array if no match
  */
 public static function getRepoStrings($locale, $repository)
 {
     $locale = Project::getLocaleInContext($locale, $repository);
     $file = TMX . "{$locale}/cache_{$locale}_{$repository}.php";
     if (!is_file($file)) {
         return [];
     }
     include $file;
     if (!isset($tmx)) {
         error_log('$tmx not set in file: ' . $file);
     }
     return $tmx;
 }
Example #3
0
    foreach (array_keys($projects['release']['repos']) as $repo) {
        if (in_array($repo, array_keys(Project::$components_names))) {
            $active_projects .= Project::$components_names[$repo] . ', ';
        }
    }
    $active_projects .= '</li>';
}
if (isset($projects['gaia'])) {
    $active_projects .= '<li><b>Gaia:</b> ';
    foreach (array_keys($projects['gaia']) as $repo) {
        $active_projects .= Project::getRepositoriesNames()[$repo] . ', ';
    }
    $active_projects .= '</li>';
}
if (isset($projects['others'])) {
    $active_projects .= '<li><b>Others:</b> ';
    foreach (array_keys($projects['others']) as $repo) {
        $active_projects .= Project::getRepositoriesNames()[$repo] . ', ';
    }
    $active_projects .= '</li>';
}
$active_projects .= '</ul>';
// Build locales select
$target_locales_list = '';
foreach ($locales_list as $loc) {
    if ($loc == 'en-US') {
        continue;
    }
    $ch = $loc == $locale ? ' selected' : '';
    $target_locales_list .= "\t<option{$ch} value={$loc}>{$loc}</option>\n";
}
Example #4
0
    $completion = $completion > 100 ? 100 : $completion;
    // Get color from completion value
    $color = Utils::redYellowGreen($completion);
    // Get active projects
    if (isset($projects['release']['repos'])) {
        $active_projects .= '<li><b>Desktop:</b> ';
        $tmp_projects = [];
        foreach (array_keys($projects['release']['repos']) as $repo) {
            if (in_array($repo, array_keys(Project::$components_names))) {
                $tmp_projects[] = Project::$components_names[$repo];
            }
        }
        $active_projects .= implode(', ', $tmp_projects) . '</li>';
    }
    if (isset($projects['gaia'])) {
        $active_projects .= '<li><b>Gaia:</b> ';
        $tmp_projects = [];
        foreach (array_keys($projects['gaia']) as $repo) {
            $tmp_projects[] = Project::getRepositoriesNames()[$repo];
        }
        $active_projects .= implode(', ', $tmp_projects) . '</li>';
    }
    if (isset($projects['others'])) {
        $active_projects .= '<li><b>Others:</b> ';
        $tmp_projects = [];
        foreach (array_keys($projects['others']) as $repo) {
            $tmp_projects[] = Project::getRepositoriesNames()[$repo];
        }
        $active_projects .= implode(', ', $tmp_projects) . '</li>';
    }
}
Example #5
0
 /**
  * Check that a locale is available for a repository
  *
  * @param  string  $locale     Locale code we want to check
  * @param  string  $repository Repository name we want to check the locale for
  * @return boolean True if we support the locale, False if we don't
  */
 private function verifyLocaleExists($locale, $repository)
 {
     if (!in_array($locale, Project::getRepositoryLocales($repository))) {
         $this->log("The locale queried ({$locale}) is not " . "available for the repository ({$repository}).");
         return false;
     }
     return true;
 }
Example #6
0
 /**
  * @dataProvider getLocaleInContextDP
  */
 public function testGetLocaleInContext($a, $b, $c)
 {
     $obj = new _Project();
     $this->string($obj->getLocaleInContext($a, $b))->isEqualTo($c);
 }
Example #7
0
<?php

namespace Transvision;

use Cache\Cache;
$cache_id = $repo . $entity . 'alllocales';
if (!($translations = Cache::getKey($cache_id))) {
    $translations = [];
    foreach (Project::getRepositoryLocales($repo) as $locale_code) {
        $strings = Utils::getRepoStrings($locale_code, $repo);
        if (isset($strings[$entity])) {
            $strings[$entity] = trim($strings[$entity]);
            if (Strings::endsWith(strtolower($strings[$entity]), '{ok}')) {
                $strings[$entity] = trim(substr($strings[$entity], 0, -4));
            }
            $translations[$locale_code] = $strings[$entity];
        }
        // Releasing memory in the loop saves 15% memory on the script
        unset($strings);
    }
    Cache::setKey($cache_id, $translations);
}
return $json = $translations;