File "l10n.php"
Full Path: /home/ycoalition/public_html/blog/wp-includes/theme-compat/l10n.php
File size: 8 KB
MIME-type: text/x-php
Charset: utf-8
<?php
/**
* Core Translation API
*
* @package WordPress
* @subpackage i18n
* @since 1.2.0
*/
/**
* 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.
*
* @since 1.5.0
*
* @global string $locale The current locale.
* @global string $wp_local_package Locale code of the package.
*
* @return string The locale of the blog or from the {@see 'locale'} hook.
*/
function get_locale() {
global $locale, $wp_local_package;
if ( isset( $locale ) ) {
/** This filter is documented in wp-includes/l10n.php */
return apply_filters( 'locale', $locale );
}
if ( isset( $wp_local_package ) ) {
$locale = $wp_local_package;
}
// WPLANG was defined in wp-config.
if ( defined( 'WPLANG' ) ) {
$locale = WPLANG;
}
// If multisite, check options.
if ( is_multisite() ) {
// Don't check blog option when installing.
if ( wp_installing() ) {
$ms_locale = get_site_option( 'WPLANG' );
} else {
$ms_locale = get_option( 'WPLANG' );
if ( false === $ms_locale ) {
$ms_locale = get_site_option( 'WPLANG' );
}
}
if ( false !== $ms_locale ) {
$locale = $ms_locale;
}
} else {
$db_locale = get_option( 'WPLANG' );
if ( false !== $db_locale ) {
$locale = $db_locale;
}
}
if ( empty( $locale ) ) {
$locale = 'en_US';
}
/**
* Filters the locale ID of the WordPress installation.
*
* @since 1.5.0
*
* @param string $locale The locale ID.
*/
return apply_filters( 'locale', $locale );
}
/**
* 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().
*
* @since 4.7.0
*
* @param int|WP_User $user User's ID or a WP_User object. Defaults to current user.
* @return string The locale of the user.
*/
function get_user_locale( $user = 0 ) {
$user_object = false;
if ( 0 === $user && function_exists( 'wp_get_current_user' ) ) {
$user_object = wp_get_current_user();
} elseif ( $user instanceof WP_User ) {
$user_object = $user;
} elseif ( $user && is_numeric( $user ) ) {
$user_object = get_user_by( 'id', $user );
}
if ( ! $user_object ) {
return get_locale();
}
$locale = $user_object->locale;
return $locale ? $locale : get_locale();
}
/**
* Determines the current locale desired for the request.
*
* @since 5.0.0
*
* @global string $pagenow The filename of the current screen.
*
* @return string The determined locale.
*/
function determine_locale() {
/**
* Filters the locale for the current request prior to the default determination process.
*
* Using this filter allows to override the default logic, effectively short-circuiting the function.
*
* @since 5.0.0
*
* @param string|null $locale The locale to return and short-circuit. Default null.
*/
$determined_locale = apply_filters( 'pre_determine_locale', null );
if ( $determined_locale && is_string( $determined_locale ) ) {
return $determined_locale;
}
if (
isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] &&
( ! empty( $_GET['wp_lang'] ) || ! empty( $_COOKIE['wp_lang'] ) )
) {
if ( ! empty( $_GET['wp_lang'] ) ) {
$determined_locale = sanitize_locale_name( $_GET['wp_lang'] );
} else {
$determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] );
}
} elseif (
is_admin() ||
( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() )
) {
$determined_locale = get_user_locale();
} elseif (
( ! empty( $_REQUEST['language'] ) || isset( $GLOBALS['wp_local_package'] ) )
&& wp_installing()
) {
if ( ! empty( $_REQUEST['language'] ) ) {
$determined_locale = sanitize_locale_name( $_REQUEST['language'] );
} else {
$determined_locale = $GLOBALS['wp_local_package'];
}
}
if ( ! $determined_locale ) {
$determined_locale = get_locale();
}
/**
* Filters the locale for the current request.
*
* @since 5.0.0
*
* @param string $determined_locale The locale.
*/
return apply_filters( 'determine_locale', $determined_locale );
}
/**
* Retrieves 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.
*
* @since 2.2.0
* @since 5.5.0 Introduced `gettext-{$domain}` filter.
*
* @param string $text Text to translate.
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
* Default 'default'.
* @return string Translated text.
*/
function translate( $text, $domain = 'default' ) {
$translations = get_translations_for_domain( $domain );
$translation = $translations->translate( $text );
/**
* Filters text with its translation.
*
* @since 2.0.11
*
* @param string $translation Translated text.
* @param string $text Text to translate.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*/
$translation = apply_filters( 'gettext', $translation, $text, $domain );
/**
* Filters text with its translation for a domain.
*
* The dynamic portion of the hook name, `$domain`, refers to the text domain.
*
* @since 5.5.0
*
* @param string $translation Translated text.
* @param string $text Text to translate.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*/
$translation = apply_filters( "gettext_{$domain}", $translation, $text, $domain );
return $translation;
}
/**
* Removes 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.
*
* @since 2.8.0
*
* @param string $text A pipe-delimited string.
* @return string Either $text or everything before the last pipe.
*/
function before_last_bar( $text ) {
$last_bar = strrpos( $text, '|' );
if ( false === $last_bar ) {
return $text;
} else {
return substr( $text, 0, $last_bar );
}
}
/**
* Retrieves 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.
*
* @since 2.8.0
* @since 5.5.0 Introduced `gettext_with_context-{$domain}` filter.
*
* @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.
* Default 'default'.
* @return string Translated text on success, original text on failure.
*/
function translate_with_gettext_context( $text, $context, $domain = 'default' ) {
$translations = get_translations_for_domain( $domain );
$translation = $translations->translate( $text, $context );
/**
* Filters text with its translation based on context information.
*
* @since 2.8.0
*
* @param string $translation Translated text.
* @param string $text Text to translate.
* @param string $context Context information for the translators.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*/
$translation = apply_filters( 'gettext_with_context', $translation, $text, $context, $domain );
/**
* Filters text with its translation based on context information for a domain.
*
* The dynamic portion of the hook name, `$domain`, refers to the text domain.
*
* @since 5.5.0
*
* @param string $translation Translated text.
* @param string $text