MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / reload

Method reload

launcher/translations/POTranslator.cpp:156–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154};
155
156void 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 }

Callers 1

POTranslatorMethod · 0.45

Calls 9

openMethod · 0.80
isEmptyMethod · 0.80
insertMethod · 0.80
resizeMethod · 0.80
chompStringMethod · 0.80
chompMethod · 0.80
clearMethod · 0.45
sizeMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected