escape ' -> \' for the UI-WELCOME_ERROR#10581
Conversation
|
Can one of the admins verify this patch? |
|
FYI @hickeyma |
|
jenkins, test this |
src/ui/views/ui_app.jade
Outdated
There was a problem hiding this comment.
I am wondering would it be better here to assign to double quotes instead to escape the single quote:
err.innerText = "#{i18n('UI-WELCOME_ERROR')}";
There was a problem hiding this comment.
@hickeyma I tried that, actually using JSON.stringify instead and double quotes… but Jade (now pug) ends up quoting oddly- I think a html safe transform is implicated.
There was a problem hiding this comment.
still would need to quote doublequotes in that case.
There was a problem hiding this comment.
for that matter, this line could just be:
`err.innerText = '#{i18n('UI-WELCOME_ERROR').replace(/'/g,'\'')}';
and drop the other function.
There was a problem hiding this comment.
I tried this and it works as expected without any other cahnges:
err.innerText = "#{i18n('UI-WELCOME_ERROR')}";
There was a problem hiding this comment.
will that work if a " shows up in the string? In Hebrew that can be used as a standin for gershayim ״ (in Hebrew). So it might fix French but break Hebrew.
There was a problem hiding this comment.
what about something like err.innerText = "#{i18n('UI-WELCOME_ERROR').replace(/"/g,'\\"')}"; for this one spot (if we don't use the meta tag option)
you are in a maze of twisty nested quoted strings, some alike
src/ui/index.js
Outdated
There was a problem hiding this comment.
Not sure we would want 2 variables passed which contain the separate instances of the translations. Refer to comment in 'src/ui/views/ui_app.jade' by using double quotes.
There was a problem hiding this comment.
they're two functions… and actually, they are only for this startup page.
There was a problem hiding this comment.
Ahhhh .. meant functions! Just trying to avoid having to make changes if another means possible.
|
Take notice how we handle this here: https://github.com/srl295/kibana/blob/559bb8bf3cbad7a189681f9ae864fc4f9f1cbe0c/src/ui/views/ui_app.jade#L104 |
|
@spalger I thought about that, but was not sure how to stringify the existing function. |
|
@srl295 the JSON stringification happens server side, so the line would look like: err.innerText = !{JSON.stringify(i18n(…))};Now that I think about it, that wouldn't work if the string had html in it 😞 . Escaping in a script tag is hard (which is why we ended up using a meta tag for our injected vars). |
|
Can we just use a meta tag for this? |
|
@hickeyma it would probably work, but I'm just not comfortable writing an escaping function inline (or elsewhere) unless it's tested and the requirements of the function are better researched/more certain. |
|
@spalger let me try the meta tag option. |
6c30eb7 to
c17baa4
Compare
|
I've rebased now that #8766 is merged. |
|
jenkins, test this |
|
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
💔 Build Failed |
|
Hey happy new year and all! I think this may need some serious rebasing. @tsullivan as you noted the changed file in question is now at https://github.com/elastic/kibana/blob/master/src/ui/ui_render/views/ui_app.jade - it was moved in #14745 and modified in #15904, it's possible this change is moot. |
|
Old commit was srl295@c17baa4 — pushing an untested rebase now. |
c17baa4 to
246e7b9
Compare
|
Not sure if this is still relevant or not, Spencer would probably know best. |
|
I couldn't remember how I tested this. I'm doing this locally to test: diff --git a/src/core_plugins/kibana/translations/en.json b/src/core_plugins/kibana/translations/en.json
index ddb7a272e..37e7553a2 100644
--- a/src/core_plugins/kibana/translations/en.json
+++ b/src/core_plugins/kibana/translations/en.json
@@ -1,4 +1,4 @@
{
"UI-WELCOME_MESSAGE": "Loading Kibana",
- "UI-WELCOME_ERROR": "Kibana did not load properly. Check the server output for more information."
+ "UI-WELCOME_ERROR": "Kibana didn't load properly. Check the server output for more information."
}
diff --git a/src/ui/ui_render/bootstrap/template.js.hbs b/src/ui/ui_render/bootstrap/template.js.hbs
index 8a4c5fe52..6ed394f6e 100644
--- a/src/ui/ui_render/bootstrap/template.js.hbs
+++ b/src/ui/ui_render/bootstrap/template.js.hbs
@@ -40,6 +40,8 @@ window.onload = function () {
dom.setAttribute('async', '');
dom.addEventListener('error', failure);
+ failure();
+
if (type === 'script') {
dom.setAttribute('src', file);
dom.addEventListener('load', next); |
|
@Bargs Hi! I was able to get a rebase to work. I'm checking to see if I can repro the original issue. |
|
Yup I can repro. see my above comment, fails (spins forever on loading) because of:
So, it's still relevant. And the PR fixes it. Rerun it through CI? |
|
jenkins, test this |
💚 Build Succeeded |
|
I didn't test the fix but the code looks ok to me. I'm going to assign @azasypkin as a reviewer as he's taking over the internationalization effort, so he can decide if it makes sense to merge this or not. |
There was a problem hiding this comment.
nit: since we don't use i18n helper anymore we can safely remove it from app_bootstrap.js (including all other related pieces like lodash import and knownHelpers property).
There was a problem hiding this comment.
@azasypkin hm - well, the point here is to load the localized error. What's the right way to do it now?
The entire bug here is that at runtime,
err.innerText = '{{i18n 'UI-WELCOME_ERROR'}}';could (with the right translation) get replaced by the i18n helper to:
err.innerText = 'Quel temps va-t-il faire aujourd'hui?';… which is invalid JS.
There was a problem hiding this comment.
Right, I mean previously we rendered message with the help of i18n Handlebars helper (see here) that led to invalid JS. In this PR you're extracting error message from the DOM, so we don't need this helper anymore.
i18n Jade helper used in ui_app.jade or chrome.jade (see here is a different thing, we still need it.
There was a problem hiding this comment.
got it. now when i get a chance I'll rebase and update.
src/ui/ui_render/views/ui_app.jade
Outdated
There was a problem hiding this comment.
suggestion: what if we use data attribute instead?
.kibanaWelcomeText(data-error-message='#{i18n("UI-WELCOME_ERROR")}')It won't require additional style with display: none, in js we can extract it like this:
document.querySelector('[data-error-message]').dataset.errorMessageOr even maybe add this attribute to body in chrome.jade and then we won't need querySelector at all:
document.body.dataset.errorMessageWhat do you think?
There was a problem hiding this comment.
@azasypkin makes some sense. But still uses the i18n helper?
There was a problem hiding this comment.
But still uses the i18n helper?
Yes, but see my comment above, we need Jade i18n helper, not the one we used in Handlebars template.
There was a problem hiding this comment.
Sorry, it's confusing, I know :)
|
Hey @srl295 Thanks for your contribution, the i18n implementation has changed in the last months, do you have time to rebase to master? |
* store the error message in an extra div for later retrieval Fixes: elastic#10580
💔 Build Failed |
246e7b9 to
c640e69
Compare
|
@markov00 I have addressed @azasypkin ’s suggestions and rebased. However, I can't figure out how to 'break' Kibana in order to get the error message to show up now. Do you have any suggestions? |
|
Jenkins, test this @srl295 thanks for that 👍 |
| .kibanaWelcomeLogoCircle | ||
| .kibanaWelcomeLogo | ||
| .kibanaWelcomeText | ||
| .kibanaWelcomeText(data-error-message='#{i18n("UI-WELCOME_ERROR")}') |
There was a problem hiding this comment.
issue: that's why CI is failing (https://kibana-ci.elastic.co/job/elastic+kibana+pull-request+multijob-intake/4504/console):
12:49:04 [10:49:04] → I18N ERROR Error in src/ui/ui_render/views/ui_app.pug
12:49:04 Error: Empty defaultMessage in i18n() or i18n.translate() is not allowed ("UI-WELCOME_ERROR").
12:49:04 ERROR I18N ERROR Error in src/ui/ui_render/views/ui_app.pug
12:49:04 Error: Empty defaultMessage in i18n() or i18n.translate() is not allowed ("UI-WELCOME_ERROR").
I guess you wanted to write something like this instead
.kibanaWelcomeText(data-error-message="#{i18n('common.ui.welcomeError', { defaultMessage: 'Kibana did not load properly. Check the server output for more information.' })}")`Our tools now enforce default message for all labels that allows developers to actually see the real label content without looking into translation files. So we got rid of en.json entirely and extract all default messages automatically whenever translation vendors need them.
@pavel06081991 @maryia-lapata can you please help @srl295 to test this change (i.e where one should put and register test translation file for common.ui. etc.)? Essentially we need a localized version of this label that includes apostrophe.
There was a problem hiding this comment.
@srl295
As far as I understood, the code below doesn't really call function i18n
.kibanaWelcomeText(data-error-message="#{i18n('common.ui.welcomeErrorMessage', { defaultMessage: 'Kibana did not load properly. Check the server output for more information.' })}")
And the attribute value is displayed as it is:

If we change code to invoke i18n, like this:
.kibanaWelcomeText(data-error-message=i18n('common.ui.welcomeErrorMessage', { defaultMessage: 'Kibana did not load properly. Check the server output for more information.' }))
it will be rendered correctly (I checked with fr locale):

But i18n tool doesn't extract such message for now. @LeanidShutau just created PR #24006 to fix this.
In case you would like to check translations with custom locale, here the steps are:
- run command
node scripts/i18n_check --output ./. It will generateen.jsonfile with default translations and it place the file in the root folder. - create
fr.jsonfile, copy translations fromen.json, update messages infr.jsonaccording to locale (you can just update one or several messages). - point plugin to the translation file. For example, in
src/core_plugins/kibana/index.jsadd path tofr.jsonfile intranslationsarray:
translations: [
require('path').resolve(__dirname, './../../../fr.json')
],
- set up locale in
config/kibana.ymlby changingi18n.localeparam. (i18n.locale: "fr")
There was a problem hiding this comment.
Hey @srl295! Please let us know if you need any help with this PR. We intend to ship fix for this issue in the 6.6 release, but If you don't have time that's fine too! Someone from the i18n team will just take it over.
💔 Build Failed |
Fixes: #10580