[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/ -> l10n.php (summary)

Core Translation API

File Size: 1631 lines (53 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 1 file
 wp-admin/includes/translation-install.php

Defines 45 functions

  get_locale()
  get_user_locale()
  determine_locale()
  translate()
  before_last_bar()
  translate_with_gettext_context()
  __()
  esc_attr__()
  esc_html__()
  _e()
  esc_attr_e()
  esc_html_e()
  _x()
  _ex()
  esc_attr_x()
  esc_html_x()
  _n()
  _nx()
  _n_noop()
  _nx_noop()
  translate_nooped_plural()
  load_textdomain()
  unload_textdomain()
  load_default_textdomain()
  load_plugin_textdomain()
  load_muplugin_textdomain()
  load_theme_textdomain()
  load_child_theme_textdomain()
  load_script_textdomain()
  load_script_translations()
  _load_textdomain_just_in_time()
  _get_path_to_translation()
  _get_path_to_translation_from_lang_dir()
  get_translations_for_domain()
  is_textdomain_loaded()
  translate_user_role()
  get_available_languages()
  wp_get_installed_translations()
  wp_get_pomo_file_data()
  wp_dropdown_languages()
  is_rtl()
  switch_to_locale()
  restore_previous_locale()
  restore_current_locale()
  is_locale_switched()

Functions
Functions that are not part of a class:

get_locale()   X-Ref
Retrieves the current locale.

If the locale is set, then it will filter the locale in the {@see 'locale'}
filter hook and return the value.

If the locale is not set already, then the WPLANG constant is used if it is
defined. Then it is filtered through the {@see 'locale'} filter hook and
the value for the locale global set and the locale is returned.

The process to get the locale should only be done once, but the locale will
always be filtered using the {@see 'locale'} hook.

return: string The locale of the blog or from the {@see 'locale'} hook.

get_user_locale( $user_id = 0 )   X-Ref
Retrieves the locale of a user.

If the user has a locale set to a non-empty string then it will be
returned. Otherwise it returns the locale of get_locale().

return: string The locale of the user.
param: int|WP_User $user_id User's ID or a WP_User object. Defaults to current user.

determine_locale()   X-Ref
Determine the current locale desired for the request.

return: string The determined locale.

translate( $text, $domain = 'default' )   X-Ref
Retrieve the translation of $text.

If there is no translation, or the text domain isn't loaded, the original text is returned.

*Note:* Don't use translate() directly, use __() or related functions.

return: string Translated text
param: string $text   Text to translate.
param: string $domain Optional. Text domain. Unique identifier for retrieving translated strings.

before_last_bar( $string )   X-Ref
Remove last item on a pipe-delimited string.

Meant for removing the last item in a string, such as 'Role name|User role'. The original
string will be returned if no pipe '|' characters are found in the string.

return: string Either $string or everything before the last pipe.
param: string $string A pipe-delimited string.

translate_with_gettext_context( $text, $context, $domain = 'default' )   X-Ref
Retrieve the translation of $text in the context defined in $context.

If there is no translation, or the text domain isn't loaded the original
text is returned.

*Note:* Don't use translate_with_gettext_context() directly, use _x() or related functions.

return: string Translated text on success, original text on failure.
param: string $text    Text to translate.
param: string $context Context information for the translators.
param: string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.

__( $text, $domain = 'default' )   X-Ref
Retrieve the translation of $text.

If there is no translation, or the text domain isn't loaded, the original text is returned.

return: string Translated text.
param: string $text   Text to translate.
param: string $domain Optional. Text domain. Unique identifier for retrieving translated strings.

esc_attr__( $text, $domain = 'default' )   X-Ref
Retrieve the translation of $text and escapes it for safe use in an attribute.

If there is no translation, or the text domain isn't loaded, the original text is returned.

return: string Translated text on success, original text on failure.
param: string $text   Text to translate.
param: string $domain Optional. Text domain. Unique identifier for retrieving translated strings.

esc_html__( $text, $domain = 'default' )   X-Ref
Retrieve the translation of $text and escapes it for safe use in HTML output.

If there is no translation, or the text domain isn't loaded, the original text
is escaped and returned.

return: string Translated text
param: string $text   Text to translate.
param: string $domain Optional. Text domain. Unique identifier for retrieving translated strings.

_e( $text, $domain = 'default' )   X-Ref
Display translated text.

param: string $text   Text to translate.
param: string $domain Optional. Text domain. Unique identifier for retrieving translated strings.

esc_attr_e( $text, $domain = 'default' )   X-Ref
Display translated text that has been escaped for safe use in an attribute.

param: string $text   Text to translate.
param: string $domain Optional. Text domain. Unique identifier for retrieving translated strings.

esc_html_e( $text, $domain = 'default' )   X-Ref
Display translated text that has been escaped for safe use in HTML output.

param: string $text   Text to translate.
param: string $domain Optional. Text domain. Unique identifier for retrieving translated strings.

_x( $text, $context, $domain = 'default' )   X-Ref
Retrieve translated string with gettext context.

Quite a few times, there will be collisions with similar translatable text
found in more than two places, but with different translated context.

By including the context in the pot file, translators can translate the two
strings differently.

return: string Translated context string without pipe.
param: string $text    Text to translate.
param: string $context Context information for the translators.
param: string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.

_ex( $text, $context, $domain = 'default' )   X-Ref
Display translated string with gettext context.

return: string Translated context string without pipe.
param: string $text    Text to translate.
param: string $context Context information for the translators.
param: string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.

esc_attr_x( $text, $context, $domain = 'default' )   X-Ref
Translate string with gettext context, and escapes it for safe use in an attribute.

return: string Translated text
param: string $text    Text to translate.
param: string $context Context information for the translators.
param: string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.

esc_html_x( $text, $context, $domain = 'default' )   X-Ref
Translate string with gettext context, and escapes it for safe use in HTML output.

return: string Translated text.
param: string $text    Text to translate.
param: string $context Context information for the translators.
param: string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.

_n( $single, $plural, $number, $domain = 'default' )   X-Ref
Translates and retrieves the singular or plural form based on the supplied number.

Used when you want to use the appropriate form of a string based on whether a
number is singular or plural.

Example:

printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );

return: string The translated singular or plural form.
param: string $single The text to be used if the number is singular.
param: string $plural The text to be used if the number is plural.
param: int    $number The number to compare against to use either the singular or plural form.
param: string $domain Optional. Text domain. Unique identifier for retrieving translated strings.

_nx( $single, $plural, $number, $context, $domain = 'default' )   X-Ref
Translates and retrieves the singular or plural form based on the supplied number, with gettext context.

This is a hybrid of _n() and _x(). It supports context and plurals.

Used when you want to use the appropriate form of a string with context based on whether a
number is singular or plural.

Example of a generic phrase which is disambiguated via the context parameter:

printf( _nx( '%s group', '%s groups', $people, 'group of people', 'text-domain' ), number_format_i18n( $people ) );
printf( _nx( '%s group', '%s groups', $animals, 'group of animals', 'text-domain' ), number_format_i18n( $animals ) );

return: string The translated singular or plural form.
param: string $single  The text to be used if the number is singular.
param: string $plural  The text to be used if the number is plural.
param: int    $number  The number to compare against to use either the singular or plural form.
param: string $context Context information for the translators.
param: string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.

_n_noop( $singular, $plural, $domain = null )   X-Ref
Registers plural strings in POT file, but does not translate them.

Used when you want to keep structures with translatable plural
strings and use them later when the number is known.

Example:

$message = _n_noop( '%s post', '%s posts', 'text-domain' );
...
printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );

