Support language change for context menu
authorYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 17 Jun 2014 18:21:23 +0000 (11:21 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Patch uses "WebKit" text translation system to support language
change for context menu. This needs to be fixed later for the
same as "Blink".

Issue: CBBROWSER-146
Change-Id: Ib3a5b3bf394489d95743d3d399b1a8bbd8b4ed32

tizen_src/impl/context_menu_controller_efl.cc
tizen_src/impl/selection_controller_efl.cc
tizen_src/impl/selection_controller_efl.h

index 4f8edb35ef056c4956ea34d5fc5605717231fb68..22459e12bc1e36b4d244c9f75bcf88d7f8b3e003 100644 (file)
@@ -78,33 +78,33 @@ void ContextMenuControllerEfl::GetProposedContextMenu() {
   if (!params_.link_url.is_empty())
     AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
                          MENU_ITEM_OPEN_LINK_IN_NEW_WINDOW,
-                         std::string("Open in new window"),
+                         std::string(dgettext("WebKit","IDS_WEBVIEW_OPT_OPEN_LINK_IN_NEW_TAB_ABB")),
                          std::string(),
                          params_.link_url.spec(),
                          std::string());
   if (!params_.selection_text.empty())
     AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
                          MENU_ITEM_CUT,
-                         std::string("Cut"),
+                         std::string(dgettext("WebKit","IDS_WEBVIEW_OPT_CUT_ABB")),
                          std::string(),
                          std::string(),
                          std::string());
   if (params_.is_editable) {
     AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
                          MENU_ITEM_SELECT_WORD,
-                         std::string("Select"),
+                         std::string(dgettext("WebKit","IDS_WEBVIEW_OPT_SELECT_ABB")),
                          std::string(),
                          std::string(),
                          std::string());
     AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
                          MENU_ITEM_SELECT_ALL,
-                         std::string("Select All"),
+                         std::string(dgettext("WebKit","IDS_WEBVIEW_OPT_SELECT_ALL_ABB")),
                          std::string(),
                          std::string(),
                          std::string());
     AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
                          MENU_ITEM_PASTE,
-                         std::string("Paste"),
+                         std::string(dgettext("WebKit","IDS_WEBVIEW_OPT_PASTE")),
                          std::string(),
                          std::string(),
                          std::string());
@@ -112,27 +112,27 @@ void ContextMenuControllerEfl::GetProposedContextMenu() {
   if (!params_.selection_text.empty())
     AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
                          MENU_ITEM_COPY,
-                         std::string("Copy"),
+                         std::string(dgettext("WebKit","IDS_WEBVIEW_OPT_COPY")),
                          std::string(),
                          std::string(),
                          std::string());
   if (params_.has_image_contents && !params_.link_url.is_empty())
     AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
                          MENU_ITEM_OPEN_IMAGE_IN_NEW_WINDOW,
-                         std::string("Open Image"),
+                         std::string(dgettext("WebKit","IDS_WEBVIEW_OPT_OPEN_IMAGE_IN_NEW_TAB_ABB")),
                          params_.link_url.spec(),
                          params_.link_url.spec(),
                          std::string());
   if (!params_.has_image_contents && !params_.link_url.is_empty())
     AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
                          MENU_ITEM_TEXT_SELECTION_MODE,
-                         std::string("Select Mode"),
+                         std::string(dgettext("WebKit","IDS_WEBVIEW_OPT_SELECTION_MODE_ABB")),
                          params_.link_url.spec(),
                          params_.link_url.spec(),
                          std::string());
   AddItemToPropsedList(MENU_ITEM_TYPE_ACTION,
                        MENU_ITEM_CLIPBOARD,
-                       std::string("Clipboard"),
+                       std::string(dgettext("WebKit","IDS_WEBVIEW_OPT_CLIPBOARD")),
                        std::string(),
                        std::string(),
                        std::string());
index 79ba374cfc21f3ef9d9083d7af3f36e35478ae8a..cdcaadff2d95a8ffe4be567a1e6b4f97b39eb5d8 100644 (file)
@@ -24,6 +24,9 @@
 
 #include <Edje.h>
 
