private function FileToArray($strFile, $strLocale, $blnIncludeFileLine = false) { $arrTexts = array(); $hndFile = fopen($strFile, 'r'); if (!$hndFile) { NarroLogger::LogError(sprintf('Cannot open input file "%s" for reading.', $strFile)); return false; } $intTotalToProcess = NarroUtils::CountFileLines($strFile); $intProcessedSoFar = 0; /** * read the template file line by line */ while (!feof($hndFile)) { $strFileLine = fgets($hndFile); $intProcessedSoFar++; if ($strFileLine == '') { // NarroLogger::LogDebug(sprintf('Skipping empty line from "%s"', $strFileLine)); continue; } /** * OpenOffice uses tab separated values */ $arrColumn = explode("\t", $strFileLine); if (count($arrColumn) != 15) { NarroLogger::LogError(sprintf('Skipping line "%s" from "%s" because it does not split into 15 fields by tab', $strFileLine, $strFile)); continue; } $strLangCode = $arrColumn[9]; if ($strLangCode == 1) { $strLangCode = NarroLanguage::SOURCE_LANGUAGE_CODE; } if ($strLocale == trim($strLangCode)) { $strContext = ''; /** * positions 8, 9 and 10 contain a number, the language code and the text/translation * positions 1 and 2 contain path info * position 3 contains a number * position 14 contains a date */ foreach (array(3, 4, 5, 6, 7, 11, 12, 13) as $intPos) { if (trim($arrColumn[$intPos]) != '') { $strContext .= $arrColumn[$intPos] . "\n"; } } $strContext = trim($strContext); $strText = $arrColumn[10]; $strTextAccKey = null; $strTextAccKeyPrefix = null; if (strstr($strText, '~') && preg_match('/~(\\w)/', $strText, $arrTextAccMatches)) { $strTextAccKey = $arrTextAccMatches[1]; $strText = mb_ereg_replace('~' . $strTextAccKey, $strTextAccKey, $strText); $strTextAccKeyPrefix = '~'; } elseif (strstr($strText, '&') && preg_match('/&(\\w)/', $strText, $arrTextAccMatches)) { $strTextAccKey = $arrTextAccMatches[1]; $strText = mb_ereg_replace('&' . $strTextAccKey, $strTextAccKey, $strText); $strTextAccKeyPrefix = '&'; } else { $strTextAccKey = null; } if (isset($arrTexts[$strContext])) { $strContext .= "\n" . $intProcessedSoFar; } $arrTexts[$strContext] = array($strText, $strTextAccKey, $strTextAccKeyPrefix, $blnIncludeFileLine ? $strFileLine : ''); } else { // NarroLogger::LogDebug(sprintf('Skipping line "%s" from "%s" because detected language code "%s" does not match the expected one "%s"', $strFileLine, $strFile, $strLangCode, $strLocale)); } } fclose($hndFile); return $arrTexts; }