return: array {
param: string $singular Singular form to be localized.
param: string $plural   Plural form to be localized.
param: string $domain   Optional. Text domain. Unique identifier for retrieving translated strings.

_nx_noop( $singular, $plural, $context, $domain = null )   X-Ref
Registers plural strings with gettext context in POT file, but does not translate them.

Used when you want to keep structures with translatable plural
strings and use them later when the number is known.

Example of a generic phrase which is disambiguated via the context parameter:

$messages = array(
'people'  => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ),
'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ),
);
...
$message = $messages[ $type ];
printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );

return: array {
param: string $singular Singular form to be localized.
param: string $plural   Plural form to be localized.
param: string $context  Context information for the translators.
param: string $domain   Optional. Text domain. Unique identifier for retrieving translated strings.

translate_nooped_plural( $nooped_plural, $count, $domain = 'default' )   X-Ref
Translates and retrieves the singular or plural form of a string that's been registered
with _n_noop() or _nx_noop().

Used when you want to use a translatable plural string once the number is known.

Example:

$message = _n_noop( '%s post', '%s posts', 'text-domain' );
...
printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );

return: string Either $single or $plural translated text.
param: array  $nooped_plural Array with singular, plural, and context keys, usually the result of _n_noop() or _nx_noop().
param: int    $count         Number of objects.
param: string $domain        Optional. Text domain. Unique identifier for retrieving translated strings. If $nooped_plural contains

