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

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

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

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 convertString ($value)
 Decodes a T_CONSTANT_ENCAPSED_STRING string. 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 fromString ($string, Translations $translations=null, $file='')
 Parses a string and append the translations found in the Translations instance. More...
 

Static Public Attributes

static $functions
 
static $extractComments = false
 

Static Private Member Functions

static unicodeChar ($dec)
 

Additional Inherited Members

- 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 PhpCode.php.

Member Function Documentation

◆ convertString()

static Gettext\Extractors\PhpCode::convertString (   $value)
static

Decodes a T_CONSTANT_ENCAPSED_STRING string.

Parameters
string$value
Returns
string

Definition at line 72 of file PhpCode.php.

73 {
74 if (strpos($value, '\\') === false) {
75 return substr($value, 1, -1);
76 }
77
78 if ($value[0] === "'") {
79 return strtr(substr($value, 1, -1), array('\\\\' => '\\', '\\\'' => '\''));
80 }
81
82 $value = substr($value, 1, -1);
83
84 return preg_replace_callback('/\\\‍(n|r|t|v|e|f|\$|"|\\\|x[0-9A-Fa-f]{1,2}|u{[0-9a-f]{1,6}}|[0-7]{1,3})/', function ($match) {
85 switch ($match[1][0]) {
86 case 'n':
87 return "\n";
88 case 'r':
89 return "\r";
90 case 't':
91 return "\t";
92 case 'v':
93 return "\v";
94 case 'e':
95 return "\e";
96 case 'f':
97 return "\f";
98 case '$':
99 return '$';
100 case '"':
101 return '"';
102 case '\\':
103 return '\\';
104 case 'x':
105 return chr(hexdec(substr($match[0], 1)));
106 case 'u':
107 return self::unicodeChar(hexdec(substr($match[0], 1)));
108 default:
109 return chr(octdec($match[0]));
110 }
111 }, $value);
112 }
static unicodeChar($dec)
Definition: PhpCode.php:115

References Gettext\Extractors\PhpCode\unicodeChar().

Referenced by Gettext\Utils\PhpFunctionsScanner\getFunctions().

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

◆ fromString()

static Gettext\Extractors\PhpCode::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 50 of file PhpCode.php.

51 {
52 if ($translations === null) {
53 $translations = new Translations();
54 }
55
56 $functions = new PhpFunctionsScanner($string);
57 if (self::$extractComments !== false) {
58 $functions->enableCommentsExtraction(self::$extractComments);
59 }
60 $functions->saveGettextFunctions(self::$functions, $translations, $file);
61
62 return $translations;
63 }
Class to manage a collection of translations.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file, and Gettext\Extractors\PhpCode\$functions.

Referenced by Gettext\Extractors\Blade\fromString(), and Gettext\Extractors\Twig\fromString().

+ Here is the caller graph for this function:

◆ unicodeChar()

static Gettext\Extractors\PhpCode::unicodeChar (   $dec)
staticprivate

Definition at line 115 of file PhpCode.php.

116 {
117 if ($dec < 0x80) {
118 return chr($dec);
119 }
120
121 if ($dec < 0x0800) {
122 return chr(0xC0 + ($dec >> 6))
123 .chr(0x80 + ($dec & 0x3f));
124 }
125
126 if ($dec < 0x010000) {
127 return chr(0xE0 + ($dec >> 12))
128 .chr(0x80 + (($dec >> 6) & 0x3f))
129 .chr(0x80 + ($dec & 0x3f));
130 }
131
132 if ($dec < 0x200000) {
133 return chr(0xF0 + ($dec >> 18))
134 .chr(0x80 + (($dec >> 12) & 0x3f))
135 .chr(0x80 + (($dec >> 6) & 0x3f))
136 .chr(0x80 + ($dec & 0x3f));
137 }
138 }

Referenced by Gettext\Extractors\PhpCode\convertString().

+ Here is the caller graph for this function:

Field Documentation

◆ $extractComments

Gettext\Extractors\PhpCode::$extractComments = false
static

Definition at line 45 of file PhpCode.php.

◆ $functions

Gettext\Extractors\PhpCode::$functions
static
Initial value:
= array(
'gettext' => '__',
'__' => '__',
'__e' => '__',
'ngettext' => 'n__',
'n__' => 'n__',
'n__e' => 'n__',
'pgettext' => 'p__',
'p__' => 'p__',
'p__e' => 'p__',
'dgettext' => 'd__',
'd__' => 'd__',
'd__e' => 'd__',
'dpgettext' => 'dp__',
'dp__' => 'dp__',
'dp__e' => 'dp__',
'npgettext' => 'np__',
'np__' => 'np__',
'np__e' => 'np__',
'dnpgettext' => 'dnp__',
'dnp__' => 'dnp__',
'dnp__e' => 'dnp__',
)

Definition at line 13 of file PhpCode.php.

Referenced by Gettext\Extractors\PhpCode\fromString(), and Gettext\Extractors\Twig\fromString().


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