add on_missing handler to the i18n
This commit is contained in:
parent
99a226e09c
commit
a298c00ede
@ -24,6 +24,9 @@ namespace nana
|
|||||||
{
|
{
|
||||||
friend class i18n_eval;
|
friend class i18n_eval;
|
||||||
public:
|
public:
|
||||||
|
/// Sets a handler to handle a msgid which hasn't been translated.
|
||||||
|
static void set_missing(std::function<void(const std::string& msgid_utf8)> handler);
|
||||||
|
|
||||||
void load(const std::string& file);
|
void load(const std::string& file);
|
||||||
void load_utf8(const std::string& file);
|
void load_utf8(const std::string& file);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
std::wstring type;
|
std::wstring type;
|
||||||
ires>>m.name>>type>>type;
|
ires>>m.name>>type>>type;
|
||||||
m.directory = (type == L"Directory");
|
m.directory = (to_utf8(type) == internationalization()("NANA_FILEBOX_DIRECTORY"));
|
||||||
return ires;
|
return ires;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +65,8 @@ namespace nana
|
|||||||
_m_add(tm, item.modified_time.tm_min)<<':';
|
_m_add(tm, item.modified_time.tm_min)<<':';
|
||||||
_m_add(tm, item.modified_time.tm_sec);
|
_m_add(tm, item.modified_time.tm_sec);
|
||||||
|
|
||||||
|
internationalization i18n;
|
||||||
|
|
||||||
ores<<item.name<<tm.str();
|
ores<<item.name<<tm.str();
|
||||||
if(!item.directory)
|
if(!item.directory)
|
||||||
{
|
{
|
||||||
@ -72,12 +74,12 @@ namespace nana
|
|||||||
if(pos != item.name.npos && (pos + 1 < item.name.size()))
|
if(pos != item.name.npos && (pos + 1 < item.name.size()))
|
||||||
ores<<item.name.substr(pos + 1);
|
ores<<item.name.substr(pos + 1);
|
||||||
else
|
else
|
||||||
ores<<L"File";
|
ores<<i18n("NANA_FILEBOX_FILE");
|
||||||
|
|
||||||
ores<<_m_trans(item.bytes);
|
ores<<_m_trans(item.bytes);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ores<<L"Directory";
|
ores << i18n("NANA_FILEBOX_DIRECTORY");
|
||||||
return ores;
|
return ores;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +116,8 @@ namespace nana
|
|||||||
|
|
||||||
return s + ustr[uid];
|
return s + ustr[uid];
|
||||||
}
|
}
|
||||||
ss<<bytes<<" Bytes";
|
internationalization i18n;
|
||||||
|
ss<<bytes<<" "<<i18n("NANA_FILEBOX_BYTES");
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -138,6 +141,7 @@ namespace nana
|
|||||||
filebox_implement(window owner, bool io_read, const std::string& title)
|
filebox_implement(window owner, bool io_read, const std::string& title)
|
||||||
: form(owner, API::make_center(owner, 630, 440)), io_read_(io_read)
|
: form(owner, API::make_center(owner, 630, 440)), io_read_(io_read)
|
||||||
{
|
{
|
||||||
|
internationalization i18n;
|
||||||
path_.create(*this);
|
path_.create(*this);
|
||||||
path_.splitstr("/");
|
path_.splitstr("/");
|
||||||
path_.events().selected.connect_unignorable([this](const arg_categorize<int>&)
|
path_.events().selected.connect_unignorable([this](const arg_categorize<int>&)
|
||||||
@ -157,7 +161,7 @@ namespace nana
|
|||||||
|
|
||||||
filter_.create(*this);
|
filter_.create(*this);
|
||||||
filter_.multi_lines(false);
|
filter_.multi_lines(false);
|
||||||
filter_.tip_string("Filter");
|
filter_.tip_string(i18n("NANA_FILEBOX_FILTER"));
|
||||||
|
|
||||||
filter_.events().key_release.connect_unignorable([this](const arg_keyboard&)
|
filter_.events().key_release.connect_unignorable([this](const arg_keyboard&)
|
||||||
{
|
{
|
||||||
@ -165,23 +169,23 @@ namespace nana
|
|||||||
});
|
});
|
||||||
|
|
||||||
btn_folder_.create(*this);
|
btn_folder_.create(*this);
|
||||||
btn_folder_.caption("&New Folder");
|
btn_folder_.i18n(i18n_eval("NANA_FILEBOX_NEW_FOLDER_SHORTKEY"));
|
||||||
|
|
||||||
btn_folder_.events().click.connect_unignorable([this](const arg_click&)
|
btn_folder_.events().click.connect_unignorable([this](const arg_click&)
|
||||||
{
|
{
|
||||||
form fm(this->handle(), API::make_center(*this, 300, 35));
|
form fm(this->handle(), API::make_center(*this, 300, 35));
|
||||||
fm.caption("Name the new folder");
|
fm.i18n(i18n_eval("NANA_FILEBOX_NEW_FOLDER_CAPTION"));
|
||||||
|
|
||||||
textbox folder(fm, nana::rectangle(5, 5, 160, 25));
|
textbox folder(fm, nana::rectangle(5, 5, 160, 25));
|
||||||
folder.multi_lines(false);
|
folder.multi_lines(false);
|
||||||
|
|
||||||
button btn(fm, nana::rectangle(170, 5, 60, 25));
|
button btn(fm, nana::rectangle(170, 5, 60, 25));
|
||||||
btn.caption("Create");
|
btn.i18n(i18n_eval("NANA_BUTTON_CREATE"));
|
||||||
|
|
||||||
btn.events().click.connect_unignorable(folder_creator(*this, fm, folder));
|
btn.events().click.connect_unignorable(folder_creator(*this, fm, folder));
|
||||||
|
|
||||||
button btn_cancel(fm, nana::rectangle(235, 5, 60, 25));
|
button btn_cancel(fm, nana::rectangle(235, 5, 60, 25));
|
||||||
btn_cancel.caption("Cancel");
|
btn_cancel.i18n(i18n_eval("NANA_BUTTON_CANCEL"));
|
||||||
|
|
||||||
btn_cancel.events().click.connect_unignorable([&fm](const arg_click&)
|
btn_cancel.events().click.connect_unignorable([&fm](const arg_click&)
|
||||||
{
|
{
|
||||||
@ -193,10 +197,10 @@ namespace nana
|
|||||||
tree_.create(*this);
|
tree_.create(*this);
|
||||||
|
|
||||||
ls_file_.create(*this);
|
ls_file_.create(*this);
|
||||||
ls_file_.append_header("Name", 190);
|
ls_file_.append_header(i18n("NANA_FILEBOX_HEADER_NAME"), 190);
|
||||||
ls_file_.append_header("Modified", 145);
|
ls_file_.append_header(i18n("NANA_FILEBOX_HEADER_MODIFIED"), 145);
|
||||||
ls_file_.append_header("Type", 80);
|
ls_file_.append_header(i18n("NANA_FILEBOX_HEADER_TYPE"), 80);
|
||||||
ls_file_.append_header("Size", 70);
|
ls_file_.append_header(i18n("NANA_FILEBOX_HEADER_SIZE"), 70);
|
||||||
|
|
||||||
auto fn_sel_file = [this](const arg_mouse& arg){
|
auto fn_sel_file = [this](const arg_mouse& arg){
|
||||||
_m_sel_file(arg);
|
_m_sel_file(arg);
|
||||||
@ -274,7 +278,7 @@ namespace nana
|
|||||||
});
|
});
|
||||||
|
|
||||||
lb_file_.create(*this);
|
lb_file_.create(*this);
|
||||||
lb_file_.caption("File:");
|
lb_file_.i18n(i18n_eval("NANA_FILEBOX_FILE_COLON"));
|
||||||
|
|
||||||
tb_file_.create(*this);
|
tb_file_.create(*this);
|
||||||
tb_file_.multi_lines(false);
|
tb_file_.multi_lines(false);
|
||||||
@ -290,14 +294,15 @@ namespace nana
|
|||||||
cb_types_.events().selected.connect_unignorable([this](const arg_combox&){ _m_list_fs(); });
|
cb_types_.events().selected.connect_unignorable([this](const arg_combox&){ _m_list_fs(); });
|
||||||
|
|
||||||
btn_ok_.create(*this);
|
btn_ok_.create(*this);
|
||||||
btn_ok_.caption("&OK");
|
btn_ok_.i18n(i18n_eval("NANA_BUTTON_OK_SHORTKEY"));
|
||||||
|
|
||||||
|
|
||||||
btn_ok_.events().click.connect_unignorable([this](const arg_click&)
|
btn_ok_.events().click.connect_unignorable([this](const arg_click&)
|
||||||
{
|
{
|
||||||
_m_ok();
|
_m_ok();
|
||||||
});
|
});
|
||||||
btn_cancel_.create(*this);
|
btn_cancel_.create(*this);
|
||||||
btn_cancel_.caption("&Cancel");
|
btn_cancel_.i18n(i18n_eval("NANA_BUTTON_CANCEL_SHORTKEY"));
|
||||||
|
|
||||||
btn_cancel_.events().click.connect_unignorable([this](const arg_click&)
|
btn_cancel_.events().click.connect_unignorable([this](const arg_click&)
|
||||||
{
|
{
|
||||||
@ -309,7 +314,7 @@ namespace nana
|
|||||||
_m_init_tree();
|
_m_init_tree();
|
||||||
|
|
||||||
if(0 == title.size())
|
if(0 == title.size())
|
||||||
caption(io_read ? "Open" : "Save As");
|
this->i18n(i18n_eval(io_read ? "NANA_FILEBOX_OPEN" : "NANA_FILEBOX_SAVE_AS"));
|
||||||
else
|
else
|
||||||
caption(title);
|
caption(title);
|
||||||
}
|
}
|
||||||
@ -640,11 +645,12 @@ namespace nana
|
|||||||
{
|
{
|
||||||
auto path = tx_path_.caption();
|
auto path = tx_path_.caption();
|
||||||
|
|
||||||
msgbox mb(fm_, "Create Folder");
|
internationalization i18n;
|
||||||
|
msgbox mb(fm_, i18n("NANA_FILEBOX_NEW_FOLDER"));
|
||||||
mb.icon(msgbox::icon_warning);
|
mb.icon(msgbox::icon_warning);
|
||||||
if(0 == path.size() || path[0] == '.' || path[0] == '/')
|
if(0 == path.size() || path[0] == '.' || path[0] == '/')
|
||||||
{
|
{
|
||||||
mb<<L"Please input a valid name for the new folder.";
|
mb << i18n("NANA_FILEBOX_ERROR_INVALID_FOLDER_NAME");
|
||||||
mb();
|
mb();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -657,14 +663,14 @@ namespace nana
|
|||||||
|
|
||||||
if(fst.type() != file_type::not_found && fst.type() != file_type::none)
|
if(fst.type() != file_type::not_found && fst.type() != file_type::none)
|
||||||
{
|
{
|
||||||
mb<<L"The folder is existing, please rename it.";
|
mb<<i18n("NANA_FILEBOX_ERROR_RENAME_FOLDER_BECAUSE_OF_EXISTING");
|
||||||
mb();
|
mb();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(false == fs::create_directory(fspath))
|
if(false == fs::create_directory(fspath))
|
||||||
{
|
{
|
||||||
mb<<L"Failed to create the folder, please rename it.";
|
mb<<i18n("NANA_FILEBOX_ERROR_RENAME_FOLDER_BECAUSE_OF_FAILED_CREATION");
|
||||||
mb();
|
mb();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -741,11 +747,12 @@ namespace nana
|
|||||||
auto file = tb_file_.caption();
|
auto file = tb_file_.caption();
|
||||||
if(file.size())
|
if(file.size())
|
||||||
{
|
{
|
||||||
|
internationalization i18n;
|
||||||
if(file[0] == '.')
|
if(file[0] == '.')
|
||||||
{
|
{
|
||||||
msgbox mb(*this, caption());
|
msgbox mb(*this, caption());
|
||||||
mb.icon(msgbox::icon_warning);
|
mb.icon(msgbox::icon_warning);
|
||||||
mb<<file<<std::endl<<"The filename is invalid.";
|
mb<<file<<std::endl<<i18n("NANA_FILEBOX_ERROR_INVALID_FILENAME");
|
||||||
mb();
|
mb();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -780,7 +787,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
msgbox mb(*this, caption());
|
msgbox mb(*this, caption());
|
||||||
mb.icon(msgbox::icon_information);
|
mb.icon(msgbox::icon_information);
|
||||||
mb<<"The file \""<<tar<<"\"\n is not existing. Please check and retry.";
|
mb << i18n("NANA_FILEBOX_ERROR_NOT_EXISTING_AND_RETRY", tar);
|
||||||
mb();
|
mb();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -792,7 +799,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
msgbox mb(*this, caption(), msgbox::yes_no);
|
msgbox mb(*this, caption(), msgbox::yes_no);
|
||||||
mb.icon(msgbox::icon_question);
|
mb.icon(msgbox::icon_question);
|
||||||
mb<<"The input file is existing, do you want to overwrite it?";
|
mb<<i18n("NANA_FILEBOX_ERROR_QUERY_REWRITE_BECAUSE_OF_EXISTING");
|
||||||
if(msgbox::pick_no == mb())
|
if(msgbox::pick_no == mb())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -61,14 +61,14 @@ namespace nana
|
|||||||
{
|
{
|
||||||
_m_click(arg);
|
_m_click(arg);
|
||||||
});
|
});
|
||||||
yes_.i18n(i18n_eval("OK"));
|
yes_.i18n(i18n_eval("NANA_BUTTON_OK"));
|
||||||
width_pixel += 77;
|
width_pixel += 77;
|
||||||
|
|
||||||
if(msgbox::yes_no == btn || msgbox::yes_no_cancel == btn)
|
if(msgbox::yes_no == btn || msgbox::yes_no_cancel == btn)
|
||||||
{
|
{
|
||||||
yes_.i18n(i18n_eval("Yes"));
|
yes_.i18n(i18n_eval("NANA_BUTTON_YES"));
|
||||||
no_.create(*this);
|
no_.create(*this);
|
||||||
no_.i18n(i18n_eval("No"));
|
no_.i18n(i18n_eval("NANA_BUTTON_NO"));
|
||||||
no_.events().click.connect_unignorable([this](const arg_click& arg)
|
no_.events().click.connect_unignorable([this](const arg_click& arg)
|
||||||
{
|
{
|
||||||
_m_click(arg);
|
_m_click(arg);
|
||||||
@ -79,7 +79,7 @@ namespace nana
|
|||||||
if(msgbox::yes_no_cancel == btn)
|
if(msgbox::yes_no_cancel == btn)
|
||||||
{
|
{
|
||||||
cancel_.create(*this);
|
cancel_.create(*this);
|
||||||
cancel_.i18n(i18n_eval("Cancel"));
|
cancel_.i18n(i18n_eval("NANA_BUTTON_CANCEL"));
|
||||||
cancel_.events().click.connect_unignorable([this](const arg_click& arg)
|
cancel_.events().click.connect_unignorable([this](const arg_click& arg)
|
||||||
{
|
{
|
||||||
_m_click(arg);
|
_m_click(arg);
|
||||||
@ -493,7 +493,7 @@ namespace nana
|
|||||||
auto desc_extent = desc_.measure(470);
|
auto desc_extent = desc_.measure(470);
|
||||||
|
|
||||||
btn_ok_.create(*this);
|
btn_ok_.create(*this);
|
||||||
btn_ok_.i18n(i18n_eval("OK"));
|
btn_ok_.i18n(i18n_eval("NANA_BUTTON_OK"));
|
||||||
btn_ok_.events().click.connect_unignorable([this]{
|
btn_ok_.events().click.connect_unignorable([this]{
|
||||||
|
|
||||||
if (verifier_ && !verifier_(handle()))
|
if (verifier_ && !verifier_(handle()))
|
||||||
@ -504,7 +504,7 @@ namespace nana
|
|||||||
});
|
});
|
||||||
|
|
||||||
btn_cancel_.create(*this);
|
btn_cancel_.create(*this);
|
||||||
btn_cancel_.i18n(i18n_eval("Cancel"));
|
btn_cancel_.i18n(i18n_eval("NANA_BUTTON_CANCEL"));
|
||||||
btn_cancel_.events().click.connect_unignorable([this]{
|
btn_cancel_.events().click.connect_unignorable([this]{
|
||||||
close();
|
close();
|
||||||
});
|
});
|
||||||
@ -1141,7 +1141,7 @@ namespace nana
|
|||||||
impl->path_edit.multi_lines(false);
|
impl->path_edit.multi_lines(false);
|
||||||
|
|
||||||
impl->browse.create(impl->dock);
|
impl->browse.create(impl->dock);
|
||||||
impl->browse.i18n(i18n_eval("Browse"));
|
impl->browse.i18n(i18n_eval("NANA_BUTTON_BROWSE"));
|
||||||
impl->browse.events().click.connect_unignorable([wd, impl](const arg_click&)
|
impl->browse.events().click.connect_unignorable([wd, impl](const arg_click&)
|
||||||
{
|
{
|
||||||
impl->fbox.owner(wd);
|
impl->fbox.owner(wd);
|
||||||
|
@ -151,7 +151,44 @@ namespace nana
|
|||||||
|
|
||||||
struct data
|
struct data
|
||||||
{
|
{
|
||||||
|
std::function<void(const std::string&)> on_missing;
|
||||||
std::unordered_map<std::string, std::string> table;
|
std::unordered_map<std::string, std::string> table;
|
||||||
|
|
||||||
|
data()
|
||||||
|
{
|
||||||
|
//initializes nana's translation
|
||||||
|
table["NANA_BUTTON_OK"] = "OK";
|
||||||
|
table["NANA_BUTTON_OK_SHORTKEY"] = "&OK";
|
||||||
|
table["NANA_BUTTON_YES"] = "Yes";
|
||||||
|
table["NANA_BUTTON_NO"] = "No";
|
||||||
|
table["NANA_BUTTON_BROWSE"] = "Browse";
|
||||||
|
table["NANA_BUTTON_CANCEL"] = "Cancel";
|
||||||
|
table["NANA_BUTTON_CANCEL_SHORTKEY"] = "&Cancel";
|
||||||
|
table["NANA_BUTTON_CREATE"] = "Create";
|
||||||
|
|
||||||
|
table["NANA_FILEBOX_BYTES"] = "Bytes";
|
||||||
|
table["NANA_FILEBOX_FILESYSTEM"] = "FILESYSTEM";
|
||||||
|
table["NANA_FILEBOX_FILTER"] = "Filter";
|
||||||
|
table["NANA_FILEBOX_NEW_FOLDER"] = "New Folder";
|
||||||
|
table["NANA_FILEBOX_NEW_FOLDER_SHORTKEY"] = "&New Folder";
|
||||||
|
table["NANA_FILEBOX_HEADER_NAME"] = "Name";
|
||||||
|
table["NANA_FILEBOX_HEADER_MODIFIED"] = "Modified";
|
||||||
|
table["NANA_FILEBOX_HEADER_TYPE"] = "Type";
|
||||||
|
table["NANA_FILEBOX_HEADER_SIZE"] = "Size";
|
||||||
|
table["NANA_FILEBOX_NEW_FOLDER_CAPTION"] = "Name the new folder";
|
||||||
|
|
||||||
|
table["NANA_FILEBOX_SAVE_AS"] = "Save As";
|
||||||
|
table["NANA_FILEBOX_OPEN"] = "Open";
|
||||||
|
table["NANA_FILEBOX_DIRECTORY"] = "Directory";
|
||||||
|
table["NANA_FILEBOX_FILE"] = "File";
|
||||||
|
table["NANA_FILEBOX_FILE_COLON"] = "File:";
|
||||||
|
table["NANA_FILEBOX_ERROR_INVALID_FOLDER_NAME"] = "Please input a valid name for the new folder.";
|
||||||
|
table["NANA_FILEBOX_ERROR_RENAME_FOLDER_BECAUSE_OF_EXISTING"] = "The folder is existing, please rename it.";
|
||||||
|
table["NANA_FILEBOX_ERROR_RENAME_FOLDER_BECAUSE_OF_FAILED_CREATION"] = "Failed to create the folder, please rename it.";
|
||||||
|
table["NANA_FILEBOX_ERROR_INVALID_FILENAME"] = "The filename is invalid.";
|
||||||
|
table["NANA_FILEBOX_ERROR_NOT_EXISTING_AND_RETRY"] = "The file \"%arg0\"\n is not existing. Please check and retry.";
|
||||||
|
table["NANA_FILEBOX_ERROR_QUERY_REWRITE_BECAUSE_OF_EXISTING"] = "The input file is existing, do you want to overwrite it?";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::shared_ptr<data>& get_data_ptr()
|
static std::shared_ptr<data>& get_data_ptr()
|
||||||
@ -293,6 +330,10 @@ namespace nana
|
|||||||
}
|
}
|
||||||
}//end namespace internationalization_parts
|
}//end namespace internationalization_parts
|
||||||
|
|
||||||
|
void internationalization::set_missing(std::function<void(const std::string& msgid_utf8)> handler)
|
||||||
|
{
|
||||||
|
internationalization_parts::get_data_ptr()->on_missing = std::move(handler);
|
||||||
|
}
|
||||||
|
|
||||||
void internationalization::load(const std::string& file)
|
void internationalization::load(const std::string& file)
|
||||||
{
|
{
|
||||||
@ -324,6 +365,9 @@ namespace nana
|
|||||||
if (i != impl->table.end())
|
if (i != impl->table.end())
|
||||||
return i->second;
|
return i->second;
|
||||||
|
|
||||||
|
if (impl->on_missing)
|
||||||
|
impl->on_missing(msgid);
|
||||||
|
|
||||||
return std::move(msgid);
|
return std::move(msgid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user