-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Convert private WebUI strings to i18next #20610
base: master
Are you sure you want to change the base?
[WIP] Convert private WebUI strings to i18next #20610
Conversation
Search: (<((?!class=).)*?)>QBT_TR\((.+?)\)QBT_TR(\[CONTEXT=.+?\])? Replace: $1 class="qbt-translatable" data-i18n="$3">$3 File glob: src/webui/www/private/**/*.html
Search: (<.+?class=".+?)(".*?)>QBT_TR\((.+?)\)QBT_TR(\[CONTEXT=.+?\])? Replace: $1 qbt-translatable$2 data-i18n="$3">$3 File glob: src/webui/www/private/**/*.html
Search: (<(?:(?!class=).)+?)(\S+?)="QBT_TR\((.+?)\)QBT_TR(?:\[CONTEXT=.+?\])?" Replace: $1class="qbt-translatable" data-i18n="[$2]$3" $2="$3" File glob: src/webui/www/private/**/*.html
Search: (<.+?class=".+?)(".*?)(\S+?)="QBT_TR\((.+?)\)QBT_TR(?:\[CONTEXT=.+?\])?" Replace: $1 qbt-translatable$2data-i18n="[$3]$4" $3="$4" File glob: src/webui/www/private/**/*.html
Search: (<.+?data-i18n=".+?)(".*?)(\S+?)="QBT_TR\((.+?)\)QBT_TR(?:\[CONTEXT=.+?\])?" Replace: $1;[$3]$4$2$3="$4" File glob: src/webui/www/private/**/*.html
Search: (["'])QBT_TR\((.+?)\)QBT_TR(?:\[CONTEXT=.+?\])?\1 Replace: i18next.t($1$2$1) File glob: src/webui/www/private/**/*.html
Manual conversion to template literal Search: (["'])QBT_TR\((.+?)\)QBT_TR(?:\[CONTEXT=.+?\])?\s*?\1 Replace: i18next.t($1$2$1) File glob: src/webui/www/private/**/*.html
Search: `(.*?)QBT_TR\((.+?)\)QBT_TR(?:\[CONTEXT=.+?\])? Replace: `$1\${i18next.t('$2')} File glob: src/webui/www/private/**/*.html
Search: (["'])(\s*? )?QBT_TR\((.+?)\)QBT_TR(?:\[CONTEXT=.+?\])?((\\n)*?)\1 Replace: `$2${i18next.t($1$3$1)}$4` File glob: src/webui/www/private/**/*.html
Search: (["'])QBT_TR\((.+?)\)QBT_TR(?:\[CONTEXT=.+?\])?\1 Replace: i18next.t($1$2$1) File glob: src/webui/www/private/**/*.js
Search: (["'])(\s*? )?QBT_TR\((.+?)\)QBT_TR(?:\[CONTEXT=.+?\])?\1 Replace: `$2${i18next.t($1$3$1)}` File glob: src/webui/www/private/**/*.js
Manual conversion
Damn it. I worked on an older state of the master branch. |
@Chocobo1 // remove any leading [] in the key
key = key.replace(/^\[[a-zA-Z0-9_-]*\]/, '')
// if empty grab innerHTML from regex
key = key || $node.text() So we can probably de-duplicate the HTML files. Instead of doing this: <p class="random qbt-translatable" data-i18n="Some text">Some text</P> we can do this: <p class="random qbt-translatable">Some text</P> And our loading function will use the .text() as key if the |
@@ -43,7 +43,7 @@ | |||
|
|||
<body> | |||
<noscript id="noscript"> | |||
<h1>QBT_TR(JavaScript Required! You must enable JavaScript for the WebUI to work properly)QBT_TR[CONTEXT=HttpServer]</h1> | |||
<h1 class="qbt-translatable" data-i18n="JavaScript Required! You must enable JavaScript for the WebUI to work properly">JavaScript Required! You must enable JavaScript for the WebUI to work properly</h1> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is noscript
, no point in providing translation strings.
It seems the link was using jquery-i18next which we don't use and therefore we don't have
I tried to apply it to the public login page. There are a few issues with it:
I quickly skimmed through the changes. It seems that the Or perhaps we really need to write our own custom string extractor... |
Yes, because we use the vanilla version. We are responsible for applying the translated strings.
I wonder if we could further optimize
I wanted to also talk about this.
The regex I have in each commit can probably be made to also capture the CONTEXT value. However, i18next's JSON format saves it as "key_context: translated string". Or you mean having our own format for runtime and extraction? This might work. I don't know how hard the implementation will be. |
Maybe this, I haven't test: https://stackoverflow.com/questions/2694640/find-an-element-in-dom-based-on-an-attribute-value
Transifex would very likely to present the full string which is not what we want for the translators. I thought about this and I reckon that the CONTEXT isn't that useful. It would be useful if the translation strings is too many to hold it in one js Object/Map and needed to use CONTEXT to access different Object/Map. <p class="qbt-translatable" data-i18n="Some text{disambiguation}">Some text</P> Extracted JSON: "Some text{disambiguation}": ""
|
I was thinking about the problem this past day and I came to a similar conclusion. |
I'll experiment on public login page first and submit a PR if the results are satisfactory.
Unless you mean to create our own string extractor, I think there are some problems with i18next context (and probably i18next-parser):
Which is why I used the form: |
Yeah, I wanted to introduce a PR this weekend too.
I have slightly different understanding on how these work and how I intend them to work:
Maybe my thoughts will be conveyed better in code. I'll try to have a PR ready today/tomorrow. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Take a look at #20643 first. |
This PR is stale because it has been 60 days with no activity. This PR will be automatically closed within 7 days if there is no further activity. |
This draft PR is meant for collaboration for the i18next transition of the WebUI private part. The public part was done with PR #20520
You can use my commits into your own work without any kind of attribution.
Each commit provides the regex I used for each converstion from
QBT_TR(string)QBT_TR
to the i18next way.There are .html files with nested elements that the regex hasn't converted. I think they need manucal conversion. About 124 instances.
Almost the same issue with the 3 remaining instances in the .js files.
@Chocobo1
For translating HTML attributes we need to do some like the following. For example:
Aka we set the
data-i18n
attribute's value to[attribute-name]string
. And if we have multiple attributes to translate for the same HTML element we separate it with;
eg[attribute-name1]string1;[attribute-name2]string2
However, I haven't tested if i18next-parser can correctly break out the different strings.
Source: https://stackoverflow.com/a/22822236/10260481
@ OTHER contributors
If you have time please take look at the diffs and try to verify the conversion.
Example:
This HTML
becomes this:
and this Javascript:
becomes this: