ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Gettext\Extractors\Twig Class Reference

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

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

Static Public Member Functions

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 addExtension ($extension)
 Initialise Twig if it isn't already, and add a given Twig extension. More...
 
- Static Public Member Functions inherited from Gettext\Extractors\Extractor
static fromFile ($file, Translations $translations=null)
 Extract the translations from a file. More...
 
- Static Public Member Functions inherited from Gettext\Extractors\ExtractorInterface
static fromFile ($file, Translations $translations=null)
 Extract the translations from a file. More...
 

Static Protected Member Functions

static checkHasExtensionByClassName ($className)
 Checks if a given Twig extension is already registered or not. 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...
 

Static Protected Attributes

static $twig
 

Detailed Description

Class to get gettext strings from twig files returning arrays.

Definition at line 12 of file Twig.php.

Member Function Documentation

◆ addExtension()

static Gettext\Extractors\Twig::addExtension (   $extension)
static

Initialise Twig if it isn't already, and add a given Twig extension.

This must be called before calling fromString().

Parameters
mixed$extensionAlready initialised extension to add

Definition at line 44 of file Twig.php.

45  {
46  // initialise twig
47  if (!isset(self::$twig)) {
48  $twigCompiler = new Twig_Loader_String();
49 
50  self::$twig = new Twig_Environment($twigCompiler);
51  }
52 
53  if (!self::checkHasExtensionByClassName($extension)) {
54  self::$twig->addExtension(new $extension());
55  }
56  }
Stores the Twig configuration.
Definition: Environment.php:17

◆ checkHasExtensionByClassName()

static Gettext\Extractors\Twig::checkHasExtensionByClassName (   $className)
staticprotected

Checks if a given Twig extension is already registered or not.

Parameters
stringName of Twig extension to check
Returns
bool Whether it has been registered already or not

Definition at line 65 of file Twig.php.

66  {
67  foreach (self::$twig->getExtensions() as $extension) {
68  if ($className == get_class($extension)) {
69  return true;
70  }
71  }
72 
73  return false;
74  }

◆ fromString()

static Gettext\Extractors\Twig::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.

Definition at line 24 of file Twig.php.

References $file, Gettext\Extractors\PhpCode\$functions, and Gettext\Extractors\PhpCode\fromString().

25  {
26  self::addExtension('Twig_Extensions_Extension_I18n');
27 
28  $string = self::$twig->compileSource($string);
29 
30  // add default global php gettext functions
31  PhpCode::$functions['gettext'] = '__';
32  PhpCode::$functions['ngettext'] = '__';
33  PhpCode::$functions['_'] = '__';
34 
35  return PhpCode::fromString($string, $translations, $file);
36  }
static fromString($string, Translations $translations=null, $file='')
{Parses a string and append the translations found in the Translations instance.The file path to inse...
Definition: PhpCode.php:50
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

Field Documentation

◆ $twig

Gettext\Extractors\Twig::$twig
staticprotected

Definition at line 19 of file Twig.php.


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