load_textdomain( $domain, $mofile )   X-Ref
Load a .mo file into the text domain $domain.

If the text domain already exists, the translations will be merged. If both
sets have the same string, the translation from the original value will be taken.

On success, the .mo file will be placed in the $l10n global by $domain
and will be a MO object.

return: bool True on success, false on failure.
param: string $domain Text domain. Unique identifier for retrieving translated strings.
param: string $mofile Path to the .mo file.

unload_textdomain( $domain )   X-Ref
Unload translations for a text domain.

return: bool Whether textdomain was unloaded.
param: string $domain Text domain. Unique identifier for retrieving translated strings.

load_default_textdomain( $locale = null )   X-Ref
Load default translated strings based on locale.

Loads the .mo file in WP_LANG_DIR constant path from WordPress root.
The translated (.mo) file is named based on the locale.

return: bool Whether the textdomain was loaded.
param: string $locale Optional. Locale to load. Default is the value of get_locale().

load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false )   X-Ref
Loads a plugin's translated strings.

If the path is not given then it will be the root of the plugin directory.

The .mo file should be named based on the text domain with a dash, and then the locale exactly.

return: bool True when textdomain is successfully loaded, false otherwise.
param: string       $domain          Unique identifier for retrieving translated strings
param: string|false $deprecated      Optional. Deprecated. Use the $plugin_rel_path parameter instead.
param: string|false $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides.

load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' )   X-Ref
Load the translated strings for a plugin residing in the mu-plugins directory.

return: bool True when textdomain is successfully loaded, false otherwise.
param: string $domain             Text domain. Unique identifier for retrieving translated strings.
param: string $mu_plugin_rel_path Optional. Relative to `WPMU_PLUGIN_DIR` directory in which the .mo

load_theme_textdomain( $domain, $path = false )   X-Ref
Load the theme's translated strings.

If the current locale exists as a .mo file in the theme's root directory, it
will be included in the translated strings by the $domain.

The .mo files must be named based on the locale exactly.

return: bool True when textdomain is successfully loaded, false otherwise.
param: string $domain Text domain. Unique identifier for retrieving translated strings.
param: string $path   Optional. Path to the directory containing the .mo file.

load_child_theme_textdomain( $domain, $path = false )   X-Ref
Load the child themes translated strings.

If the current locale exists as a .mo file in the child themes
root directory, it will be included in the translated strings by the $domain.

The .mo files must be named based on the locale exactly.

return: bool True when the theme textdomain is successfully loaded, false otherwise.
param: string $domain Text domain. Unique identifier for retrieving translated strings.
param: string $path   Optional. Path to the directory containing the .mo file.

load_script_textdomain( $handle, $domain = 'default', $path = null )   X-Ref
Loads the script translated strings.

return: false|string False if the script textdomain could not be loaded, the translated strings
param: string $handle Name of the script to register a translation domain to.
param: string $domain Optional. Text domain. Default 'default'.
param: string $path   Optional. The full file path to the directory containing translation files.

load_script_translations( $file, $handle, $domain )   X-Ref
Loads the translation data for the given script handle and text domain.

return: string|false The JSON-encoded translated strings for the given script handle and text domain. False if there are none.
param: string|false $file   Path to the translation file to load. False if there isn't one.
param: string       $handle Name of the script to register a translation domain to.
param: string       $domain The text domain.

_load_textdomain_just_in_time( $domain )   X-Ref
Loads plugin and theme textdomains just-in-time.

When a textdomain is encountered for the first time, we try to load
the translation file from `wp-content/languages`, removing the need
to call load_plugin_texdomain() or load_theme_texdomain().

return: bool True when the textdomain is successfully loaded, false otherwise.
param: string $domain Text domain. Unique identifier for retrieving translated strings.

_get_path_to_translation( $domain, $reset = false )   X-Ref
Gets the path to a translation file for loading a textdomain just in time.

Caches the retrieved results internally.

return: string|false The path to the translation file or false if no translation file was found.
param: string $domain Text domain. Unique identifier for retrieving translated strings.
param: bool   $reset  Whether to reset the internal cache. Used by the switch to locale functionality.

_get_path_to_translation_from_lang_dir( $domain )   X-Ref
Gets the path to a translation file in the languages directory for the current locale.

Holds a cached list of available .mo files to improve performance.

return: string|false The path to the translation file or false if no translation file was found.
param: string $domain Text domain. Unique identifier for retrieving translated strings.

get_translations_for_domain( $domain )   X-Ref
Return the Translations instance for a text domain.

If there isn't one, returns empty Translations instance.

return: Translations|NOOP_Translations A Translations instance.
param: string $domain Text domain. Unique identifier for retrieving translated strings.

is_textdomain_loaded( $domain )   X-Ref
Whether there are translations for the text domain.

return: bool Whether there are translations.
param: string $domain Text domain. Unique identifier for retrieving translated strings.

translate_user_role( $name, $domain = 'default' )   X-Ref
Translates role name.

Since the role names are in the database and not in the source there
are dummy gettext calls to get them into the POT file and this function
properly translates them back.

The before_last_bar() call is needed, because older installations keep the roles
using the old context format: 'Role name|User role' and just skipping the
content after the last bar is easier than fixing them in the DB. New installations
won't suffer from that problem.

return: string Translated role name on success, original name on failure.
param: string $name   The role name.
param: string $domain Optional. Text domain. Unique identifier for retrieving translated strings.

get_available_languages( $dir = null )   X-Ref
Get all available languages based on the presence of *.mo files in a given directory.

The default directory is WP_LANG_DIR.

return: array An array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names.
param: string $dir A directory to search for language files.

wp_get_installed_translations( $type )   X-Ref
Get installed translations.

Looks in the wp-content/languages directory for translations of
plugins or themes.

return: array Array of language data.
param: string $type What to search for. Accepts 'plugins', 'themes', 'core'.

wp_get_pomo_file_data( $po_file )   X-Ref
Extract headers from a PO file.

return: array PO file headers.
param: string $po_file Path to PO file.

wp_dropdown_languages( $args = array()   X-Ref
Language selector.

return: string HTML content
param: string|array $args {

is_rtl()   X-Ref
Determines whether the current locale is right-to-left (RTL).

For more information on this and similar theme functions, check out
the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
Conditional Tags} article in the Theme Developer Handbook.

return: bool Whether locale is RTL.

switch_to_locale( $locale )   X-Ref
Switches the translations according to the given locale.

return: bool True on success, false on failure.
param: string $locale The locale.

restore_previous_locale()   X-Ref
Restores the translations according to the previous locale.

return: string|false Locale on success, false on error.

restore_current_locale()   X-Ref
Restores the translations according to the original locale.

return: string|false Locale on success, false on error.

is_locale_switched()   X-Ref
Whether switch_to_locale() is in effect.

return: bool True if the locale has been switched, false otherwise.



Generated: Sat Sep 21 08:20:01 2019 Cross-referenced by PHPXref 0.7