kelatty19 wrote:Will be this feature available in the future? I need it, because i want to change the application language runtime. I don't want to restart the app. The context menu remains english without restart.
int Application::Initialize()
{
...
// initialization
CefSettings settings;
...
std::wstring sLang = L"";
GetProductLocale(sLang);
cef_string_copy(sLang.c_str(), static_cast<int>(sLang.length()), &settings->locale);
...
}
void Application::GetProductLocale(std::wstring& sLang)
{
sLang = L"xx-XX"; // replace with your desired app locale, user locale, system locale etc.
return;
}
CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override {
return this;
}
bool MainWindow::GetContextMenuLabel(int command_id, std::wstring& str)
{
str.clear();
if(command_id == MENU_ID_VIEW_SOURCE) {
str = L"View le Sources";
return true;
}
// ... more command IDs are in include/internal/cef_types.h, enum cef_menu_id_t
return !str.empty();
}
void ClientHandler::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, CefRefPtr<CefContextMenuParams> params,
CefRefPtr<CefMenuModel> model)
{
if(!model)
return;
// set text for all items from our resources, if present
int nItemCount = model->GetCount();
for(int c = 0; c < nItemCount; c++) {
int command_id = model->GetCommandIdAt(c);
if(command_id != -1) {
std::wstring strLabel;
if(m_pMainWindow->GetContextMenuLabel(command_id, strLabel)) {
_ASSERTE(!strLabel.empty());
model->SetLabel(command_id, CefString(strLabel));
}
}
}
// remove View source in release
if(model->IsVisible(MENU_ID_VIEW_SOURCE)) {
#ifndef _DEBUG
model->Remove(MENU_ID_VIEW_SOURCE);
#endif
}
return;
}
str = L"View le Sources"; etc.
Peter wrote:The question is: can I set CEF language without changing the locale in the OS?
Users browsing this forum: No registered users and 45 guests