diff --git a/bin/lang/LangList.txt b/bin/lang/LangList.txt new file mode 100644 index 0000000..a6081c7 --- /dev/null +++ b/bin/lang/LangList.txt @@ -0,0 +1,3 @@ +;LangName LangID SubLangID FileName +English(US) 0x09 0x01 english.json +日本語 0x11 0x01 japanese.json diff --git a/bin/lang/ja.json b/bin/lang/ja.json new file mode 100644 index 0000000..e4b7a2a --- /dev/null +++ b/bin/lang/ja.json @@ -0,0 +1,33 @@ +{ +"IDC_STATIC_IO_SETTING":"入出力設定", +"IDC_STATIC_INPUT_PATH":"入力パス\r\n(フォルダでもOK)", +"IDC_BUTTON_INPUT_REF":"参照", +"IDC_STATIC_OUTPUT_PATH":"出力パス", +"IDC_STATIC_TANS_EXT_LIST":"フォルダ内の変換する拡張子", +"IDC_STATIC_OUTPUT_EXT":"出力拡張子", +"IDC_STATIC_OUTPUT_QUALITY":"出力画質設定(1~100)", +"IDC_STATIC_QUALITY_PROCESS_SETTING":"画質・処理設定", +"IDC_STATIC_TRANS_MODE":"変換モード", +"IDC_RADIO_MODE_NOISE_SCALE":"ノイズ除去と拡大", +"IDC_RADIO_MODE_SCALE":"拡大", +"IDC_RADIO_MODE_NOISE":"ノイズ除去", +"IDC_RADIO_AUTO_SCALE":"ノイズ除去(自動判別)と拡大", +"IDC_STATIC_JPEG_NOISE_LEVEL":"JPEGノイズ除去レベル", +"IDC_RADIONOISE_LEVEL1":"レベル1", +"IDC_RADIONOISE_LEVEL2":"レベル2", +"IDC_STATIC_SCALE_RATE":"拡大率", +"IDC_STATIC_MODEL":"モデル", +"IDC_RADIO_MODEL_RGB":"2次元イラスト (RGBモデル)", +"IDC_RADIO_MODEL_PHOTO":"写真・アニメ (Photoモデル)", +"IDC_RADIO_MODEL_Y":"2次元イラスト2 (Yモデル)", +"IDC_CHECK_TTA":"TTAモードを使う", +"IDC_STATIC_PROCESS_SPEED_SETTING":"処理速度設定", +"IDC_STATIC_PROCESSOR":"プロセッサー", +"IDC_RADIO_MODE_GPU":"CUDA(使えたらcuDNN)", +"IDC_RADIO_MODE_CPU":"CPU", +"IDC_STATIC_CROP_SIZE":"分割サイズ", +"IDC_BUTTON_CHECK_CUDNN":"cuDNNチェック", +"IDC_BUTTON_CANCEL":"キャンセル", +"IDC_BUTTON_EXEC":"実行" +"IDC_STATIC_LANG_UI":"UIの言語" +} diff --git a/waifu2x-caffe-gui/Resource.rc b/waifu2x-caffe-gui/Resource.rc index 9602db4..26660dc 100644 Binary files a/waifu2x-caffe-gui/Resource.rc and b/waifu2x-caffe-gui/Resource.rc differ diff --git a/waifu2x-caffe-gui/Source.cpp b/waifu2x-caffe-gui/Source.cpp index b345ff3..feeab2f 100644 --- a/waifu2x-caffe-gui/Source.cpp +++ b/waifu2x-caffe-gui/Source.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ const std::pair DefaultCommonDivisorRange = {90, 140}; const TCHAR * const CropSizeListName = TEXT("crop_size_list.txt"); const TCHAR * const SettingFileName = TEXT("setting.ini"); +const TCHAR * const LangListFileName = TEXT("lang/LangList.txt"); #ifdef UNICODE @@ -114,6 +116,160 @@ std::vector CommonDivisorList(const int N) return list; } +class LangStringList +{ +public: + struct stLangSetting + { + std::wstring LangName; + WORD LangID; + WORD SubLangID; + std::wstring FileName; + + stLangSetting() : LangID(0), SubLangID(0) + {} + }; + +private: + tstring LangBaseDir; + std::vector LangList; + stLangSetting NowLang; + LANGID NowLangID = GetUserDefaultUILanguage(); + +private: + static std::wstring Utf8ToUtf16(const char *src, int src_size = -1) + { + int ret; + + ret = MultiByteToWideChar(CP_UTF8, 0, src, src_size, NULL, 0); + if (ret == 0) + return std::wstring(); + + std::vector buf(ret); + + ret = MultiByteToWideChar(CP_UTF8, 0, src, src_size, buf.data(), ret); + if (ret == 0) + return std::wstring(); + + if (buf.back() != L'\0') + buf.push_back(L'\0'); + + return std::wstring(buf.data()); + } + + static int getNum(const std::string &str) + { + if (str.length() >= 3 && str.substr(0, 2) == "0x") + return strtol(str.c_str(), NULL, 16); + else + return strtol(str.c_str(), NULL, 10); + } + + const stLangSetting& GetLang(const LANGID id) const + { + const auto Primarylang = PRIMARYLANGID(id); + const auto Sublang = SUBLANGID(id); + + int FindPrimary = -1; + int FindSub = -1; + + for (size_t i = 0; i < LangList.size(); i++) + { + const auto &l = LangList[i]; + + if (Primarylang == l.LangID) + { + FindPrimary = (int)i; + if (Primarylang == l.SubLangID) + { + FindSub = (int)i; + break; + } + } + } + + if (FindPrimary >= 0 && FindSub >= 0) // ݂̌Ƀsb^‚‚ + return LangList[FindSub]; + else if (FindPrimary >= 0) // ݂̌ɑ̂‚ + return LangList[FindPrimary]; + + // ‚ȂԍŏɏÂɂ + if (LangList.size() > 0) + return LangList[0]; + + return stLangSetting(); + } + + void ReadLangFile(const stLangSetting &lang) + { + } + +public: + void SetLangBaseDir(const tstring &LangBaseDir) + { + this->LangBaseDir = LangBaseDir; + } + + bool ReadLangList(const tstring &LangListPath) + { + std::ifstream ifs(LangListPath); + if (ifs.fail()) + return false; + + LangList.clear(); + + std::string str; + while (getline(ifs, str)) + { + if (str.length() > 0 && str.front() == ';') + continue; + + boost::char_separator sep("\t"); + boost::tokenizer> tokens(str, sep); + + std::vector list; + for (const auto& t : tokens) + list.emplace_back(t); + + if (list.size() != 4) + continue; + + stLangSetting ls; + ls.LangName = Utf8ToUtf16(list[0].c_str(), list[0].length()); + ls.LangID = getNum(list[1]); + ls.SubLangID = getNum(list[2]); + ls.FileName = Utf8ToUtf16(list[1].c_str(), list[1].length()); + + LangList.push_back(ls); + } + + if (NowLangID != 0) + SetLang(NowLangID); + + return true; + } + + void SetLang(const LANGID id) + { + NowLang = GetLang(id); + NowLangID = id; + } + + void SetLang() + { + SetLang(GetUserDefaultUILanguage()); + } + + const stLangSetting& GetLang() const + { + return NowLang; + } + + std::wstring GetString(const wchar_t *key) const + { + } +}; + // _CAOp class DialogEvent { @@ -163,6 +319,8 @@ private: eModelType modelType; + LangStringList langStringList; + private: template static tstring to_tstring(T val) @@ -964,6 +1122,12 @@ public: exeDir = exePath.branch_path(); } + { + const boost::filesystem::path LangListPath(exeDir / LangListFileName); + langStringList.SetLangBaseDir(getTString(exeDir)); + langStringList.ReadLangList(getTString(LangListPath)); + } + const boost::filesystem::path CropSizeListPath(exeDir / CropSizeListName); std::ifstream ifs(CropSizeListPath.wstring()); if (ifs) @@ -1352,7 +1516,6 @@ public: } }; - int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, diff --git a/waifu2x-caffe-gui/resource.h b/waifu2x-caffe-gui/resource.h index 50ad997..60d7bfb 100644 Binary files a/waifu2x-caffe-gui/resource.h and b/waifu2x-caffe-gui/resource.h differ