|
Revision 28843, 2.3 kB
(checked in by fabien, 3 years ago)
|
[1.3, 1.4] fixed i18n extractor keeps acumulating texts when more than 1 Heredoc string is used (closes #8166 - patch from gonrial)
|
- Property svn:mime-type set to
text/x-php
- Property svn:eol-style set to
native
- Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
class sfI18nPhpExtractor implements sfI18nExtractorInterface |
|---|
| 18 |
{ |
|---|
| 19 |
|
|---|
| 20 |
* Extract i18n strings for the given content. |
|---|
| 21 |
* |
|---|
| 22 |
* @param string $content The content |
|---|
| 23 |
* |
|---|
| 24 |
* @return array An array of i18n strings |
|---|
| 25 |
*/ |
|---|
| 26 |
public function extract($content) |
|---|
| 27 |
{ |
|---|
| 28 |
$tokens = token_get_all($content); |
|---|
| 29 |
|
|---|
| 30 |
$strings = array(); |
|---|
| 31 |
$i18n_function = 0; |
|---|
| 32 |
$line = 0; |
|---|
| 33 |
$heredoc = false; |
|---|
| 34 |
$buffer = ''; |
|---|
| 35 |
foreach ($tokens as $token) |
|---|
| 36 |
{ |
|---|
| 37 |
if (is_string($token)) |
|---|
| 38 |
{ |
|---|
| 39 |
switch ($token) |
|---|
| 40 |
{ |
|---|
| 41 |
case '(': |
|---|
| 42 |
if (1 == $i18n_function) |
|---|
| 43 |
{ |
|---|
| 44 |
$i18n_function = 2; |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
break; |
|---|
| 48 |
default: |
|---|
| 49 |
$i18n_function = 0; |
|---|
| 50 |
} |
|---|
| 51 |
} |
|---|
| 52 |
else |
|---|
| 53 |
{ |
|---|
| 54 |
list($id, $text) = $token; |
|---|
| 55 |
|
|---|
| 56 |
switch ($id) |
|---|
| 57 |
{ |
|---|
| 58 |
case T_STRING: |
|---|
| 59 |
if ($heredoc && 2 == $i18n_function) |
|---|
| 60 |
{ |
|---|
| 61 |
$buffer .= $text; |
|---|
| 62 |
} |
|---|
| 63 |
else |
|---|
| 64 |
{ |
|---|
| 65 |
$i18n_function = ('__' == $text || 'format_number_choice' == $text) ? 1 : 0; |
|---|
| 66 |
} |
|---|
| 67 |
break; |
|---|
| 68 |
case T_WHITESPACE: |
|---|
| 69 |
break; |
|---|
| 70 |
case T_START_HEREDOC: |
|---|
| 71 |
$heredoc = true; |
|---|
| 72 |
break; |
|---|
| 73 |
case T_END_HEREDOC: |
|---|
| 74 |
$heredoc = false; |
|---|
| 75 |
if ($buffer) |
|---|
| 76 |
{ |
|---|
| 77 |
$strings[] = $buffer; |
|---|
| 78 |
$buffer = ''; |
|---|
| 79 |
} |
|---|
| 80 |
$i18n_function = 0; |
|---|
| 81 |
break; |
|---|
| 82 |
case T_CONSTANT_ENCAPSED_STRING: |
|---|
| 83 |
if (2 == $i18n_function) |
|---|
| 84 |
{ |
|---|
| 85 |
$delimiter = $text[0]; |
|---|
| 86 |
$strings[] = str_replace('\\'.$delimiter, $delimiter, substr($text, 1, -1)); |
|---|
| 87 |
} |
|---|
| 88 |
$i18n_function = 0; |
|---|
| 89 |
break; |
|---|
| 90 |
default: |
|---|
| 91 |
if ($heredoc && 2 == $i18n_function) |
|---|
| 92 |
{ |
|---|
| 93 |
$buffer .= $text; |
|---|
| 94 |
} |
|---|
| 95 |
else |
|---|
| 96 |
{ |
|---|
| 97 |
$i18n_function = 0; |
|---|
| 98 |
} |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
return $strings; |
|---|
| 104 |
} |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|