/** * Compare original and translated strings to check abnormal length. * This is used in search views to warn of strings that look much wider * or much shorter than English * * @param string $origin The source string * @param string $translated The string we want to compare to * @return string 'large' or 'small' or false if it doesn't look abnormal */ public static function checkAbnormalStringLength($origin, $translated) { $origin_length = Strings::getLength($origin); $translated_length = Strings::getLength($translated); if ($origin_length != 0 && $translated_length != 0) { $difference = $translated_length / $origin_length * 100; $difference = round($difference); if ($origin_length > 100 && $difference > 150) { // Large translation for a large origin $abnormal_length = 'large'; } elseif ($origin_length > 100 && $difference < 50) { // Small translation for a large origin $abnormal_length = 'small'; } elseif ($origin_length < 100 && $difference > 200 && $translated_length > 100) { // Large translation for a small origin $abnormal_length = 'large'; } elseif ($origin_length < 100 && $difference < 25) { // Small translation for a small origin $abnormal_length = 'small'; } else { // No problems detected $abnormal_length = false; } } else { // Missing origin or translated string $abnormal_length = false; } return $abnormal_length; }
break; case 'mobile': $path[] = $component . '/android/branding'; $path[] = $component . '/android/defines.inc'; $path[] = $component . '/chrome/region.properties'; break; case 'suite': $path[] = $component . '/chrome/browser/region.properties'; $path[] = $component . '/chrome/common/region.properties'; break; case 'toolkit': $path[] = $component . '/content/tests/'; break; } $english_entities = array_filter($english_entities, function ($entity) use($path) { return !Strings::startsWith($entity, $path); }); // Map the values foreach ($english_entities as $entity) { $english_strings[$entity] = $strings[$ref_locale][$repo][$entity]; if (isset($strings[$locale][$repo][$entity])) { $locale_strings[$entity] = $strings[$locale][$repo][$entity]; } } // Get pretty name for component or fallback to folder name $name = in_array($component, array_keys(Project::$components_names)) ? Project::$components_names[$component] : $component; // Store stats and status data for current component and repo. $projects[$repo]['stats'] = $stats; $projects[$repo]['repos'][$component] = Health::getStatus($name, $english_strings, $locale_strings); unset($locale_entities, $english_entities, $english_strings, $locale_strings); }
<?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;
/** * @dataProvider getLevenshteinQualityDP */ public function testLevenshteinQuality($a, $b, $c) { $obj = new _Strings(); $this->float($obj->levenshteinQuality($a, $b))->isNearlyEqualTo($c); }
/** * Return the correct locale code based on context * For example: given "es", returns "es-ES" for Bugzilla, * "es" for Gaia, "es-ES" for other repos. * * @param string $locale Name of the current locale * @param string $context The context we need to use this locale in * @return string Locale code to use in the requested context */ public static function getLocaleInContext($locale, $context) { $locale_mappings = []; // Bugzilla locales $locale_mappings['bugzilla'] = ['es' => 'es-ES', 'gu' => 'gu-IN', 'pa' => 'pa-IN', 'sr-Cyrl' => 'sr', 'sr-Latn' => 'sr']; // Gaia locales $locale_mappings['gaia'] = ['es-AR' => 'es', 'es-CL' => 'es', 'es-ES' => 'es', 'es-MX' => 'es', 'gu-IN' => 'gu', 'pa-IN' => 'pa', 'sr' => 'sr-Cyrl']; // Use Gaia mapping for all Gaia repositories if (Strings::startsWith($context, 'gaia')) { $context = 'gaia'; } // Firefox for iOS $locale_mappings['firefox_ios'] = ['es-AR' => 'es', 'es-ES' => 'es']; // For other contexts use the same as Bugzilla $locale_mappings['other'] = $locale_mappings['bugzilla']; // Fallback to 'other' if context doesn't exist in $locale_mappings $context = array_key_exists($context, $locale_mappings) ? $context : 'other'; $locale = array_key_exists($locale, $locale_mappings[$context]) ? $locale_mappings[$context][$locale] : $locale; return $locale; }