Translator初步

This commit is contained in:
EmsiaetKadosh
2025-03-21 11:06:51 +08:00
parent 28cc82bcd7
commit 20f4ef1cee
11 changed files with 85 additions and 47 deletions
+19 -6
View File
@@ -61,7 +61,7 @@ void Font::drawDirect(const RenderableString::StringConfig& config, const int x,
}
void Font::clear() const {
for (const auto& fnt : fonts | std::views::values) renderer.deleteObject(fnt);
for (const auto& [_, fnt] : fonts) renderer.deleteObject(fnt);
fonts.clear();
}
@@ -103,7 +103,7 @@ void Font::drawCenter(const RenderableString& text, int x, int y, const int w, c
}
int Font::getWidth(const RenderableString::StringConfig& config) const {
HFONT font = tryCreate(config);
HFONT const font = tryCreate(config);
RECT rect{};
SelectObject(renderer.assistDC, font);
DrawTextW(renderer.assistDC, config.text.c_str(), static_cast<int>(config.text.length()), &rect, DT_CALCRECT | DT_NOCLIP | DT_SINGLELINE);
@@ -129,10 +129,23 @@ void TranslatableText::refreshText() const noexcept {
void languageMakeChinese(Language& lang) {
Logger.debug(L"languageMakeChinese called");
Map<std::wstring, LiteralText>& map = lang.translateTable;
map.emplace(String(L"hbp.title"), TranslatedText(L"高血压"));
map.emplace(String(L"hbp.confirm.confirm"), TranslatedText(L"确认"));
map.emplace(String(L"hbp.confirm.cancel"), TranslatedText(L"取消"));
Map<std::wstring, TranslatedText>& map = lang.translateTable;
map.emplace(L"hbp.title", TranslatedText(L"高血压"));
map.emplace(L"hbp.confirm.confirm", TranslatedText(L"确认"));
map.emplace(L"hbp.confirm.cancel", TranslatedText(L"取消"));
map.emplace(L"hbp.caption.close", TranslatedText(L"\\#ffee0000关闭窗口"));
map.emplace(L"hbp.caption.maximize", TranslatedText(L"\\#ff4488ee最大化窗口"));
map.emplace(L"hbp.caption.restore", TranslatedText(L"\\#ff4488ee复原窗口"));
map.emplace(L"hbp.caption.minimize", TranslatedText(L"\\#ffeeaaaa最小化窗口"));
map.emplace(L"hbp.float.freshCanvas", TranslatedText(L"\\.ff4488aa\\#ff000000右键以刷新窗口绘制"));
map.emplace(L"hbp.button.exit", TranslatedText(L"\\#ff44ee66退出"));
map.emplace(L"hbp.float.exit", TranslatedText(L"\\#ff44ee66退出游戏"));
map.emplace(L"hbp.confirming.exit", TranslatedText(L"是否\\#ff44ee66退出游戏\\r"));
map.emplace(L"hbp.button.settings", TranslatedText(L"\\#ff4488aa设置"));
map.emplace(L"hbp.float.settings", TranslatedText(L"\\#ff4488aa设置"));
map.emplace(L"hbp.button.start", TranslatedText(L"\\#ffee0000开始"));
map.emplace(L"hbp.float.start", TranslatedText(L"\\#ffee0000开始游戏"));
map.emplace(L"hbp.confirming.start", TranslatedText(L"是否\\#ffee0000退出游戏\\r"));
}
inline Translator translator = Translator();