Skip to content
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

Merged
merged 1 commit into from Jun 21, 2018

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Jun 7, 2018

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.

@jorgefilipecosta jorgefilipecosta added the Internationalization (i18n) Issues or PRs related to internationalization efforts label Jun 7, 2018
@jorgefilipecosta jorgefilipecosta self-assigned this Jun 7, 2018
ocean90
ocean90 previously requested changes Jun 7, 2018
Copy link
Member

@ocean90 ocean90 left a 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.

@jorgefilipecosta jorgefilipecosta force-pushed the update/improve-translatable-strings branch from 4efdfd1 to 60a9d02 Compare June 7, 2018 10:28
@jorgefilipecosta jorgefilipecosta changed the title Improve translatable strings containing "%s" to have a context Improve translatable strings containing "%s" to have a translator comment Jun 7, 2018
@jorgefilipecosta
Copy link
Member Author

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>
Copy link
Contributor

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 ?

Copy link
Member Author

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.

@jorgefilipecosta jorgefilipecosta force-pushed the update/improve-translatable-strings branch from 60a9d02 to 4faa48b Compare June 18, 2018 15:37
@jorgefilipecosta jorgefilipecosta added this to the 3.1 milestone Jun 20, 2018
Copy link
Member

@gziolo gziolo left a 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
Copy link
Member

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 __( ... ).

@gziolo gziolo dismissed ocean90’s stale review June 21, 2018 07:43

There is no usage of _x() anymore so dismissing this one to unblock PR. @ocean90 feel free to review again.

@jorgefilipecosta jorgefilipecosta force-pushed the update/improve-translatable-strings branch from 4faa48b to 9790144 Compare June 21, 2018 10:23
@jorgefilipecosta jorgefilipecosta merged commit 859f016 into master Jun 21, 2018
@jorgefilipecosta jorgefilipecosta deleted the update/improve-translatable-strings branch June 21, 2018 10:32
@jorgefilipecosta
Copy link
Member Author

Thank you for the reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants