'', 'Report-Msgid-Bugs-To' => '', 'POT-Creation-Date' => '', 'PO-Revision-Date' => '', 'Last-Translator' => '', 'Language-Team' => '', 'Content-Type' => '', 'Content-Transfer-Encoding' => '', 'Plural-Forms' => '', ]; public static function load($file, $context = null) { $pattern = '/(msgctxt\s+"(.*?(? $message) { $separatorPosition = strpos($id, chr(4)); if ($separatorPosition !== false) { $content .= 'msgctxt "' . substr($id, 0, $separatorPosition) . "\"\n"; $id = substr($id, $separatorPosition + 1); } $content .= 'msgid "' . self::encode($id) . "\"\n"; $lines = preg_split('/\r?\n/', $message); if (count($lines) > 1) { $content .= 'msgstr ""' . "\n"; foreach ($lines as $line) { $line = trim($line); if ($line) { $content .= '"' . self::encode($line) . '\n"' . "\n"; } } $content .= "\n"; } else { $content .= 'msgstr "' . self::encode($message) . "\"\n\n"; } } return file_put_contents($file, $content); } protected static function encode($string) { return str_replace(['"', "\n", "\t", "\r"], ['\\"', '\\n', '\\t', '\\r'], $string); } protected static function decode($string) { $string = preg_replace( ['/"\s+"/', '/\\\\n/', '/\\\\r/', '/\\\\t/', '/\\\\"/'], ['', "\n", "\r", "\t", '"'], $string ); return substr(rtrim($string), 1, -1); } }