$stats['repo'] = $repo; unset($commits); /* cache the data */ Cache::setKey($cache_id, $stats); } // Utility closure to create a cache file of filtered strings $cache_filtered_strings = function ($lang, $cache_id) use($repo) { // Get all the strings (English and locale), ignore empty entities $filter_empty = function ($arr) { // return $arr; return array_filter($arr, 'strlen'); }; if ($cache = Cache::getKey($cache_id)) { return $cache; } else { $filtered_strings = $filter_empty(Utils::getRepoStrings($lang, $repo)); Cache::setKey($cache_id, $filtered_strings); return $filtered_strings; } }; $strings[$locale][$repo] = $cache_filtered_strings($locale, $locale . $repo . 'filteredstrings'); $strings[$ref_locale][$repo] = $cache_filtered_strings($ref_locale, $ref_locale . $repo . 'filteredstrings'); // If Desktop, parse the strings to get components if (in_array($repo, Project::getDesktopRepositories())) { foreach (Project::getComponents($strings[$locale][$repo]) as $component) { $filter_pattern = function ($locale_code) use($component, $repo, $strings) { return array_filter(preg_grep('#^' . $component . '/.*#', array_keys($strings[$locale_code][$repo])), 'strlen'); }; $locale_entities = $filter_pattern($locale); $english_entities = $filter_pattern($ref_locale); // Skip some special cases (mostly optional strings)
/** * @dataProvider getRepoStringsDP */ public function testGetRepoStrings($a, $b, $c) { if (!getenv('TRAVIS')) { $obj = new _Utils(); $this->array($obj->getRepoStrings($a, $b))->contains($c); } }
<?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;