-
Notifications
You must be signed in to change notification settings - Fork 901
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
19701 try to come up with a solution where html tags in translations are not reliant on the order #21938
base: trunk
Are you sure you want to change the base?
Conversation
Also implements it in the site basic page
@vraja-pro Please be aware that following packages have been abandoned and are not actively maintained anymore:
Please consider using the other packages instead. |
@vraja-pro Please be aware that following packages have been abandoned and are not actively maintained anymore:
Please consider using the other packages instead. |
@vraja-pro Please be aware that following packages have been abandoned and are not actively maintained anymore:
Please consider using the other packages instead. |
@vraja-pro Please be aware that following packages have been abandoned and are not actively maintained anymore:
Please consider using the other packages instead. |
Pull Request Test Coverage Report for Build 6f62ddda7c77c1b82f39a56ab18fe791914123d5Details
💛 - Coveralls |
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.
CR 🏗️
Edit: I think the changelog entries should be user facing. Maybe not the technical one that is there now. But maybe improvement that translations will now fall back to English?
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.
As you see in the comments you got, the helpers package should not be added to.
The reason for this is that we don't want to maintain a random assortment of helpers in a helper package. If there is a need for a overarching package. You could create a specific one. The smaller and targeted, the less maintenance it needs?
Why did you add it to helpers in the first place?
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.
I was thinking it would be easier to use in the rest of the addon/premium
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.
Easier than what?
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.
We also skipped this package when improving Jest. There are missing dev deps there.
jest.mock( "@wordpress/element", () => ( { | ||
createInterpolateElement: jest.fn(), | ||
} ) ); | ||
|
||
jest.mock( "@wordpress/i18n", () => ( { | ||
sprintf: jest.fn(), | ||
} ) ); |
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.
Why mock? That seems to defeat the whole purpose.
const args = [ "world" ]; | ||
const conversionMap = { world: <span>world</span> }; | ||
const interpolatedElement = <span>Hello world</span>; |
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.
const args = [ "world" ]; | |
const conversionMap = { world: <span>world</span> }; | |
const interpolatedElement = <span>Hello world</span>; | |
const args = [ "<world />" ]; | |
const conversionMap = { world: <span>world</span> }; | |
const interpolatedElement = <>Hello <span>world</span></>; |
|
||
expect( sprintf ).toHaveBeenCalledWith( translatedString, ...args ); | ||
expect( createInterpolateElement ).toHaveBeenCalledWith( "Hello world", conversionMap ); | ||
expect( result ).toBe( interpolatedElement ); |
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.
Then this would need to be toEqual
const translatedString = "Hello %s"; | ||
const args = [ "world" ]; | ||
const conversionMap = { world: <span>world</span> }; | ||
|
||
sprintf.mockImplementation( () => { | ||
throw new Error( "Test error" ); | ||
} ); |
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.
Why mock? We have the perfect use case already, as per the issue.
const translatedString = "Hello %s"; | |
const args = [ "world" ]; | |
const conversionMap = { world: <span>world</span> }; | |
sprintf.mockImplementation( () => { | |
throw new Error( "Test error" ); | |
} ); | |
const translatedString = "Hello %2$sworld%1$s"; | |
const args = [ "<world>", "</world>" ]; | |
const conversionMap = { world: <span>world</span> }; | |
* Create an interpolated element from a translated string and catches errors. | ||
* | ||
* @param {string} translatedString The translated string to be interpolated. | ||
* @param {[string]} args The arguments to be interpolated into the translated string. |
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.
sprintf
does not need to be string only. You can use numbers and the like with %d
.
Links:
* | ||
* @returns {object} The interpolated element. | ||
*/ | ||
export const i18nCreateInterpolateElement = ( translatedString, args, conversionMap ) => { |
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.
I think the variable naming can be improved here.
Also, the needing to write args
in array form is a bit meh?
export const i18nCreateInterpolateElement = ( translatedString, args, conversionMap ) => { | ||
try { | ||
return createInterpolateElement( | ||
sprintf( |
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.
You changed this to include sprintf
.
While making the fallback easier, it does add complexity with doing two things.
This means we no longer have the option to not sprintf
when using this safer translation.
Also, if possible in the future, we could just add the HTML in the translation string? I'm not sure why we always use sprintf
now. Did you investigate this?
Can you explain a bit your reasoning and thoughts here? Or rather in the issue tech choices? 😬
I would love some more details on your choices.
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.
The breaking error is caused when using sprintf.
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.
I highly doubt that, since the source includes a try/catch around it: https://github.com/WordPress/gutenberg/blob/trunk/packages/i18n/src/sprintf.js
@@ -23,6 +23,7 @@ | |||
"license": "GPL-3.0", | |||
"private": false, | |||
"dependencies": { | |||
"@wordpress/element": "^6.14.0", |
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.
Why this version?
Our lowest support WP version is 6.5:
https://github.com/WordPress/wordpress-develop/blob/6.5.0/package.json#L113C3-L113C31
Context
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
Relevant test scenarios
Test instructions for QA when the code is in the RC
QA can test this PR by following these steps:
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
UI changes
Other environments
[shopify-seo]
, added test instructions for Shopify and attached theShopify
label to this PR.Documentation
Quality assurance
Innovation
innovation
label.Fixes Try to come up with a solution where HTML tags in translations are not reliant on the order