Commit b632fc1d authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_js_style: publish the page current language

parent 78cf1c94
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
current_language python: web_site.getPortalObject().Localizer.get_selected_language(); current_language python: web_site.getPortalObject().Localizer.get_selected_language();
global_definitions_macros here/global_definitions/macros;"> global_definitions_macros here/global_definitions/macros;">
<tal:block metal:use-macro="global_definitions_macros/header_definitions" /> <tal:block metal:use-macro="global_definitions_macros/header_definitions" />
<html> <html tal:attributes="lang current_language">
<head> <head>
<base tal:attributes="href python: '%s/' % web_section.absolute_url()" /> <base tal:attributes="href python: '%s/' % web_section.absolute_url()" />
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1" /> <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1" />
......
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
return result; return result;
} }
function parsePageContent(body_element, base_uri) { function parsePageContent(body_element, language, base_uri) {
var i, var i,
element, element,
element_list, element_list,
...@@ -174,6 +174,7 @@ ...@@ -174,6 +174,7 @@
return { return {
original_content: body_element.innerHTML, original_content: body_element.innerHTML,
html_content: body_element.querySelector('main').innerHTML, html_content: body_element.querySelector('main').innerHTML,
language: language,
language_list: parseLanguageElement( language_list: parseLanguageElement(
body_element.querySelector('nav#language') body_element.querySelector('nav#language')
), ),
...@@ -215,7 +216,9 @@ ...@@ -215,7 +216,9 @@
// consider this must be reloaded // consider this must be reloaded
throw new Error('Trigger an error to force reload'); throw new Error('Trigger an error to force reload');
} }
parsed_content = parsePageContent(dom_parser.body, dom_parser.baseURI); parsed_content = parsePageContent(dom_parser.body,
dom_parser.documentElement.lang,
dom_parser.baseURI);
gadget.parsed_content = parsed_content; gadget.parsed_content = parsed_content;
parsed_content.page_title = dom_parser.title; parsed_content.page_title = dom_parser.title;
return result_dict.style_gadget.render(parsed_content.html_content, return result_dict.style_gadget.render(parsed_content.html_content,
...@@ -312,7 +315,8 @@ ...@@ -312,7 +315,8 @@
return rJS.declareCSS(style_css_url, document.head); return rJS.declareCSS(style_css_url, document.head);
} }
parsed_content = parsePageContent(gadget.element); parsed_content = parsePageContent(gadget.element,
document.documentElement.lang);
gadget.parsed_content = parsed_content; gadget.parsed_content = parsed_content;
parsed_content.page_title = document.title; parsed_content.page_title = document.title;
gadget.style_gadget_url = gadget.style_gadget_url =
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
current_language python: web_site.getPortalObject().Localizer.get_selected_language(); current_language python: web_site.getPortalObject().Localizer.get_selected_language();
global_definitions_macros here/global_definitions/macros;"> global_definitions_macros here/global_definitions/macros;">
<tal:block metal:use-macro="global_definitions_macros/header_definitions" /> <tal:block metal:use-macro="global_definitions_macros/header_definitions" />
<html> <html tal:attributes="lang current_language">
<head> <head>
<base tal:attributes="href python: '%s/' % web_section.absolute_url()" /> <base tal:attributes="href python: '%s/' % web_section.absolute_url()" />
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1" /> <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1" />
......
...@@ -45,6 +45,11 @@ ...@@ -45,6 +45,11 @@
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'en')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
...@@ -83,6 +88,11 @@ ...@@ -83,6 +88,11 @@
<td>//main//p[text()="Contenu de la page d'accueil"]</td> <td>//main//p[text()="Contenu de la page d'accueil"]</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'fr')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()="Contenu de la page d'accueil"]</td> <td>//main//p[text()="Contenu de la page d'accueil"]</td>
...@@ -121,6 +131,11 @@ ...@@ -121,6 +131,11 @@
<td>//main//p[text()="主页内容"]</td> <td>//main//p[text()="主页内容"]</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'zh')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()="主页内容"]</td> <td>//main//p[text()="主页内容"]</td>
...@@ -159,6 +174,11 @@ ...@@ -159,6 +174,11 @@
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'en')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
......
...@@ -45,6 +45,11 @@ ...@@ -45,6 +45,11 @@
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'en')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
...@@ -83,6 +88,11 @@ ...@@ -83,6 +88,11 @@
<td>//main//p[text()="Contenu de la page d'accueil"]</td> <td>//main//p[text()="Contenu de la page d'accueil"]</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'fr')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()="Contenu de la page d'accueil"]</td> <td>//main//p[text()="Contenu de la page d'accueil"]</td>
...@@ -121,6 +131,11 @@ ...@@ -121,6 +131,11 @@
<td>//main//p[text()="主页内容"]</td> <td>//main//p[text()="主页内容"]</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'zh')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()="主页内容"]</td> <td>//main//p[text()="主页内容"]</td>
...@@ -159,6 +174,11 @@ ...@@ -159,6 +174,11 @@
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'en')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
......
...@@ -45,6 +45,11 @@ ...@@ -45,6 +45,11 @@
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'en')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
...@@ -78,6 +83,11 @@ ...@@ -78,6 +83,11 @@
<td>//main//p[text()="Contenu de la page d'accueil"]</td> <td>//main//p[text()="Contenu de la page d'accueil"]</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'fr')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()="Contenu de la page d'accueil"]</td> <td>//main//p[text()="Contenu de la page d'accueil"]</td>
...@@ -111,6 +121,11 @@ ...@@ -111,6 +121,11 @@
<td>//main//p[text()="主页内容"]</td> <td>//main//p[text()="主页内容"]</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'zh')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()="主页内容"]</td> <td>//main//p[text()="主页内容"]</td>
...@@ -144,6 +159,11 @@ ...@@ -144,6 +159,11 @@
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertElementPresent</td>
<td>//p[@id='current_language'][contains(text(), 'en')]</td>
<td></td>
</tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//main//p[text()='Frontpage content']</td> <td>//main//p[text()='Frontpage content']</td>
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<p id="gadget_style_url"></p> <p id="gadget_style_url"></p>
<p id="render_count"></p> <p id="render_count"></p>
<p id="portal_status_message"></p> <p id="portal_status_message"></p>
<p id="current_language"></p>
<nav id="language"></nav> <nav id="language"></nav>
<nav id="sitemap"></nav> <nav id="sitemap"></nav>
<aside id="document_list"></aside> <aside id="document_list"></aside>
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
.declareMethod("render", function (html_content, parsed_content) { .declareMethod("render", function (html_content, parsed_content) {
var state = { var state = {
document_list: JSON.stringify(parsed_content.document_list || []), document_list: JSON.stringify(parsed_content.document_list || []),
current_language: parsed_content.language || "",
language_list: JSON.stringify(parsed_content.language_list || []), language_list: JSON.stringify(parsed_content.language_list || []),
sitemap: JSON.stringify(parsed_content.sitemap || {}), sitemap: JSON.stringify(parsed_content.sitemap || {}),
page_title: parsed_content.page_title || "", page_title: parsed_content.page_title || "",
...@@ -87,6 +88,11 @@ ...@@ -87,6 +88,11 @@
text: 'render count: ' + gadget.state.render_count text: 'render count: ' + gadget.state.render_count
}); });
} }
if (modification_dict.hasOwnProperty('current_language')) {
domsugar(gadget.element.querySelector('p#current_language'), {
text: gadget.state.current_language
});
}
if (modification_dict.hasOwnProperty('language_list')) { if (modification_dict.hasOwnProperty('language_list')) {
language_list = JSON.parse(gadget.state.language_list); language_list = JSON.parse(gadget.state.language_list);
child_list = []; child_list = [];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment