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: set up auto-generated API docs #14266

Merged
merged 5 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/update-readmes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const packages = [
'element',
'escape-html',
'html-entities',
//'i18n',
'i18n',
'keycodes',
//'plugins',
//'priority-queue',
Expand Down
125 changes: 108 additions & 17 deletions packages/i18n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Internationalization utilities for client-side localization.

https://codex.wordpress.org/I18n_for_WordPress_Developers
<https://codex.wordpress.org/I18n_for_WordPress_Developers>

## Installation

Expand Down Expand Up @@ -37,38 +37,129 @@ npx pot-to-php languages/myplugin.pot languages/myplugin-translations.php text-d

## API

`__( text: string, domain: string ): string`
<!-- START TOKEN(Autogenerated API docs) -->

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**

- <http://messageformat.github.io/Jed/>

**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**

- <http://www.diveintojavascript.com/projects/javascript-sprintf>

**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/__/
- <https://developer.wordpress.org/reference/functions/_n/>

`_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**

- <https://developer.wordpress.org/reference/functions/_nx/>

**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**

- <https://developer.wordpress.org/reference/functions/_x/>

`_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.

### \_\_
oandregal marked this conversation as resolved.
Show resolved Hide resolved

[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.
- <https://developer.wordpress.org/reference/functions/__/>

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.
<!-- END TOKEN(Autogenerated API docs) -->

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
2 changes: 1 addition & 1 deletion packages/i18n/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down