| 265 | } |
| 266 | |
| 267 | bool Translation::ParseLanguageFiles(std::string_view lang_id) |
| 268 | { |
| 269 | FilesystemView language_tree; |
| 270 | |
| 271 | // Create the directory tree (for lookups). |
| 272 | if (!lang_id.empty()) { |
| 273 | language_tree = GetRootTree().Subtree(lang_id); |
| 274 | if (!language_tree) { |
| 275 | Output::Warning("Translation for '{}' does not appear to exist", lang_id); |
| 276 | return false; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | // Clear the old translation |
| 281 | ClearTranslationLookups(); |
| 282 | |
| 283 | // For default, this is all we need. |
| 284 | if (!language_tree) { |
| 285 | current_language = {}; |
| 286 | return true; |
| 287 | } |
| 288 | |
| 289 | // Scan for files in the directory and parse them. |
| 290 | for (const auto& tr_name : *language_tree.ListDirectory()) { |
| 291 | if (tr_name.second.type != DirectoryTree::FileType::Regular) { |
| 292 | continue; |
| 293 | } |
| 294 | |
| 295 | if (tr_name.first == TRFILE_RPG_RT_LDB) { |
| 296 | sys = std::make_unique<Dictionary>(); |
| 297 | auto is = language_tree.OpenInputStream(tr_name.second.name); |
| 298 | if (is) { |
| 299 | ParsePoFile(std::move(is), *sys); |
| 300 | } |
| 301 | } else if (tr_name.first == TRFILE_RPG_RT_BATTLE) { |
| 302 | battle = std::make_unique<Dictionary>(); |
| 303 | auto is = language_tree.OpenInputStream(tr_name.second.name); |
| 304 | if (is) { |
| 305 | ParsePoFile(std::move(is), *battle); |
| 306 | } |
| 307 | } else if (tr_name.first == TRFILE_RPG_RT_COMMON) { |
| 308 | common = std::make_unique<Dictionary>(); |
| 309 | auto is = language_tree.OpenInputStream(tr_name.second.name); |
| 310 | if (is) { |
| 311 | ParsePoFile(std::move(is), *common); |
| 312 | } |
| 313 | } else if (tr_name.first == TRFILE_RPG_RT_LMT) { |
| 314 | mapnames = std::make_unique<Dictionary>(); |
| 315 | auto is = language_tree.OpenInputStream(tr_name.second.name); |
| 316 | if (is) { |
| 317 | ParsePoFile(std::move(is), *mapnames); |
| 318 | } |
| 319 | } else if (EndsWith(tr_name.first, ".po")) { |
| 320 | // This will fail in the web player but is intentional |
| 321 | // The fetching happens on map load instead |
| 322 | // Still parsing all files locally to get syntax errors early |
| 323 | auto is = language_tree.OpenInputStream(tr_name.second.name); |
| 324 | if (is) { |
nothing calls this directly
no test coverage detected