+// FIXME: To use BLINK_TEXT_DIR, following line needs to be modified later.
+#define WEBKIT_TEXT_DIR "/usr/share/ewebkit2-0/locale/po"
+
 namespace content {
 
 static const int menuHeight = 140;// The Height fo the context menu.
@@ -46,6 +49,12 @@ SelectionControllerEfl::SelectionControllerEfl(EWebView* parent_view)
        input_handle_(new SelectionHandleEfl(this, SelectionHandleEfl::HANDLE_TYPE_INPUT, parent_view->evas_object())),
        magnifier_(new SelectionMagnifierEfl(this)) {
   evas_object_event_callback_add(parent_view_->evas_object(), EVAS_CALLBACK_MOVE, &EvasParentViewMoveCallback, this);
+
+#if defined(OS_TIZEN)
+  setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
+  bindtextdomain("WebKit", WEBKIT_TEXT_DIR);
+  vconf_notify_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged, this);
+#endif
 }
 
 void SelectionControllerEfl::SetSelectionStatus(bool enable) {
@@ -59,6 +68,21 @@ bool SelectionControllerEfl::GetSelectionStatus() const {
   return selection_data_->GetStatus();
 }
 
+#if defined(OS_TIZEN)
+void SelectionControllerEfl::PlatformLanguageChanged(keynode_t* keynode, void* data) {
+  setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
+  bindtextdomain("WebKit", WEBKIT_TEXT_DIR);
+
+  SelectionControllerEfl* selection_controller = static_cast<SelectionControllerEfl*>(data);
+  if (!selection_controller)
+    return;
+
+  if (selection_controller->GetSelectionStatus())
+    selection_controller->ClearSelectionViaEWebView();
+  selection_controller->HideHandleAndContextMenu();
+}
+#endif
+
 void SelectionControllerEfl::SetSelectionEditable(bool enable) {
   TRACE_EVENT1("selection,efl", __PRETTY_FUNCTION__, "enable", enable);
   selection_data_->SetEditable(enable);
@@ -103,6 +127,10 @@ void SelectionControllerEfl::UpdateMagnifierScreen(Evas_Object* img) {
   magnifier_->UpdateScreen(img);
 }
 
+void SelectionControllerEfl::ClearSelectionViaEWebView() {
+  parent_view_->ClearSelection();
+}
+
 void SelectionControllerEfl::UpdateSelectionDataAndShow(const gfx::Rect& left_rect, const gfx::Rect& right_rect, bool is_anchor_first) {
   TRACE_EVENT0("selection,efl", __PRETTY_FUNCTION__);
   selection_data_->UpdateRectData(left_rect, right_rect, is_anchor_first);
index 84450f3365c1660716db7178d81b97926477e7a8..f051f94973d8c387daa32f3dedaf791bc09c14ba 100644 (file)
 #include "selection_handle_efl.h"
 #include "selection_magnifier_efl.h"
 
+#if defined(OS_TIZEN)
+#include "vconf/vconf.h"
+#endif
+
+#include <libintl.h>
+
 class EWebView;
 
 namespace content {
@@ -81,6 +87,7 @@ class SelectionControllerEfl {
 
   // Clears the selection and hides context menu and handles
   void ClearSelection();
+  void ClearSelectionViaEWebView();
   EWebView* GetParentView() { return parent_view_; }
   void HideHandle();
   void HideHandleAndContextMenu();
@@ -102,6 +109,10 @@ class SelectionControllerEfl {
   static void EvasParentViewMoveCallback(void *data, Evas *e, Evas_Object *obj, void *event_info)
   { reinterpret_cast<SelectionControllerEfl*>(data)->OnParentParentViewMove(); }
 
+#if defined(OS_TIZEN)
+  static void PlatformLanguageChanged(keynode_t* keynode, void* data);
+#endif
+
   void OnParentParentViewMove();
 
   // Is required to send back selction points and range extenstion co-ordinates