| 159 | |
| 160 | |
| 161 | void Translation::SelectLanguage(std::string_view lang_id) |
| 162 | { |
| 163 | // Try to read in our language files. |
| 164 | Output::Debug("Changing language to: '{}'", (!lang_id.empty() ? lang_id : "<Default>")); |
| 165 | |
| 166 | AsyncHandler::ClearRequests(); |
| 167 | |
| 168 | if (!lang_id.empty()) { |
| 169 | auto root = GetRootTree(); |
| 170 | if (!root) { |
| 171 | Output::Warning("Cannot load translation. 'Language' folder does not exist"); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | FilesystemView language_tree = root.Subtree(lang_id); |
| 176 | if (language_tree) { |
| 177 | auto files = Utils::MakeSvArray(TRFILE_RPG_RT_LDB, TRFILE_RPG_RT_BATTLE, TRFILE_RPG_RT_COMMON, TRFILE_RPG_RT_LMT, "Font/Font", "Font/Font2"); |
| 178 | request_counter = static_cast<int>(files.size()); |
| 179 | for (auto s: files) { |
| 180 | FileRequestAsync* request = AsyncHandler::RequestFile(language_tree.GetFullPath(), s); |
| 181 | request->SetImportantFile(true); |
| 182 | requests.emplace_back(request->Bind(&Translation::SelectLanguageAsync, this, lang_id)); |
| 183 | request->Start(); |
| 184 | } |
| 185 | } else { |
| 186 | Output::Warning("Translation for '{}' does not appear to exist", lang_id); |
| 187 | } |
| 188 | } else { |
| 189 | // Default language, no request needed |
| 190 | request_counter = 1; |
| 191 | SelectLanguageAsync(nullptr, lang_id); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | void Translation::SelectLanguageAsync(FileRequestResult*, std::string_view lang_id) { |
| 196 | --request_counter; |
no test coverage detected