public function ImportFile($strTemplate, $strTranslatedFile = null) { // No need to check equals for gettext $this->blnCheckEqual = false; $arrTemplateFile = $this->getFieldGroups($strTemplate); $arrTranslatedFile = $this->getFieldGroups($strTranslatedFile); $intTotalContexts = count($arrTemplateFile); $intCurrentContext = 0; foreach ($arrTemplateFile as $strIndex => $arrTemplateFields) { $intCurrentContext++; NarroProgress::SetProgressPerFile($intCurrentContext / $intTotalContexts * 100, $this->objProject->ProjectId, 'import'); /** * ignore po header */ if ($arrTemplateFields['MsgId'] === '') { continue; } if (isset($arrTranslatedFile[$strIndex]['MsgStr']) && $arrTranslatedFile[$strIndex]['MsgStr'] != '' && isset($arrTranslatedFile[$strIndex]['MsgId']) && $arrTranslatedFile[$strIndex]['MsgId'] == $arrTemplateFields['MsgId']) { $arrTranslatedFile[$strIndex]['MsgStr'] = str_replace('\\"', '"', $arrTranslatedFile[$strIndex]['MsgStr']); } else { $arrTranslatedFile[$strIndex]['MsgStr'] = null; } if (strstr($arrTranslatedFile[$strIndex]['Flag'], 'fuzzy')) { /** * if the string is marked fuzzy, don't import the translation and delete fuzzy flag */ $arrTranslatedFile[$strIndex]['MsgStr'] = ''; } for ($intPluralId = 0; $intPluralId < $this->objTargetLanguage->Plurals; $intPluralId++) { if (strstr($arrTranslatedFile[$strIndex]['Flag'], 'fuzzy')) { /** * if the string is marked fuzzy, don't import the translation and delete fuzzy flag */ $arrTranslatedFile[$strIndex]['MsgStr' . $intPluralId] = ''; $arrTranslatedFile[$strIndex]['Flag'] = str_replace(', fuzzy', '', $arrTranslatedFile[$strIndex]['Flag']); /** * if no other flags are found, just empty the variable */ if (strlen(trim($arrTranslatedFile[$strIndex]['Flag'])) < 4) { $arrTranslatedFile[$strIndex]['Flag'] = null; } } else { if (isset($arrTranslatedFile[$strIndex]['MsgStr' . $intPluralId]) && $arrTranslatedFile[$strIndex]['MsgStr' . $intPluralId] != '' && isset($arrTranslatedFile[$strIndex]['MsgPluralId']) && $arrTranslatedFile[$strIndex]['MsgPluralId'] == $arrTemplateFields['MsgPluralId']) { $arrTranslatedFile[$strIndex]['MsgStr' . $intPluralId] = str_replace('\\"', '"', $arrTranslatedFile[$strIndex]['MsgStr' . $intPluralId]); } else { $arrTranslatedFile[$strIndex]['MsgStr' . $intPluralId] = ''; } } } $arrTranslatedFile[$strIndex]['Flag'] = str_replace(', fuzzy', '', $arrTranslatedFile[$strIndex]['Flag']); /** * if no other flags are found, just empty the variable */ if (strlen(trim($arrTranslatedFile[$strIndex]['Flag'])) < 4) { $arrTranslatedFile[$strIndex]['Flag'] = null; } /** * if it's not a plural, just add msgid and msgstr */ if (is_null($arrTemplateFields['MsgPluralId'])) { $this->AddTranslation($this->stripAccessKey($arrTemplateFields['MsgId']), $this->getAccessKey($arrTemplateFields['MsgId']), $this->stripAccessKey($arrTranslatedFile[$strIndex]['MsgStr']), $this->getAccessKey($arrTranslatedFile[$strIndex]['MsgStr']), $arrTemplateFields['Context'], $arrTemplateFields['ContextComment']); } else { /** * if it's a plural, add the pluralid with all the msgstr's available * the first one is added with msgid/msgstr[0] (this is the singular) * the next ones are added with plural id, so in fact they will be tied to the same text */ if (!is_null($arrTemplateFields['MsgStr0'])) { $this->AddTranslation($this->stripAccessKey($arrTemplateFields['MsgId']), $this->getAccessKey($arrTemplateFields['MsgId']), $this->stripAccessKey($arrTranslatedFile[$strIndex]['MsgStr0']), $this->getAccessKey($arrTranslatedFile[$strIndex]['MsgStr0']), $arrTemplateFields['Context'] . "\nThis text has plurals.", $arrTemplateFields['ContextComment']); } for ($intPluralId = 1; $intPluralId < $this->objTargetLanguage->Plurals; $intPluralId++) { if (!is_null($arrTranslatedFile[$strIndex]['MsgStr' . $intPluralId])) { $this->AddTranslation($this->stripAccessKey($arrTemplateFields['MsgPluralId']), $this->getAccessKey($arrTemplateFields['MsgPluralId']), $arrTranslatedFile[$strIndex]['MsgStr' . $intPluralId], $this->getAccessKey($arrTranslatedFile[$strIndex]['MsgStr' . $intPluralId]), $arrTemplateFields['Context'] . "\nThis is plural form {$intPluralId} for the text \"" . $arrTemplateFields['MsgId'] . "\".", $arrTemplateFields['ContextComment']); } } } } }