ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Gettext\Extractors\PhpArray Class Reference

Class to get gettext strings from php files returning arrays. More...

+ Inheritance diagram for Gettext\Extractors\PhpArray:
+ Collaboration diagram for Gettext\Extractors\PhpArray:

Static Public Member Functions

static fromFile ($file, Translations $translations=null)
 Extract the translations from a file. More...
 
static fromString ($string, Translations $translations=null, $file='')
 {Parses a string and append the translations found in the Translations instance.
Parameters
string$string
Translations | null$translations
string$fileThe file path to insert the reference
Returns
Translations
} More...
 
static handleArray (array $content, Translations $translations)
 Handle an array of translations and append to the Translations instance. More...
 
static fromFile ($file, Translations $translations=null)
 Extract the translations from a file. More...
 
static fromFile ($file, Translations $translations=null)
 Extract the translations from a file. More...
 
static fromString ($string, Translations $translations=null, $file='')
 Parses a string and append the translations found in the Translations instance. More...
 

Static Protected Member Functions

static insertTranslation (Translations $translations, $key, $message)
 Extract and insert a new translation. More...
 
- Static Protected Member Functions inherited from Gettext\Extractors\Extractor
static getFiles ($file)
 Checks and returns all files. More...
 
static readFile ($file)
 Reads and returns the content of a file. More...
 

Detailed Description

Class to get gettext strings from php files returning arrays.

Definition at line 11 of file PhpArray.php.

Member Function Documentation

◆ fromFile()

static Gettext\Extractors\PhpArray::fromFile (   $file,
Translations  $translations = null 
)
static

Extract the translations from a file.

Parameters
array | string$fileA path of a file or files
null | Translations$translationsThe translations instance to append the new translations.
Returns
Translations

Reimplemented from Gettext\Extractors\Extractor.

Definition at line 21 of file PhpArray.php.

22 {
23 if ($translations === null) {
24 $translations = new Translations();
25 }
26
27 foreach (self::getFiles($file) as $file) {
28 self::handleArray(include($file), $translations);
29 }
30
31 return $translations;
32 }
static handleArray(array $content, Translations $translations)
Handle an array of translations and append to the Translations instance.
Definition: PhpArray.php:48

References Gettext\Extractors\PhpArray\handleArray().

+ Here is the call graph for this function:

◆ fromString()

static Gettext\Extractors\PhpArray::fromString (   $string,
Translations  $translations = null,
  $file = '' 
)
static

{Parses a string and append the translations found in the Translations instance.

Parameters
string$string
Translations | null$translations
string$fileThe file path to insert the reference
Returns
Translations
}

Implements Gettext\Extractors\ExtractorInterface.

Reimplemented in Gettext\Extractors\Jed.

Definition at line 37 of file PhpArray.php.

38 {
39 throw new Exception('PhpArray::fromString() cannot be called. Use PhpArray::fromFile()');
40 }

◆ handleArray()

static Gettext\Extractors\PhpArray::handleArray ( array  $content,
Translations  $translations 
)
static

Handle an array of translations and append to the Translations instance.

Parameters
array$content
Translations$translations

Definition at line 48 of file PhpArray.php.

49 {
50 $content = current($content);
51
52 $translations_info = isset($content['']) ? $content[''] : null;
53 unset($content['']);
54
55 if (isset($translations_info['domain'])) {
56 $translations->setDomain($translations_info['domain']);
57 }
58
59 foreach ($content as $key => $message) {
60 static::insertTranslation($translations, $key, $message);
61 }
62 }
$key
Definition: croninfo.php:18
catch(Exception $e) $message

References $key, $message, and Gettext\Translations\setDomain().

Referenced by Gettext\Extractors\PhpArray\fromFile(), and Gettext\Extractors\Jed\fromString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertTranslation()

static Gettext\Extractors\PhpArray::insertTranslation ( Translations  $translations,
  $key,
  $message 
)
staticprotected

Extract and insert a new translation.

Parameters
Translations$translations
string$key
string$message

Reimplemented in Gettext\Extractors\Jed.

Definition at line 71 of file PhpArray.php.

72 {
73 $context_glue = '\u0004';
74 $key = explode($context_glue, $key);
75
76 $context = isset($key[1]) ? array_shift($key) : '';
77 $original = array_shift($key);
78 $plural = array_shift($message);
79 $translation = array_shift($message);
80 $plural_translation = array_shift($message);
81
82 $entry = $translations->insert($context, $original, $plural);
83 $entry->setTranslation($translation);
84 $entry->setPluralTranslation($plural_translation);
85 }
$context
Definition: webdav.php:25

References $context, $key, $message, and Gettext\Translations\insert().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: