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

i18n Improvements #696

Merged
merged 7 commits into from Aug 11, 2016
Merged

i18n Improvements #696

merged 7 commits into from Aug 11, 2016

Conversation

ramiy
Copy link
Contributor

@ramiy ramiy commented Jul 29, 2016

update translation strings related issues.

  • Security: escaping translation strings with esc_html__() and esc_attr__().
  • Replace <a> links with %s placeholder.
  • Merge three similar translation strings into one string, and use placeholders for the links
  • Add translators comments to string with placeholders (%s, %1$s and %2$s).

@ramiy ramiy mentioned this pull request Jul 29, 2016
'name' => esc_html__( 'oEmbed', 'cmb2' ),
'desc' => sprintf(
/* translators: %s: link to codex.wordpress.org/Embeds */
esc_html__( 'Enter a youtube, twitter, or instagram URL. Supports services listed at %s.', 'cmb2' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you want to leave comments for translators, the _x() family of functions should be used. e.g.

esc_html_x( 'Enter a youtube, twitter, or instagram URL. Supports services listed at %s.', '%s is a link to codex.wordpress.org/Embeds', 'cmb2' ),

@ramiy
Copy link
Contributor Author

ramiy commented Jul 30, 2016

@jtsternberg
Actually, you are wrong.

You should never use context _x() function to describe placeholders. You should use only translator comments /* translators: %s: placeholder description */. The translator comment will appear on the sidebar:

context

As for the _x(), in WordPress core, we use context functions when a string is used in many places, but we want one of those strings to have a different meaning. When we add the context function, this string will appear as a separate string in translate.wordpress.org.

context

When using context function, It creates a new line in translate.wordpress.org, and allows you to provide a different meaning for this particular string.

@jtsternberg
Copy link
Member

Oh wow, well thank you very much for educating me! Looks like I've been using those functions improperly. I'll review this a bit more thoroughly when I get back to my computer, but should be good. Thanks again!

@jazzsequence
Copy link
Collaborator

@jtsternberg the best example of proper use of _x would be:

_x( 'Buffalo', 'textdomain', 'A city in New York.' );
_x( 'Buffalo', 'textdomain', 'A large animal that lives in North America' );

@jtsternberg jtsternberg merged commit 66ce8bf into CMB2:trunk Aug 11, 2016
@jtsternberg
Copy link
Member

Thanks for you contribution @ramiy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants