///////////////////////////////////////////////////////////////////////////////////////// // NameDecoder::NameDecoder //! Create decoder from string id //! //! \param[in] id - Name/description resource id ///////////////////////////////////////////////////////////////////////////////////////// NameDecoder(resource_t id) { auto text = StringResource(id).c_str<encoding>(); // [NAME/DESCRIPTION] Extract name & description if (text.contains(LineFeed)) { int32_t sep = text.find(LineFeed); // Assign description and truncate name Name.assign(text.begin(), text.begin()+(sep+1)); Description.assign(text.begin()+(sep+1), text.end()); } // [NAME] Leave description blank else Name = text; }
XLIFFFile* XLIFFFile::Parse(const string& filename) { XLIFFFile* result = new XLIFFFile(); XMLNode* root = NodeHandler::ParseFile(filename, XMLNode::PRETTY); if (root == NULL) { return NULL; } // <file> vector<XMLNode*> files = root->GetElementsByName(XLIFF_XMLNS, "file"); for (size_t i=0; i<files.size(); i++) { XMLNode* file = files[i]; string datatype = file->GetAttribute("", "datatype", ""); string originalFile = file->GetAttribute("", "original", ""); Configuration sourceConfig; sourceConfig.locale = file->GetAttribute("", "source-language", ""); result->m_sourceConfig = sourceConfig; Configuration targetConfig; targetConfig.locale = file->GetAttribute("", "target-language", ""); result->m_targetConfig = targetConfig; result->m_currentVersion = file->GetAttribute("", "build-num", ""); result->m_oldVersion = "old"; // <body> XMLNode* body = get_unique_node(file, XLIFF_XMLNS, "body", true); if (body == NULL) continue; // <trans-unit> vector<XMLNode*> transUnits = body->GetElementsByName(XLIFF_XMLNS, "trans-unit"); for (size_t j=0; j<transUnits.size(); j++) { XMLNode* transUnit = transUnits[j]; string rawID = transUnit->GetAttribute("", "id", ""); if (rawID == "") { transUnit->Position().Error("<trans-unit> tag requires an id"); continue; } string id; int index; if (!StringResource::ParseTypedID(rawID, &id, &index)) { transUnit->Position().Error("<trans-unit> has invalid id '%s'\n", rawID.c_str()); continue; } // <source> XMLNode* source = get_unique_node(transUnit, XLIFF_XMLNS, "source", false); if (source != NULL) { XMLNode* node = source->Clone(); node->SetPrettyRecursive(XMLNode::EXACT); result->AddStringResource(StringResource(source->Position(), originalFile, sourceConfig, id, index, node, CURRENT_VERSION, result->m_currentVersion)); } // <target> XMLNode* target = get_unique_node(transUnit, XLIFF_XMLNS, "target", false); if (target != NULL) { XMLNode* node = target->Clone(); node->SetPrettyRecursive(XMLNode::EXACT); result->AddStringResource(StringResource(target->Position(), originalFile, targetConfig, id, index, node, CURRENT_VERSION, result->m_currentVersion)); } // <alt-trans> XMLNode* altTrans = get_unique_node(transUnit, XLIFF_XMLNS, "alt-trans", false); if (altTrans != NULL) { // <source> XMLNode* altSource = get_unique_node(altTrans, XLIFF_XMLNS, "source", false); if (altSource != NULL) { XMLNode* node = altSource->Clone(); node->SetPrettyRecursive(XMLNode::EXACT); result->AddStringResource(StringResource(altSource->Position(), originalFile, sourceConfig, id, index, node, OLD_VERSION, result->m_oldVersion)); } // <target> XMLNode* altTarget = get_unique_node(altTrans, XLIFF_XMLNS, "target", false); if (altTarget != NULL) { XMLNode* node = altTarget->Clone(); node->SetPrettyRecursive(XMLNode::EXACT); result->AddStringResource(StringResource(altTarget->Position(), originalFile, targetConfig, id, index, node, OLD_VERSION, result->m_oldVersion)); } } } } delete root; return result; }