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
Improve translatable strings containing "%s" to have a translator comment #7201
Conversation
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 use of _x()
is incorrect here. The context function is used to distinguish the same string used in different contexts. For additional info, like explaining placeholders, a translators comment should be added.
4efdfd1
to
60a9d02
Compare
Thank you for explanation @ocean90, the code was updated to use translator comments. |
@@ -80,6 +80,7 @@ export class ServerSideRender extends Component { | |||
<Placeholder><Spinner /></Placeholder> | |||
); | |||
} else if ( response.error ) { | |||
// translators: %s: error message describing the problem | |||
return ( | |||
<Placeholder>{ sprintf( __( 'Error loading block: %s' ), response.errorMsg ) }</Placeholder> |
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.
Not sure if in JS it's the same, but ideally the translators comment should be immediately before the line where it is used e..g.:
<Placeholder>{ sprintf(
// translators: %s: error message describing the problem
__( 'Error loading block: %s' )
@ocean90 ?
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.
Hi @afercia thank you for referring this, the code was updated now translator comments are immediately before the line where they are used.
60a9d02
to
4faa48b
Compare
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.
LGTM 👍
There is one thing where we might need to move the comment closer to the translation function.
@@ -34,6 +34,7 @@ export default function editorMediaUpload( { | |||
const errorHandler = ( { file, sizeAboveLimit, generalError } ) => { | |||
let errorMsg; | |||
if ( sizeAboveLimit ) { | |||
// translators: %s: file name |
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 probably need to move it inside sprintf
just before the line with __( ... )
.
There is no usage of _x()
anymore so dismissing this one to unblock PR. @ocean90 feel free to review again.
…bing what %s means.
4faa48b
to
9790144
Compare
Thank you for the reviews! |
When we use %s in a string and it is not totally obvious what %s means when reading the rest of the string, we should provide a translator comment.
Tries to address: #5361
How has this been tested?
Only comments were added to the translations was added in this changes, some smoke testing, and the automated tests should be enough to catch problems.