Socket
Socket
Sign inDemoInstall

@wordpress/i18n

Package Overview
Dependencies
8
Maintainers
5
Versions
143
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @wordpress/i18n

WordPress i18n library


Version published
Maintainers
5
Install size
2.01 MB
Created

Readme

Source

@wordpress/i18n

Internationalization utilities for client-side localization.

https://codex.wordpress.org/I18n_for_WordPress_Developers

Installation

Install the module:

npm install @wordpress/i18n --save
import { sprintf, _n } from '@wordpress/i18n';

sprintf( _n( '%d hat', '%d hats', 4, 'text-domain' ), 4 );
// 4 hats

Note that you will not need to specify domain for the strings.

Build

You can use the WordPress i18n babel plugin to generate a .pot file containing all your localized strings.

The package also includes a pot-to-php script used to generate a php files containing the messages listed in a .pot file. This is useful to trick WordPress.org translation strings discovery since at the moment, WordPress.org is not capable of parsing strings directly from JavaScript files.

npx pot-to-php languages/myplugin.pot languages/myplugin-translations.php text-domain

API

__( text: string, domain: string ): string

Retrieve the translation of text.

See: https://developer.wordpress.org/reference/functions/__/

_x( text: string, context: string, domain: string ): string

Retrieve translated string with gettext context.

See: https://developer.wordpress.org/reference/functions/_x/

_n( single: string, plural: string, number: Number, domain: string ): string

Translates and retrieves the singular or plural form based on the supplied number.

See: https://developer.wordpress.org/reference/functions/_n/

_nx( single: string, plural: string, number: Number, context: string, domain: string ): string

Translates and retrieves the singular or plural form based on the supplied number, with gettext context.

See: https://developer.wordpress.org/reference/functions/_nx/

sprintf( format: string, ...args: mixed[] ): string

Returns a formatted string.

See: http://www.diveintojavascript.com/projects/javascript-sprintf

setLocaleData( data: Object, domain: string )

Creates a new Jed instance with specified locale data configuration.

getI18n(): Jed

Returns the current Jed instance, initializing with a default configuration if not already assigned.

See: http://messageformat.github.io/Jed/



Code is Poetry.

Keywords

FAQs

Last updated on 04 Apr 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc