20 if ($translations === null) {
24 $lines = explode(
"\n", $string);
29 for (
$n = count($lines);
$i <
$n; ++
$i) {
30 $line = trim($lines[
$i]);
32 $line = self::fixMultiLines($line, $lines, $i);
35 if ($translation->is(
'',
'')) {
36 self::parseHeaders($translation->getTranslation(), $translations);
37 } elseif ($translation->hasOriginal()) {
38 $translations[] = $translation;
45 $splitLine = preg_split(
'/\s+/', $line, 2);
47 $data = isset($splitLine[1]) ? $splitLine[1] :
'';
51 $translation->addComment(
$data);
56 $translation->addExtractedComment(
$data);
61 foreach (array_map(
'trim', explode(
',', trim(
$data))) as $value) {
62 $translation->addFlag($value);
68 foreach (preg_split(
'/\s+/', trim(
$data)) as $value) {
69 if (preg_match(
'/^(.+)(:(\d*))?$/U', $value, $matches)) {
70 $translation->addReference($matches[1], isset($matches[3]) ? $matches[3] : null);
77 $translation = $translation->getClone(self::convertString(
$data));
82 $translation = $translation->getClone(null, self::convertString(
$data));
87 $translation->setPlural(self::convertString(
$data));
93 $translation->setTranslation(self::convertString(
$data));
94 $append =
'Translation';
98 $translation->setPluralTranslation(self::convertString(
$data), 0);
99 $append =
'PluralTranslation';
103 if (strpos(
$key,
'msgstr[') === 0) {
104 $translation->setPluralTranslation(self::convertString(
$data), intval(substr(
$key, 7, -1)) - 1);
105 $append =
'PluralTranslation';
109 if (isset($append)) {
110 if ($append ===
'Context') {
111 $translation = $translation->getClone($translation->getContext().
"\n".self::convertString(
$data));
115 if ($append ===
'Original') {
116 $translation = $translation->getClone(null, $translation->getOriginal().
"\n".self::convertString(
$data));
120 if ($append ===
'PluralTranslation') {
121 $key = count($translation->getPluralTranslation()) - 1;
122 $translation->setPluralTranslation($translation->getPluralTranslation(
$key).
"\n".self::convertString(
$data),
$key);
126 $getMethod =
'get'.$append;
127 $setMethod =
'set'.$append;
128 $translation->$setMethod($translation->$getMethod().
"\n".self::convertString(
$data));
134 if ($translation->hasOriginal() && !in_array($translation, iterator_to_array($translations))) {
135 $translations[] = $translation;
138 return $translations;
151 return (
bool) preg_match(
'/^[\w-]+:/', $line);
162 $headers = explode(
"\n", $headers);
163 $currentHeader = null;
165 foreach ($headers as $line) {
166 $line = self::convertString($line);
168 if (self::isHeaderDefinition($line)) {
169 $header = array_map(
'trim', explode(
':', $line, 2));
173 $entry = $translations->
getHeader($currentHeader);
174 $translations->
setHeader($currentHeader, $entry.$line);
190 for ($j =
$i,
$t = count($lines); $j <
$t; ++$j) {
191 if (substr($line, -1, 1) ==
'"' 192 && isset($lines[$j + 1])
193 && substr(trim($lines[$j + 1]), 0, 1) ==
'"' 195 $line = substr($line, 0, -1).substr(trim($lines[$j + 1]), 1);
218 if ($value[0] ===
'"') {
219 $value = substr($value, 1, -1);
Class to manage a translation string.
getHeader($name)
Returns a header value.
setHeader($name, $value)
Set a new header.
Class to manage a collection of translations.
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file