/** * {@inheritDoc} */ public static function fromString($string, Translations $translations = null, $file = '') { if ($translations === null) { $translations = new Translations(); } $functions = new PhpFunctionsScanner($string); $functions->saveGettextFunctions(self::$functions, $translations, $file); }
/** * {@inheritdoc} */ public static function fromString($string, Translations $translations, array $options = []) { $options += static::$options; $functions = new PhpFunctionsScanner($string); if ($options['extractComments'] !== false) { $functions->enableCommentsExtraction($options['extractComments']); } $functions->saveGettextFunctions($translations, $options); }
/** * {@inheritdoc} */ public static function fromString($string, Translations $translations = null, $file = '') { if ($translations === null) { $translations = new Translations(); } $functions = new PhpFunctionsScanner($string); if (self::$extractComments !== false) { $functions->enableCommentsExtraction(self::$extractComments); } $functions->saveGettextFunctions(self::$functions, $translations, $file); return $translations; }
/** * Find translations in the source code. * The parser if looking for the *translate* or * translateContext* methods. */ protected function findTranslations() { $php_files = array(); foreach ($this->source_code_paths as $path) { $php_files = array_merge($php_files, $this->glob_recursive($path . '/*.php') ?: array()); } foreach ($php_files as $php_file) { $code = file_get_contents($php_file); $php_scanner = new PhpFunctionsScanner($code); foreach ($php_scanner->getFunctions() as $function) { if ($function[0] == 'translate' || $function[0] == 'translateContext') { $args = $function[2]; if ($args && count($args) > 0) { $msgid = md5($args[0]); if (!isset($this->translations_found[$msgid])) { $this->translations_found[$msgid] = array('text' => $args[0], 'references' => array()); } $this->translations_found[$msgid]['references'][] = substr($php_file, strlen(WT_ROOT)) . ':' . $function[1]; } } } } }