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

Fixes plural messages POT generation. #13577

Merged
merged 3 commits into from
Jan 30, 2019
Merged

Fixes plural messages POT generation. #13577

merged 3 commits into from
Jan 30, 2019

Conversation

zinigor
Copy link
Contributor

@zinigor zinigor commented Jan 29, 2019

Description

In order for POT files to be generated with proper plural string templates, the nplurals variable had to be cast to int.

How has this been tested?

To test you will need to have a test file that uses plural i18n functions:


/**
 * External dependencies
 */
import { _n, _nx } from '@wordpress/i18n';

_n( 'Singular string', 'Plural string', 'textdomain' );
_nx( 'Singular string', 'Plural string', 'context', 'textdomain' );

Also you need to be using the makepot plugin in your project when processing files with Babel:

 [
		'@wordpress/babel-plugin-makepot',
		{
			output: 'gettext.pot'
			headers: {
				'content-type': 'text/plain; charset=UTF-8',
				'plural-forms': 'nplurals=2; plural=n == 1 ? 0 : 1;',
			},
		},
	]

After you have set up your repository, run babel against this file:

$ npx babel test.js 
"use strict";

var _i18n = require("@wordpress/i18n");

/**
 * External dependencies
 */
(0, _i18n._n)('Singular string', 'Plural string', 'textdomain');
(0, _i18n._nx)('Singular string', 'Plural string', 'context', 'textdomain');

You will have an gettext.pot file generated in the folder where you ran the script from, it will have the following lines:

msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"X-Generator: calypso\n"
"Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;\n"

#: test.js:8
msgid "Singular string"
msgid_plural "Plural string"
msgstr[0] ""

#: test.js:9
msgctxt "textdomain"
msgid "Singular string"
msgid_plural "Plural string"
msgstr[0] ""

Notice how the msgstr entry is only one per message, and there should be two of them, based on the nplurals setting in the header. Roll this patch on, see the different result:

msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"X-Generator: calypso\n"
"Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;\n"

#: test.js:8
msgid "Singular string"
msgid_plural "Plural string"
msgstr[0] ""
msgstr[1] ""

#: test.js:9
msgctxt "textdomain"
msgid "Singular string"
msgid_plural "Plural string"
msgstr[0] ""
msgstr[1] ""

Types of changes

  • Minor change to the babel-plugin-makepot package: bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@Soean Soean added the Internationalization (i18n) Issues or PRs related to internationalization efforts label Jan 29, 2019
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Could you please add an entry to packages/babel-plugin-makepot/CHANGELOG.md describing the bug fix?

See also: https://github.com/WordPress/gutenberg/blob/master/packages/README.md#maintaining-changelogs

packages/babel-plugin-makepot/src/index.js Outdated Show resolved Hide resolved
@aduth aduth added the [Package] Babel plugin makepot /packages/babel-plugin-makepot label Jan 30, 2019
@zinigor
Copy link
Contributor Author

zinigor commented Jan 30, 2019

Thanks for the review, Andrew! I have moved parseInt, as well as added a CHANGELOG entry.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! 👍

@aduth aduth merged commit 5a8d276 into WordPress:master Jan 30, 2019
@aduth aduth deleted the fix/makepot-plurals-parseint branch January 30, 2019 15:12
daniloercoli added a commit that referenced this pull request Jan 30, 2019
…rnmobile/372-use-RichText-on-Title-block

* 'master' of https://github.com/WordPress/gutenberg: (36 commits)
  Fixes plural messages POT generation. (#13577)
  Typo fix (#13595)
  REST API: Remove oEmbed proxy HTML filtering (#13575)
  Removed unnecessary className attribute. Fixes #11664 (#11831)
  Add changelog for RSS block (#13588)
  Components: Set type=button for TabPanel button elements. (#11944)
  Update util.js (#13582)
  Docs: Add accessbility specific page (#13169)
  Rnmobile/media methods refactor (#13554)
  chore(release): publish
  chore(release): publish
  Plugin: Deprecate gutenberg_get_script_polyfill (#13536)
  Block API: Parse entity only when valid character reference (#13512)
  RichText: List: fix indentation (#13563)
  Plugin: Deprecate window._wpLoadGutenbergEditor (#13547)
  Plugin: Avoid setting generic "Edit Post" title on load (#13552)
  Plugin: Populate demo content by default content filters (#13553)
  RichText: List: Fix getParentIndex (#13562)
  RichText: List: Fix outdent with children (#13559)
  Scripts: Remove npm run build from test-e2e default run (#13420)
  ...
@youknowriad youknowriad added this to the 5.0 (Gutenberg) milestone Feb 4, 2019
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Fixes plural messages POT generation.

* Moved the parseInt statement to the assignment.

* Added the CHANGELOG.md entry.
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Fixes plural messages POT generation.

* Moved the parseInt statement to the assignment.

* Added the CHANGELOG.md entry.
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 [Package] Babel plugin makepot /packages/babel-plugin-makepot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants