| 154 | }; |
| 155 | |
| 156 | void POTranslatorPrivate::reload() |
| 157 | { |
| 158 | QFile file(filename); |
| 159 | if(!file.open(QFile::OpenMode::enum_type::ReadOnly | QFile::OpenMode::enum_type::Text)) |
| 160 | { |
| 161 | qDebug() << "Failed to open PO file:" << filename; |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | QByteArray context; |
| 166 | QByteArray disambiguation; |
| 167 | QByteArray id; |
| 168 | QByteArray str; |
| 169 | bool fuzzy = false; |
| 170 | bool nextFuzzy = false; |
| 171 | |
| 172 | enum class Mode |
| 173 | { |
| 174 | First, |
| 175 | MessageContext, |
| 176 | MessageId, |
| 177 | MessageString |
| 178 | } mode = Mode::First; |
| 179 | |
| 180 | int lineNumber = 0; |
| 181 | QHash<QByteArray, POEntry> newMapping; |
| 182 | QHash<QByteArray, POEntry> newMapping_disambiguation; |
| 183 | auto endEntry = [&]() { |
| 184 | auto strStr = QString::fromUtf8(str); |
| 185 | // NOTE: PO header has empty id. We skip it. |
| 186 | if(!id.isEmpty()) |
| 187 | { |
| 188 | auto normalKey = context + "|" + id; |
| 189 | newMapping.insert(normalKey, {strStr, fuzzy}); |
| 190 | if(!disambiguation.isEmpty()) |
| 191 | { |
| 192 | auto disambiguationKey = context + "|" + id + "@" + disambiguation; |
| 193 | newMapping_disambiguation.insert(disambiguationKey, {strStr, fuzzy}); |
| 194 | } |
| 195 | } |
| 196 | context.clear(); |
| 197 | disambiguation.clear(); |
| 198 | id.clear(); |
| 199 | str.clear(); |
| 200 | fuzzy = nextFuzzy; |
| 201 | nextFuzzy = false; |
| 202 | }; |
| 203 | while (!file.atEnd()) |
| 204 | { |
| 205 | ParserArray line = file.readLine(); |
| 206 | if(line.endsWith('\n')) |
| 207 | { |
| 208 | line.resize(line.size() - 1); |
| 209 | } |
| 210 | if(line.endsWith('\r')) |
| 211 | { |
| 212 | line.resize(line.size() - 1); |
| 213 | } |
no test coverage detected