From b266ef47ed0265ac2c49273aeb492520a681f01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Thu, 28 Apr 2022 10:03:35 +0900 Subject: [PATCH] core,dms,xhtml_syle: support language in editor gadgets (CKEditor and pdf.js) A new option render option, "language" is passed to the gadget. It is a two letter code as used by Localier. Both CKEditor and pdf.js have support for translations and already include translations for many languages. Before this change, they were auto detecting the browser language and displaying in the browser language, ignoring the language that was selected in ERP5. With this change, they use the language selected in ERP5. For CKEditor, we need to set the language only it is actually supported, otherwise CKEditor crash. pdf.js does not this, but we had to call ourselves initialize - which is probably better, because it was a promise not awaited. --- .../testCRMCreateNewEventEditorLanguage.xml | 58 +++++++++ .../testCRMCreateNewEventEditorLanguage.zpt | 109 ++++++++++++++++ .../Zuite_CommonTemplateForCRMRenderjsUi.zpt | 10 +- .../testCRMCreateNewEventEditorLanguage.xml | 58 +++++++++ .../testCRMCreateNewEventEditorLanguage.zpt | 123 ++++++++++++++++++ .../erp5_dms/pdf_js/pdf.gadget.js.js | 22 ++-- .../dms_zuite/testPDFPreviewLanguage.xml | 58 +++++++++ .../dms_zuite/testPDFPreviewLanguage.zpt | 85 ++++++++++++ .../testPDFPreviewLanguage.xml | 58 +++++++++ .../testPDFPreviewLanguage.zpt | 66 ++++++++++ .../my_view_mode_text_content.xml | 2 +- .../erp5_core/gadget_editor.js.js | 3 + .../erp5_ckeditor/ckeditor.gadget.js.js | 10 +- 13 files changed, 644 insertions(+), 18 deletions(-) create mode 100644 bt5/erp5_crm_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_crm_action_zuite/testCRMCreateNewEventEditorLanguage.xml create mode 100644 bt5/erp5_crm_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_crm_action_zuite/testCRMCreateNewEventEditorLanguage.zpt create mode 100644 bt5/erp5_crm_ui_test/PathTemplateItem/portal_tests/crm_action_zuite/testCRMCreateNewEventEditorLanguage.xml create mode 100644 bt5/erp5_crm_ui_test/PathTemplateItem/portal_tests/crm_action_zuite/testCRMCreateNewEventEditorLanguage.zpt create mode 100644 bt5/erp5_dms_ui_test/PathTemplateItem/portal_tests/dms_zuite/testPDFPreviewLanguage.xml create mode 100644 bt5/erp5_dms_ui_test/PathTemplateItem/portal_tests/dms_zuite/testPDFPreviewLanguage.zpt create mode 100644 bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_dms_zuite/testPDFPreviewLanguage.xml create mode 100644 bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_dms_zuite/testPDFPreviewLanguage.zpt diff --git a/bt5/erp5_crm_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_crm_action_zuite/testCRMCreateNewEventEditorLanguage.xml b/bt5/erp5_crm_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_crm_action_zuite/testCRMCreateNewEventEditorLanguage.xml new file mode 100644 index 0000000000..9a96a4be4d --- /dev/null +++ b/bt5/erp5_crm_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_crm_action_zuite/testCRMCreateNewEventEditorLanguage.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>content_type</string> </key> + <value> <string>text/html</string> </value> + </item> + <item> + <key> <string>expand</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>testCRMCreateNewEventEditorLanguage</string> </value> + </item> + <item> + <key> <string>output_encoding</string> </key> + <value> <string>utf-8</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <unicode></unicode> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_crm_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_crm_action_zuite/testCRMCreateNewEventEditorLanguage.zpt b/bt5/erp5_crm_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_crm_action_zuite/testCRMCreateNewEventEditorLanguage.zpt new file mode 100644 index 0000000000..7faad3d70f --- /dev/null +++ b/bt5/erp5_crm_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_crm_action_zuite/testCRMCreateNewEventEditorLanguage.zpt @@ -0,0 +1,109 @@ +<html xmlns:tal="http://xml.zope.org/namespaces/tal" + xmlns:metal="http://xml.zope.org/namespaces/metal"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title tal:content="template/title_or_id"></title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3" tal:content="template/title_or_id"></td></tr> +</thead><tbody> + +<tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMRenderjsUi/macros/init" /> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/create_translation_data" /> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMRenderjsUi/macros/prepare_data" /> + +<!-- try with a language supported (fr) in CKEditor, then a language not supported (wo) --> +<tal:block + tal:define="language_and_translations python:[('fr', {'Font': 'Police', 'Actions': 'Actions'}), ('wo', {'Font': 'Font', 'Actions': 'caozhuo'})]" + tal:repeat="language_and_translation language_and_translations"> +<tr> + <td>store</td> + <td>${base_url}/web_site_module/renderjs_runner/<tal:block tal:replace="python: language_and_translation[0]"/>/#</td> + <td>renderjs_url</td> +</tr> + +<tal:block tal:define="translation_dict python: language_and_translation[1]"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMRenderjsUi/macros/view_create_new_event_dialog" /> +</tal:block> + +<tal:block tal:define="dialog_content_configuration python: {'field_your_title': '', + 'field_your_portal_type': 'Mail Message', + 'field_your_resource': '', + 'field_your_notification_message': '', + 'field_your_event_workflow_action': 'send', + 'field_your_source': '', + 'field_your_destination': '', + 'field_your_text_content': '<p><br></p>'}"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMRenderjsUi/macros/check_create_new_event_dialog_content" /> +</tal:block> + +<tal:block tal:define="dialog_content_configuration python: {'field_your_title': 'erp5_crm_ui_test_create_event_title', + 'field_your_portal_type': 'Letter', + 'field_your_resource': '', + 'field_your_start_date': '2010-01-01T00:00:00', + 'field_your_notification_message': '', + 'field_your_event_workflow_action': 'send', + 'field_your_source': 'erp5_crm_ui_test_agent_title', + 'field_your_destination': 'erp5_crm_ui_test_customer_title', + 'field_your_text_content': '<p>Foo<br>Bar</p>'}"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMRenderjsUi/macros/fill_create_new_event_dialog_content" /> +</tal:block> + +<tr> + <td>selectFrame</td> + <td>//iframe</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>css=.cke_combo__font > .cke_combo_label</td> + <td tal:content="python: language_and_translation[1]['Font']"></td> +</tr> +<tr> + <td>selectFrame</td> + <td>relative=top</td> + <td></td> +</tr> + +<!-- Header has a save button --> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" /> + +<tal:block tal:define="notification_configuration python: {'class': 'success', + 'text': 'Created and associated a new Letter to the ticket.'}"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_notification" /> +</tal:block> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" /> + +<tal:block tal:define="response_configuration python: {'field_my_title': 'erp5_crm_ui_test_create_event_title', + 'field_my_portal_type': 'Letter', + 'field_my_resource': '', + 'field_my_start_date': '2010-01-01T00:00:00', + 'simulation_state': 'Sent', + 'field_my_source_title': 'erp5_crm_ui_test_agent_title', + 'field_my_destination_title': 'erp5_crm_ui_test_customer_title', + 'field_my_text_content': '<p>Foo<br>Bar</p>'}"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMRenderjsUi/macros/check_response_content" /> +</tal:block> + +<tr> + <td>selectFrame</td> + <td>//iframe</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>css=.cke_combo__font > .cke_combo_label</td> + <td tal:content="python: language_and_translation[1]['Font']"></td> +</tr> +<tr> + <td>selectFrame</td> + <td>relative=top</td> + <td></td> +</tr> + +</tal:block> +</tbody></table> +</body> +</html> \ No newline at end of file diff --git a/bt5/erp5_crm_renderjs_ui_test/SkinTemplateItem/portal_skins/erp5_crm_renderjs_ui_test/Zuite_CommonTemplateForCRMRenderjsUi.zpt b/bt5/erp5_crm_renderjs_ui_test/SkinTemplateItem/portal_skins/erp5_crm_renderjs_ui_test/Zuite_CommonTemplateForCRMRenderjsUi.zpt index 557419c9ba..97230de92b 100644 --- a/bt5/erp5_crm_renderjs_ui_test/SkinTemplateItem/portal_skins/erp5_crm_renderjs_ui_test/Zuite_CommonTemplateForCRMRenderjsUi.zpt +++ b/bt5/erp5_crm_renderjs_ui_test/SkinTemplateItem/portal_skins/erp5_crm_renderjs_ui_test/Zuite_CommonTemplateForCRMRenderjsUi.zpt @@ -207,7 +207,7 @@ </tal:block> - <tal:block metal:define-macro="view_create_new_event_dialog"> + <tal:block metal:define-macro="view_create_new_event_dialog" tal:define="translation_dict translation_dict | python: {}"> <tr> <td colspan="3"><b>Display the create new event dialog</b></td> </tr> @@ -223,7 +223,7 @@ <td>//div[@data-gadget-url='${base_url}/web_site_module/renderjs_runner/gadget_erp5_pt_form_view_editable.html']</td> <td></td> </tr> - <tal:block tal:define="click_configuration python: {'text': 'Actions'}"> + <tal:block tal:define="click_configuration python: {'text': translation_dict.get('Actions', 'Actions')}"> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/click_on_header_link" /> </tal:block> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" /> @@ -234,11 +234,11 @@ </tr> <tr> <td>assertTextPresent</td> - <td>Create New Event</td> + <td tal:content="python: translation_dict.get('Create New Event', 'Create New Event')">Create New Event</td> <td></td> </tr> - <tal:block tal:define="click_configuration python: {'text': 'Create New Event'}"> + <tal:block tal:define="click_configuration python: {'text': translation_dict.get('Create New Event', 'Create New Event')}"> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/click_on_page_link" /> </tal:block> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" /> @@ -250,7 +250,7 @@ </tr> <tr> <td>assertTextPresent</td> - <td>Create New Event</td> + <td tal:content="python: translation_dict.get('Create New Event', 'Create New Event')">Create New Event</td> <td></td> </tr> <tr> diff --git a/bt5/erp5_crm_ui_test/PathTemplateItem/portal_tests/crm_action_zuite/testCRMCreateNewEventEditorLanguage.xml b/bt5/erp5_crm_ui_test/PathTemplateItem/portal_tests/crm_action_zuite/testCRMCreateNewEventEditorLanguage.xml new file mode 100644 index 0000000000..9a96a4be4d --- /dev/null +++ b/bt5/erp5_crm_ui_test/PathTemplateItem/portal_tests/crm_action_zuite/testCRMCreateNewEventEditorLanguage.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>content_type</string> </key> + <value> <string>text/html</string> </value> + </item> + <item> + <key> <string>expand</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>testCRMCreateNewEventEditorLanguage</string> </value> + </item> + <item> + <key> <string>output_encoding</string> </key> + <value> <string>utf-8</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <unicode></unicode> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_crm_ui_test/PathTemplateItem/portal_tests/crm_action_zuite/testCRMCreateNewEventEditorLanguage.zpt b/bt5/erp5_crm_ui_test/PathTemplateItem/portal_tests/crm_action_zuite/testCRMCreateNewEventEditorLanguage.zpt new file mode 100644 index 0000000000..a5fd4e9985 --- /dev/null +++ b/bt5/erp5_crm_ui_test/PathTemplateItem/portal_tests/crm_action_zuite/testCRMCreateNewEventEditorLanguage.zpt @@ -0,0 +1,123 @@ +<html xmlns:tal="http://xml.zope.org/namespaces/tal" + xmlns:metal="http://xml.zope.org/namespaces/metal"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title tal:content="template/title_or_id"></title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3" tal:content="template/title_or_id"></td></tr> +</thead><tbody> + +<tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMUiTest/macros/init" /> +<tr> + <td>open</td> + <td tal:content="string: ${here/portal_url}/Base_createUITestLanguages"></td> + <td></td> +</tr> +<tr> + <td>assertTextPresent</td> + <td>New Languages Added</td> + <td></td> +</tr> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMUiTest/macros/prepare_data" /> + +<!-- try with a language supported (fr) in CKEditor, then a language not supported (wo) --> +<tal:block + tal:define="language_and_translations python:[('French', 'Police'), ('Wolof', 'Font')]" + tal:repeat="language_and_translation language_and_translations"> + +<tr> + <td>open</td> + <td>${base_url}</td> + <td></td> +</tr> +<tr> + <td>selectAndWait</td> + <td>select_language</td> + <td tal:content="python: language_and_translation[0]"></td> +</tr> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMUiTest/macros/view_create_new_event_dialog" /> + +<tal:block tal:define="dialog_content_configuration python: {'field_your_title': '', + 'field_your_portal_type': 'Mail Message', + 'field_your_resource': '', + 'field_your_notification_message': '', + 'field_your_event_workflow_action': 'send', + 'field_your_source': '', + 'field_your_destination': '', + 'field_your_text_content': '<p><br></p>'}"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMUiTest/macros/check_create_new_event_dialog_content" /> +</tal:block> + +<tal:block tal:define="dialog_content_configuration python: {'field_your_title': 'Test event', + 'field_your_portal_type': 'Letter', + 'field_your_resource': '', + 'field_your_start_date': '2010-01-01T00:00:00', + 'field_your_notification_message': '', + 'field_your_event_workflow_action': 'send', + 'field_your_source': 'erp5_crm_ui_test_agent_title', + 'field_your_destination': 'erp5_crm_ui_test_customer_title', + 'field_your_text_content': '<p>Foo<br>Bar</p>'}"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMUiTest/macros/fill_create_new_event_dialog_content" /> +</tal:block> + +<tr> + <td>selectFrame</td> + <td>//iframe</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>css=.cke_combo__font > .cke_combo_label</td> + <td tal:content="python: language_and_translation[1]"></td> +</tr> +<tr> + <td>selectFrame</td> + <td>relative=top</td> + <td></td> +</tr> + +<tr> + <td>clickAndWait</td> + <td>dialog_submit_button</td> + <td></td> +</tr> +<tr> + <td>assertPortalStatusMessage</td> + <td>Created and associated a new Letter to the ticket.</td> + <td></td> +</tr> + +<tal:block tal:define="response_configuration python: {'field_my_title': 'Test event', + 'field_my_portal_type': 'Letter', + 'field_my_resource': '', + 'field_my_start_date': '2010-01-01T00:00:00', + 'simulation_state': 'Sent', + 'field_my_source_title': 'erp5_crm_ui_test_agent_title', + 'field_my_destination_title': 'erp5_crm_ui_test_customer_title', + 'field_my_text_content': '<p>Foo<br>Bar</p>'}"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForCRMUiTest/macros/check_response_content" /> +</tal:block> + +<tr> + <td>selectFrame</td> + <td>//iframe</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>css=.cke_combo__font > .cke_combo_label</td> + <td tal:content="python: language_and_translation[1]"></td> +</tr> +<tr> + <td>selectFrame</td> + <td>relative=top</td> + <td></td> +</tr> + +</tal:block> +</tbody></table> +</body> +</html> \ No newline at end of file diff --git a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/pdf_js/pdf.gadget.js.js b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/pdf_js/pdf.gadget.js.js index e62742412b..275e0c1d00 100644 --- a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/pdf_js/pdf.gadget.js.js +++ b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/pdf_js/pdf.gadget.js.js @@ -13,16 +13,18 @@ }); }) .declareMethod("render", function (options) { - this.props.key = options.key; - webViewerLoad(options.value); - - // hide few buttons for now - this.props.element.querySelector('#viewBookmark').hidden = true; - this.props.element.querySelector('#documentProperties').hidden = true; - this.props.element.querySelector('#documentProperties').hidden = true; - this.props.element.querySelector('#download').hidden = true; - - return; + var gadget = this; + gadget.props.key = options.key; + configure(PDFJS); + PDFJS.locale = options.language; + return PDFViewerApplication.initialize().then(function() { + webViewerInitialized(options.value); + // hide some buttons that do not make sense for us + gadget.props.element.querySelector('#viewBookmark').hidden = true; + gadget.props.element.querySelector('#documentProperties').hidden = true; + gadget.props.element.querySelector('#documentProperties').hidden = true; + gadget.props.element.querySelector('#download').hidden = true; + }); }) .declareMethod("getContent", function () { var form_data = {}; diff --git a/bt5/erp5_dms_ui_test/PathTemplateItem/portal_tests/dms_zuite/testPDFPreviewLanguage.xml b/bt5/erp5_dms_ui_test/PathTemplateItem/portal_tests/dms_zuite/testPDFPreviewLanguage.xml new file mode 100644 index 0000000000..a363932b1b --- /dev/null +++ b/bt5/erp5_dms_ui_test/PathTemplateItem/portal_tests/dms_zuite/testPDFPreviewLanguage.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>content_type</string> </key> + <value> <string>text/html</string> </value> + </item> + <item> + <key> <string>expand</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>testPDFPreviewLanguage</string> </value> + </item> + <item> + <key> <string>output_encoding</string> </key> + <value> <string>utf-8</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <unicode>PDF Preview Editor Language</unicode> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_dms_ui_test/PathTemplateItem/portal_tests/dms_zuite/testPDFPreviewLanguage.zpt b/bt5/erp5_dms_ui_test/PathTemplateItem/portal_tests/dms_zuite/testPDFPreviewLanguage.zpt new file mode 100644 index 0000000000..7c8bfc3b49 --- /dev/null +++ b/bt5/erp5_dms_ui_test/PathTemplateItem/portal_tests/dms_zuite/testPDFPreviewLanguage.zpt @@ -0,0 +1,85 @@ +<html xmlns:tal="http://xml.zope.org/namespaces/tal" + xmlns:metal="http://xml.zope.org/namespaces/metal"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title tal:content="template/title_and_id"></title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3" tal:content="template/title_and_id"></td></tr> +</thead><tbody> + +<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" /> +<tr> + <td>open</td> + <td tal:content="string: ${here/portal_url}/Base_createUITestLanguages"></td> + <td></td> +</tr> +<tr> + <td>assertTextPresent</td> + <td>New Languages Added</td> + <td></td> +</tr> +<tr> + <td>openAndWait</td> + <td>${base_url}/fr/document_module/test_ERP5_Logo_PDF/PDF_viewPDFJSPreview</td> + <td></td> +</tr> +<tr> + <td>waitForElementPresent</td> + <td>//iframe[contains(@src, "pdfjs.gadget.html")]</td> + <td></td> +</tr> +<tr> + <td>selectFrame</td> + <td>//iframe[contains(@src, "pdfjs.gadget.html")]</td> + <td></td> +</tr> +<tr> + <td>waitForText</td> + <td>//body//div[@class='textLayer']/div[1]</td> + <td>This is a sample PDF with some text and an image</td> +</tr> +<tr> + <td>waitForText</td> + <td>//option[@id="pageAutoOption"]</td> + <td>Zoom automatique</td> +</tr> +<tr> + <td>selectFrame</td> + <td>relative=top</td> + <td></td> +</tr> + +<!-- Try with a language not supported by pdf.js --> +<tr> + <td>selectAndWait</td> + <td>select_language</td> + <td>Xhosa</td> +</tr> +<tr> + <td>waitForElementPresent</td> + <td>//iframe[contains(@src, "pdfjs.gadget.html")]</td> + <td></td> +</tr> +<tr> + <td>selectFrame</td> + <td>//iframe[contains(@src, "pdfjs.gadget.html")]</td> + <td></td> +</tr> +<tr> + <td>waitForText</td> + <td>//option[@id="pageAutoOption"]</td> + <td>Automatic Zoom</td> +</tr> +<tr> + <td>selectFrame</td> + <td>relative=top</td> + <td></td> +</tr> + + +</tbody></table> +</body> +</html> \ No newline at end of file diff --git a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_dms_zuite/testPDFPreviewLanguage.xml b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_dms_zuite/testPDFPreviewLanguage.xml new file mode 100644 index 0000000000..a363932b1b --- /dev/null +++ b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_dms_zuite/testPDFPreviewLanguage.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>content_type</string> </key> + <value> <string>text/html</string> </value> + </item> + <item> + <key> <string>expand</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>testPDFPreviewLanguage</string> </value> + </item> + <item> + <key> <string>output_encoding</string> </key> + <value> <string>utf-8</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <unicode>PDF Preview Editor Language</unicode> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_dms_zuite/testPDFPreviewLanguage.zpt b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_dms_zuite/testPDFPreviewLanguage.zpt new file mode 100644 index 0000000000..9962c446c9 --- /dev/null +++ b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_dms_zuite/testPDFPreviewLanguage.zpt @@ -0,0 +1,66 @@ +<html xmlns:tal="http://xml.zope.org/namespaces/tal" + xmlns:metal="http://xml.zope.org/namespaces/metal"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title tal:content="template/title_and_id"></title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3" tal:content="template/title_and_id"></td></tr> +</thead><tbody> +<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" /> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/create_translation_data" /> + +<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/wait_for_activities" /> + +<!-- try with a language supported (fr) in pdf.js, then a language not supported (wo) --> +<tal:block + tal:define="language_and_translations python:[('fr', 'Views', 'Zoom automatique'), ('wo', 'shitu', 'Automatic Zoom')]" + tal:repeat="language_and_translation language_and_translations"> +<tr> + <td>open</td> + <td>${base_url}/web_site_module/renderjs_runner/<tal:block tal:replace="python: language_and_translation[0]"/>/#/document_module/test_ERP5_Logo_PDF?editable=1</td> + <td></td> +</tr> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" /> + +<tal:block tal:define="click_configuration python: {'text': language_and_translation[1]}"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/click_on_header_link" /> +</tal:block> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" /> +<tal:block tal:define="click_configuration python: {'text': 'Preview'}"> + <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/click_on_page_link" /> +</tal:block> +<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" /> + +<tr> + <td>waitForElementPresent</td> + <td>//iframe[contains(@src, "pdfjs.gadget.html")]</td> + <td></td> +</tr> +<tr> + <td>selectFrame</td> + <td>//iframe[contains(@src, "pdfjs.gadget.html")]</td> + <td></td> +</tr> +<tr> + <td>waitForText</td> + <td>//body//div[@class='textLayer']/div[1]</td> + <td>This is a sample PDF with some text and an image</td> +</tr> +<tr> + <td>waitForText</td> + <td>//option[@id="pageAutoOption"]</td> + <td tal:content="python: language_and_translation[2]">Automatic Zoom</td> +</tr> +<tr> + <td>selectFrame</td> + <td>relative=top</td> + <td></td> +</tr> + +</tal:block> +</tbody></table> +</body> +</html> \ No newline at end of file diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_viewFieldLibrary/my_view_mode_text_content.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_viewFieldLibrary/my_view_mode_text_content.xml index 239c933bea..ce8b5fa9fe 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_viewFieldLibrary/my_view_mode_text_content.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_viewFieldLibrary/my_view_mode_text_content.xml @@ -142,7 +142,7 @@ <dictionary> <item> <key> <string>_text</string> </key> - <value> <string>python: [(\'jio_key\', context.getRelativeUrl()), (\'editor\', context.Base_getEditorFieldPreferredTextEditor()), (\'portal_type\', context.getPortalType()), (\'maximize\', \'listbox\' not in field.id), (\'content_type\', context.getProperty(\'content_type\'))]</string> </value> + <value> <string>python: [(\'jio_key\', context.getRelativeUrl()), (\'editor\', context.Base_getEditorFieldPreferredTextEditor()), (\'portal_type\', context.getPortalType()), (\'maximize\', \'listbox\' not in field.id), (\'content_type\', context.getProperty(\'content_type\')), (\'language\', context.getPortalObject().Localizer.get_selected_language())]</string> </value> </item> </dictionary> </pickle> diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/gadget_editor.js.js b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/gadget_editor.js.js index ced875eaa4..2d320c3a68 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/gadget_editor.js.js +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/gadget_editor.js.js @@ -12,6 +12,8 @@ * @property {string} portal_type the portal type * @property {boolean} editable set to true to have an editor when user * can modify the content, false for a "read only" editor + * @property {string} language the user language, if the editor supports + * localisation it will be displayed in this language * @property {boolean} run a hack for jsmd editor * @property {string} key Key for ERP5 form */ @@ -81,6 +83,7 @@ maximize: options.maximize, portal_type: options.portal_type, editable: options.editable || false, + language: options.language, //run value is used to make jsmd viewer available in editable mode //this is temporary until the viewer becomes editable run: options.run || false, diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_ckeditor/ckeditor.gadget.js.js b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_ckeditor/ckeditor.gadget.js.js index 5ba061cecc..08658fbef0 100644 --- a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_ckeditor/ckeditor.gadget.js.js +++ b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_ckeditor/ckeditor.gadget.js.js @@ -99,7 +99,8 @@ READONLY_CONFIGURATION, is_responsive: (options.configuration_mobile !== undefined) || (options.configuration === undefined), - is_mobile: MATCH_MEDIA.matches + is_mobile: MATCH_MEDIA.matches, + language: options.language }); }) @@ -124,7 +125,8 @@ modification_dict.hasOwnProperty('configuration_readonly') || modification_dict.hasOwnProperty('is_responsive') || modification_dict.hasOwnProperty('is_mobile') || - modification_dict.hasOwnProperty('editable')) { + modification_dict.hasOwnProperty('editable') || + modification_dict.hasOwnProperty('language')) { // Expected configuration changed. // Recreate ckeditor if (gadget.hasOwnProperty('ckeditor')) { @@ -139,6 +141,10 @@ } else { configuration = gadget.state.configuration; } + if (CKEDITOR.lang.languages[gadget.state.language] !== undefined) { + configuration.language = gadget.state.language; + configuration.defaultLanguage = gadget.state.language; + } gadget.on_change_listener = gadget.deferNotifyChange.bind(gadget); gadget.ckeditor = CKEDITOR.replace( this.element.querySelector('textarea'), -- 2.30.9