diff --git a/bin/update-readmes.js b/bin/update-readmes.js index f57bca0a0e089..cd79242c8615c 100755 --- a/bin/update-readmes.js +++ b/bin/update-readmes.js @@ -22,7 +22,7 @@ const packages = [ 'element', 'escape-html', 'html-entities', - //'i18n', + 'i18n', 'keycodes', //'plugins', //'priority-queue', diff --git a/packages/i18n/README.md b/packages/i18n/README.md index 5e57b0f4cb806..6779e866f2453 100644 --- a/packages/i18n/README.md +++ b/packages/i18n/README.md @@ -2,7 +2,7 @@ Internationalization utilities for client-side localization. -https://codex.wordpress.org/I18n_for_WordPress_Developers + ## Installation @@ -37,38 +37,129 @@ npx pot-to-php languages/myplugin.pot languages/myplugin-translations.php text-d ## API -`__( text: string, domain: string ): string` + -Retrieve the translation of text. +### setLocaleData + +[src/index.js#L45-L58](src/index.js#L45-L58) + +Merges locale data into the Tannin instance by domain. Accepts data in a +Jed-formatted JSON object shape. + +**Related** + +- + +**Parameters** + +- **data** `?Object`: Locale data configuration. +- **domain** `?string`: Domain for which configuration applies. + +### sprintf + +[src/index.js#L159-L167](src/index.js#L159-L167) + +Returns a formatted string. If an error occurs in applying the format, the +original format string is returned. + +**Related** + +- + +**Parameters** + +- **format** `string`: The format of the string to generate. +- **args** `...string`: Arguments to apply to the format. + +**Returns** + +`string`: The formatted string. + +### \_n + +[src/index.js#L125-L127](src/index.js#L125-L127) + +Translates and retrieves the singular or plural form based on the supplied +number. + +**Related** -See: https://developer.wordpress.org/reference/functions/__/ +- -`_x( text: string, context: string, domain: string ): string` +**Parameters** + +- **single** `string`: The text to be used if the number is singular. +- **plural** `string`: The text to be used if the number is plural. +- **number** `number`: The number to compare against to use either the singular or plural form. +- **domain** `?string`: Domain to retrieve the translated text. + +**Returns** + +`string`: The translated singular or plural form. + +### \_nx + +[src/index.js#L144-L146](src/index.js#L144-L146) + +Translates and retrieves the singular or plural form based on the supplied +number, with gettext context. + +**Related** + +- + +**Parameters** + +- **single** `string`: The text to be used if the number is singular. +- **plural** `string`: The text to be used if the number is plural. +- **number** `number`: The number to compare against to use either the singular or plural form. +- **context** `string`: Context information for the translators. +- **domain** `?string`: Domain to retrieve the translated text. + +**Returns** + +`string`: The translated singular or plural form. + +### \_x + +[src/index.js#L107-L109](src/index.js#L107-L109) Retrieve translated string with gettext context. -See: https://developer.wordpress.org/reference/functions/_x/ +**Related** + +- -`_n( single: string, plural: string, number: Number, domain: string ): string` +**Parameters** -Translates and retrieves the singular or plural form based on the supplied number. +- **text** `string`: Text to translate. +- **context** `string`: Context information for the translators. +- **domain** `?string`: Domain to retrieve the translated text. -See: https://developer.wordpress.org/reference/functions/_n/ +**Returns** + +`string`: Translated context string without pipe. + +### \_\_ + +[src/index.js#L92-L94](src/index.js#L92-L94) + +Retrieve the translation of text. -`_nx( single: string, plural: string, number: Number, context: string, domain: string ): string` +**Related** -Translates and retrieves the singular or plural form based on the supplied number, with gettext context. +- -See: https://developer.wordpress.org/reference/functions/_nx/ +**Parameters** -`sprintf( format: string, ...args: mixed[] ): string` +- **text** `string`: Text to translate. +- **domain** `?string`: Domain to retrieve the translated text. -Returns a formatted string. +**Returns** -See: http://www.diveintojavascript.com/projects/javascript-sprintf +`string`: Translated text. -`setLocaleData( data: Object, domain: string )` -Creates a new Jed instance with specified locale data configuration. +

Code is Poetry.

diff --git a/packages/i18n/src/index.js b/packages/i18n/src/index.js index 42266da0c9ff9..50869f49efd39 100644 --- a/packages/i18n/src/index.js +++ b/packages/i18n/src/index.js @@ -150,7 +150,7 @@ export function _nx( single, plural, number, context, domain ) { * original format string is returned. * * @param {string} format The format of the string to generate. - * @param {string[]} ...args Arguments to apply to the format. + * @param {...string} args Arguments to apply to the format. * * @see http://www.diveintojavascript.com/projects/javascript-sprintf *