wp/wp-includes/l10n.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 18:28:13 +0200
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
permissions -rw-r--r--
upgrade wordpress to 5.2.3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     3
 * Core Translation API
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage i18n
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     7
 * @since 1.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    11
 * Retrieves the current locale.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    13
 * If the locale is set, then it will filter the locale in the {@see 'locale'}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    14
 * filter hook and return the value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * If the locale is not set already, then the WPLANG constant is used if it is
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
 * defined. Then it is filtered through the {@see 'locale'} filter hook and
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
 * the value for the locale global set and the locale is returned.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * The process to get the locale should only be done once, but the locale will
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    21
 * always be filtered using the {@see 'locale'} hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    25
 * @global string $locale
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    26
 * @global string $wp_local_package
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    27
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    28
 * @return string The locale of the blog or from the {@see 'locale'} hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
function get_locale() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
	global $locale, $wp_local_package;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
	if ( isset( $locale ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    35
		 * Filters the locale ID of the WordPress installation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
		 * @since 1.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		 * @param string $locale The locale ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		return apply_filters( 'locale', $locale );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
	if ( isset( $wp_local_package ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
		$locale = $wp_local_package;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
	// WPLANG was defined in wp-config.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
	if ( defined( 'WPLANG' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
		$locale = WPLANG;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	// If multisite, check options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		// Don't check blog option when installing.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    56
		if ( wp_installing() || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
			$ms_locale = get_site_option( 'WPLANG' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
		if ( $ms_locale !== false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
			$locale = $ms_locale;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
		$db_locale = get_option( 'WPLANG' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
		if ( $db_locale !== false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
			$locale = $db_locale;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
	if ( empty( $locale ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		$locale = 'en_US';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
	/** This filter is documented in wp-includes/l10n.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	return apply_filters( 'locale', $locale );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    79
 * Retrieves the locale of a user.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    80
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    81
 * If the user has a locale set to a non-empty string then it will be
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    82
 * returned. Otherwise it returns the locale of get_locale().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    83
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    84
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    85
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    86
 * @param int|WP_User $user_id User's ID or a WP_User object. Defaults to current user.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    87
 * @return string The locale of the user.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    88
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    89
function get_user_locale( $user_id = 0 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    90
	$user = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
	if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    92
		$user = wp_get_current_user();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    93
	} elseif ( $user_id instanceof WP_User ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
		$user = $user_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
	} elseif ( $user_id && is_numeric( $user_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    96
		$user = get_user_by( 'id', $user_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    98
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    99
	if ( ! $user ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   100
		return get_locale();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   101
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   102
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
	$locale = $user->locale;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   104
	return $locale ? $locale : get_locale();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   105
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   106
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   108
 * Determine the current locale desired for the request.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   109
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   110
 * @since 5.0.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   111
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   112
 * @global string $pagenow
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   113
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   114
 * @return string The determined locale.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   115
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   116
function determine_locale() {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   117
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   118
	 * Filters the locale for the current request prior to the default determination process.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   119
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   120
	 * Using this filter allows to override the default logic, effectively short-circuiting the function.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   121
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   122
	 * @since 5.0.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   123
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   124
	 * @param string|null The locale to return and short-circuit, or null as default.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   125
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   126
	$determined_locale = apply_filters( 'pre_determine_locale', null );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   127
	if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   128
		return $determined_locale;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   129
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   130
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   131
	$determined_locale = get_locale();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   132
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   133
	if ( is_admin() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   134
		$determined_locale = get_user_locale();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   135
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   136
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   137
	if ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   138
		$determined_locale = get_user_locale();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   139
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   140
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   141
	if ( ! empty( $_GET['wp_lang'] ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   142
		$determined_locale = sanitize_text_field( $_GET['wp_lang'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   143
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   144
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   145
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   146
	 * Filters the locale for the current request.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   147
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   148
	 * @since 5.0.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   149
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   150
	 * @param string $locale The locale.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   151
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   152
	return apply_filters( 'determine_locale', $determined_locale );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   153
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   154
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   155
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 * Retrieve the translation of $text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
 * If there is no translation, or the text domain isn't loaded, the original text is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   160
 * *Note:* Don't use translate() directly, use __() or related functions.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   166
 *                       Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
 * @return string Translated text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
function translate( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	$translations = get_translations_for_domain( $domain );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   171
	$translation  = $translations->translate( $text );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   174
	 * Filters text with its translation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
	 * @since 2.0.11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   178
	 * @param string $translation  Translated text.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	 * @param string $text         Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	 * @param string $domain       Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
	return apply_filters( 'gettext', $translation, $text, $domain );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
 * Remove last item on a pipe-delimited string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
 * Meant for removing the last item in a string, such as 'Role name|User role'. The original
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
 * string will be returned if no pipe '|' characters are found in the string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
 * @param string $string A pipe-delimited string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
 * @return string Either $string or everything before the last pipe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
function before_last_bar( $string ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
	$last_bar = strrpos( $string, '|' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   198
	if ( false === $last_bar ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
		return $string;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   200
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		return substr( $string, 0, $last_bar );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   202
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
 * Retrieve the translation of $text in the context defined in $context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
 * If there is no translation, or the text domain isn't loaded the original
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
 * text is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
 * *Note:* Don't use translate_with_gettext_context() directly, use _x() or related functions.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   212
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   218
 *                        Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
 * @return string Translated text on success, original text on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
function translate_with_gettext_context( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
	$translations = get_translations_for_domain( $domain );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   223
	$translation  = $translations->translate( $text, $context );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   225
	 * Filters text with its translation based on context information.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   229
	 * @param string $translation  Translated text.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
	 * @param string $text         Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	 * @param string $context      Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
	 * @param string $domain       Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   234
	return apply_filters( 'gettext_with_context', $translation, $text, $context, $domain );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   238
 * Retrieve the translation of $text.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   239
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   240
 * If there is no translation, or the text domain isn't loaded, the original text is returned.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   246
 *                       Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
 * @return string Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
function __( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
	return translate( $text, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
 * Retrieve the translation of $text and escapes it for safe use in an attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
 * If there is no translation, or the text domain isn't loaded, the original text is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   262
 *                       Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
 * @return string Translated text on success, original text on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
function esc_attr__( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	return esc_attr( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
 * Retrieve the translation of $text and escapes it for safe use in HTML output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   272
 * If there is no translation, or the text domain isn't loaded, the original text
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   273
 * is escaped and returned.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   279
 *                       Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 * @return string Translated text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
function esc_html__( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
	return esc_html( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
 * Display translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   293
 *                       Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
function _e( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
	echo translate( $text, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
 * Display translated text that has been escaped for safe use in an attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   306
 *                       Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
function esc_attr_e( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	echo esc_attr( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
 * Display translated text that has been escaped for safe use in HTML output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   319
 *                       Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
function esc_html_e( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
	echo esc_html( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
 * Retrieve translated string with gettext context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
 * Quite a few times, there will be collisions with similar translatable text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
 * found in more than two places, but with different translated context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
 * By including the context in the pot file, translators can translate the two
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
 * strings differently.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
 *                        Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
 * @return string Translated context string without pipe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
function _x( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	return translate_with_gettext_context( $text, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
 * Display translated string with gettext context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   354
 *                        Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
 * @return string Translated context string without pipe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
function _ex( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
	echo _x( $text, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
 * Translate string with gettext context, and escapes it for safe use in an attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   369
 *                        Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
 * @return string Translated text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
function esc_attr_x( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
	return esc_attr( translate_with_gettext_context( $text, $context, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
 * Translate string with gettext context, and escapes it for safe use in HTML output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   384
 *                        Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
 * @return string Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
function esc_html_x( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
	return esc_html( translate_with_gettext_context( $text, $context, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   392
 * Translates and retrieves the singular or plural form based on the supplied number.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   394
 * Used when you want to use the appropriate form of a string based on whether a
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   395
 * number is singular or plural.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   396
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   397
 * Example:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   398
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
 *     printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   403
 * @param string $single The text to be used if the number is singular.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   404
 * @param string $plural The text to be used if the number is plural.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   405
 * @param int    $number The number to compare against to use either the singular or plural form.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   407
 *                       Default 'default'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   408
 * @return string The translated singular or plural form.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
function _n( $single, $plural, $number, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	$translations = get_translations_for_domain( $domain );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   412
	$translation  = $translations->translate_plural( $single, $plural, $number );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   413
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   415
	 * Filters the singular or plural form of a string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	 * @param string $translation Translated text.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   420
	 * @param string $single      The text to be used if the number is singular.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   421
	 * @param string $plural      The text to be used if the number is plural.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   422
	 * @param string $number      The number to compare against to use either the singular or plural form.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
	return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   429
 * Translates and retrieves the singular or plural form based on the supplied number, with gettext context.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   430
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   431
 * This is a hybrid of _n() and _x(). It supports context and plurals.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   433
 * Used when you want to use the appropriate form of a string with context based on whether a
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   434
 * number is singular or plural.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   435
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   436
 * Example of a generic phrase which is disambiguated via the context parameter:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   437
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   438
 *     printf( _nx( '%s group', '%s groups', $people, 'group of people', 'text-domain' ), number_format_i18n( $people ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   439
 *     printf( _nx( '%s group', '%s groups', $animals, 'group of animals', 'text-domain' ), number_format_i18n( $animals ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   443
 * @param string $single  The text to be used if the number is singular.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   444
 * @param string $plural  The text to be used if the number is plural.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   445
 * @param int    $number  The number to compare against to use either the singular or plural form.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   448
 *                        Default 'default'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   449
 * @return string The translated singular or plural form.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   451
function _nx( $single, $plural, $number, $context, $domain = 'default' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	$translations = get_translations_for_domain( $domain );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   453
	$translation  = $translations->translate_plural( $single, $plural, $number, $context );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   454
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   456
	 * Filters the singular or plural form of a string with gettext context.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
	 * @param string $translation Translated text.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   461
	 * @param string $single      The text to be used if the number is singular.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   462
	 * @param string $plural      The text to be used if the number is plural.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   463
	 * @param string $number      The number to compare against to use either the singular or plural form.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
	 * @param string $context     Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
	return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   471
 * Registers plural strings in POT file, but does not translate them.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
 * Used when you want to keep structures with translatable plural
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   474
 * strings and use them later when the number is known.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
 * Example:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   478
 *     $message = _n_noop( '%s post', '%s posts', 'text-domain' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
 *     ...
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   480
 *     printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   484
 * @param string $singular Singular form to be localized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   485
 * @param string $plural   Plural form to be localized.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
 * @param string $domain   Optional. Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   487
 *                         Default null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   488
 * @return array {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   489
 *     Array of translation information for the strings.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   490
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   491
 *     @type string $0        Singular form to be localized. No longer used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   492
 *     @type string $1        Plural form to be localized. No longer used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   493
 *     @type string $singular Singular form to be localized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   494
 *     @type string $plural   Plural form to be localized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   495
 *     @type null   $context  Context information for the translators.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   496
 *     @type string $domain   Text domain.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   497
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
function _n_noop( $singular, $plural, $domain = null ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   500
	return array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   501
		0          => $singular,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   502
		1          => $plural,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   503
		'singular' => $singular,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   504
		'plural'   => $plural,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   505
		'context'  => null,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   506
		'domain'   => $domain,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   507
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   511
 * Registers plural strings with gettext context in POT file, but does not translate them.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   512
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   513
 * Used when you want to keep structures with translatable plural
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   514
 * strings and use them later when the number is known.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   515
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   516
 * Example of a generic phrase which is disambiguated via the context parameter:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   517
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   518
 *     $messages = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   519
 *          'people'  => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   520
 *          'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   521
 *     );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   522
 *     ...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   523
 *     $message = $messages[ $type ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   524
 *     printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
 * @since 2.8.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   527
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   528
 * @param string $singular Singular form to be localized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   529
 * @param string $plural   Plural form to be localized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   530
 * @param string $context  Context information for the translators.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   531
 * @param string $domain   Optional. Text domain. Unique identifier for retrieving translated strings.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   532
 *                         Default null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   533
 * @return array {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   534
 *     Array of translation information for the strings.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   535
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   536
 *     @type string $0        Singular form to be localized. No longer used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   537
 *     @type string $1        Plural form to be localized. No longer used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   538
 *     @type string $2        Context information for the translators. No longer used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   539
 *     @type string $singular Singular form to be localized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   540
 *     @type string $plural   Plural form to be localized.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   541
 *     @type string $context  Context information for the translators.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   542
 *     @type string $domain   Text domain.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   543
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
function _nx_noop( $singular, $plural, $context, $domain = null ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   546
	return array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   547
		0          => $singular,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   548
		1          => $plural,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   549
		2          => $context,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   550
		'singular' => $singular,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   551
		'plural'   => $plural,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   552
		'context'  => $context,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   553
		'domain'   => $domain,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   554
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   558
 * Translates and retrieves the singular or plural form of a string that's been registered
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   559
 * with _n_noop() or _nx_noop().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   560
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   561
 * Used when you want to use a translatable plural string once the number is known.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   562
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   563
 * Example:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   564
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   565
 *     $message = _n_noop( '%s post', '%s posts', 'text-domain' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   566
 *     ...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   567
 *     printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   571
 * @param array  $nooped_plural Array with singular, plural, and context keys, usually the result of _n_noop() or _nx_noop().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   572
 * @param int    $count         Number of objects.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
 * @param string $domain        Optional. Text domain. Unique identifier for retrieving translated strings. If $nooped_plural contains
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   574
 *                              a text domain passed to _n_noop() or _nx_noop(), it will override this value. Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
 * @return string Either $single or $plural translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   578
	if ( $nooped_plural['domain'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
		$domain = $nooped_plural['domain'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   580
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   582
	if ( $nooped_plural['context'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   584
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
		return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   586
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
 * Load a .mo file into the text domain $domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
 * If the text domain already exists, the translations will be merged. If both
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
 * sets have the same string, the translation from the original value will be taken.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
 * On success, the .mo file will be placed in the $l10n global by $domain
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
 * and will be a MO object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   600
 * @global MO[] $l10n          An array of all currently loaded text domains.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   601
 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   602
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
 * @param string $mofile Path to the .mo file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
 * @return bool True on success, false on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
function load_textdomain( $domain, $mofile ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   608
	global $l10n, $l10n_unloaded;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   609
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   610
	$l10n_unloaded = (array) $l10n_unloaded;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   613
	 * Filters whether to override the .mo file loading.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   617
	 * @param bool   $override Whether to override the .mo file loading. Default false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   618
	 * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   619
	 * @param string $mofile   Path to the MO file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
	$plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
	if ( true == $plugin_override ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   624
		unset( $l10n_unloaded[ $domain ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   625
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	 * Fires before the MO translation file is loaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	 * @param string $mofile Path to the .mo file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
	do_action( 'load_textdomain', $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   640
	 * Filters MO file path for loading translations for a specific text domain.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	 * @param string $mofile Path to the MO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
	$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   649
	if ( ! is_readable( $mofile ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   650
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   651
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	$mo = new MO();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   654
	if ( ! $mo->import_from_file( $mofile ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   655
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   656
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   658
	if ( isset( $l10n[ $domain ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   659
		$mo->merge_with( $l10n[ $domain ] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   660
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   662
	unset( $l10n_unloaded[ $domain ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   663
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   664
	$l10n[ $domain ] = &$mo;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
 * Unload translations for a text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   674
 * @global MO[] $l10n          An array of all currently loaded text domains.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   675
 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   676
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
 * @return bool Whether textdomain was unloaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
function unload_textdomain( $domain ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   681
	global $l10n, $l10n_unloaded;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   682
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   683
	$l10n_unloaded = (array) $l10n_unloaded;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   686
	 * Filters whether to override the text domain unloading.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   690
	 * @param bool   $override Whether to override the text domain unloading. Default false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   691
	 * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
	$plugin_override = apply_filters( 'override_unload_textdomain', false, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   695
	if ( $plugin_override ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   696
		$l10n_unloaded[ $domain ] = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   697
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
		return true;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   699
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
	 * Fires before the text domain is unloaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
	do_action( 'unload_textdomain', $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   710
	if ( isset( $l10n[ $domain ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   711
		unset( $l10n[ $domain ] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   712
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   713
		$l10n_unloaded[ $domain ] = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   714
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
 * Load default translated strings based on locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
 * Loads the .mo file in WP_LANG_DIR constant path from WordPress root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
 * The translated (.mo) file is named based on the locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
 * @see load_textdomain()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
 * @since 1.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   730
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   731
 * @param string $locale Optional. Locale to load. Default is the value of get_locale().
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   732
 * @return bool Whether the textdomain was loaded.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   734
function load_default_textdomain( $locale = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   735
	if ( null === $locale ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   736
		$locale = determine_locale();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   737
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   739
	// Unload previously loaded strings so we can switch translations.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   740
	unload_textdomain( 'default' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   741
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   742
	$return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   744
	if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
		load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   746
		return $return;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   749
	if ( is_admin() || wp_installing() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
		load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   753
	if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
		load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   755
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   757
	return $return;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   761
 * Loads a plugin's translated strings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
 * If the path is not given then it will be the root of the plugin directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
 * The .mo file should be named based on the text domain with a dash, and then the locale exactly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
 * @since 1.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   768
 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   770
 * @param string       $domain          Unique identifier for retrieving translated strings
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   771
 * @param string|false $deprecated      Optional. Deprecated. Use the $plugin_rel_path parameter instead.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   772
 *                                      Default false.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   773
 * @param string|false $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   774
 *                                      Default false.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
 * @return bool True when textdomain is successfully loaded, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   779
	 * Filters a plugin's locale.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
	 * @param string $locale The plugin's current locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   786
	$locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   787
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   788
	$mofile = $domain . '-' . $locale . '.mo';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   790
	// Try to load from the languages directory first.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   791
	if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   792
		return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   793
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   794
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   795
	if ( false !== $plugin_rel_path ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
		$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   797
	} elseif ( false !== $deprecated ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   798
		_deprecated_argument( __FUNCTION__, '2.7.0' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
		$path = ABSPATH . trim( $deprecated, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
		$path = WP_PLUGIN_DIR;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   804
	return load_textdomain( $domain, $path . '/' . $mofile );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
 * Load the translated strings for a plugin residing in the mu-plugins directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   811
 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
 * @param string $domain             Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   814
 * @param string $mu_plugin_rel_path Optional. Relative to `WPMU_PLUGIN_DIR` directory in which the .mo
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   815
 *                                   file resides. Default empty string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
 * @return bool True when textdomain is successfully loaded, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   819
	/** This filter is documented in wp-includes/l10n.php */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   820
	$locale = apply_filters( 'plugin_locale', determine_locale(), $domain );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
	$mofile = $domain . '-' . $locale . '.mo';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   824
	// Try to load from the languages directory first.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   825
	if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   826
		return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   827
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   828
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   829
	$path = WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   830
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   831
	return load_textdomain( $domain, $path . '/' . $mofile );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
 * Load the theme's translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
 * If the current locale exists as a .mo file in the theme's root directory, it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
 * will be included in the translated strings by the $domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
 * The .mo files must be named based on the locale exactly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
 * @since 1.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   843
 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
 * @param string $path   Optional. Path to the directory containing the .mo file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
 *                       Default false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
 * @return bool True when textdomain is successfully loaded, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
function load_theme_textdomain( $domain, $path = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   852
	 * Filters a theme's locale.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
	 * @param string $locale The theme's current locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   859
	$locale = apply_filters( 'theme_locale', determine_locale(), $domain );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   861
	$mofile = $domain . '-' . $locale . '.mo';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   863
	// Try to load from the languages directory first.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   864
	if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   865
		return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   866
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   868
	if ( ! $path ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   869
		$path = get_template_directory();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   870
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   871
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   872
	return load_textdomain( $domain, $path . '/' . $locale . '.mo' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
 * Load the child themes translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
 * If the current locale exists as a .mo file in the child themes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
 * root directory, it will be included in the translated strings by the $domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
 * The .mo files must be named based on the locale exactly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   886
 * @param string $path   Optional. Path to the directory containing the .mo file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   887
 *                       Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
 * @return bool True when the theme textdomain is successfully loaded, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
function load_child_theme_textdomain( $domain, $path = false ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   891
	if ( ! $path ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
		$path = get_stylesheet_directory();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   893
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
	return load_theme_textdomain( $domain, $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   898
 * Loads the script translated strings.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   899
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   900
 * @since 5.0.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   901
 * @since 5.0.2 Uses load_script_translations() to load translation data.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   902
 * @since 5.1.0 The `$domain` parameter was made optional.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   903
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   904
 * @see WP_Scripts::set_translations()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   905
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   906
 * @param string $handle Name of the script to register a translation domain to.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   907
 * @param string $domain Optional. Text domain. Default 'default'.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   908
 * @param string $path   Optional. The full file path to the directory containing translation files.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   909
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   910
 * @return false|string False if the script textdomain could not be loaded, the translated strings
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   911
 *                      in JSON encoding otherwise.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   912
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   913
function load_script_textdomain( $handle, $domain = 'default', $path = null ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   914
	$wp_scripts = wp_scripts();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   915
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   916
	if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   917
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   918
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   919
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   920
	$path   = untrailingslashit( $path );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   921
	$locale = determine_locale();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   922
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   923
	// If a path was given and the handle file exists simply return it.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   924
	$file_base       = $domain === 'default' ? $locale : $domain . '-' . $locale;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   925
	$handle_filename = $file_base . '-' . $handle . '.json';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   926
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   927
	if ( $path ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   928
		$translations = load_script_translations( $path . '/' . $handle_filename, $handle, $domain );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   929
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   930
		if ( $translations ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   931
			return $translations;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   932
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   933
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   934
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   935
	$src = $wp_scripts->registered[ $handle ]->src;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   936
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   937
	if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   938
		$src = $wp_scripts->base_url . $src;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   939
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   940
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   941
	$relative       = false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   942
	$languages_path = WP_LANG_DIR;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   943
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   944
	$src_url     = wp_parse_url( $src );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   945
	$content_url = wp_parse_url( content_url() );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   946
	$site_url    = wp_parse_url( site_url() );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   947
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   948
	// If the host is the same or it's a relative URL.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   949
	if (
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   950
		strpos( $src_url['path'], $content_url['path'] ) === 0 &&
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   951
		( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   952
	) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   953
		// Make the src relative the specific plugin or theme.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   954
		$relative = trim( substr( $src_url['path'], strlen( $content_url['path'] ) ), '/' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   955
		$relative = explode( '/', $relative );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   956
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   957
		$languages_path = WP_LANG_DIR . '/' . $relative[0];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   958
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   959
		$relative = array_slice( $relative, 2 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   960
		$relative = implode( '/', $relative );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   961
	} elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   962
		if ( ! isset( $site_url['path'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   963
			$relative = trim( $src_url['path'], '/' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   964
		} elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   965
			// Make the src relative to the WP root.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   966
			$relative = substr( $src_url['path'], strlen( $site_url['path'] ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   967
			$relative = trim( $relative, '/' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   968
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   969
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   970
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   971
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   972
	 * Filters the relative path of scripts used for finding translation files.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   973
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   974
	 * @since 5.0.2
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   975
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   976
	 * @param string $relative The relative path of the script. False if it could not be determined.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   977
	 * @param string $src      The full source url of the script.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   978
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   979
	$relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   980
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   981
	// If the source is not from WP.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   982
	if ( false === $relative ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   983
		return load_script_translations( false, $handle, $domain );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   984
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   985
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   986
	// Translations are always based on the unminified filename.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   987
	if ( substr( $relative, -7 ) === '.min.js' ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   988
		$relative = substr( $relative, 0, -7 ) . '.js';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   989
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   990
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   991
	$md5_filename = $file_base . '-' . md5( $relative ) . '.json';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   992
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   993
	if ( $path ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   994
		$translations = load_script_translations( $path . '/' . $md5_filename, $handle, $domain );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   995
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   996
		if ( $translations ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   997
			return $translations;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   998
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   999
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1000
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1001
	$translations = load_script_translations( $languages_path . '/' . $md5_filename, $handle, $domain );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1002
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1003
	if ( $translations ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1004
		return $translations;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1005
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1006
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1007
	return load_script_translations( false, $handle, $domain );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1008
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1009
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1010
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1011
 * Loads the translation data for the given script handle and text domain.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1012
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1013
 * @since 5.0.2
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1014
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1015
 * @param string|false $file   Path to the translation file to load. False if there isn't one.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1016
 * @param string       $handle Name of the script to register a translation domain to.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1017
 * @param string       $domain The text domain.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1018
 * @return string|false The JSON-encoded translated strings for the given script handle and text domain. False if there are none.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1019
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1020
function load_script_translations( $file, $handle, $domain ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1021
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1022
	 * Pre-filters script translations for the given file, script handle and text domain.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1023
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1024
	 * Returning a non-null value allows to override the default logic, effectively short-circuiting the function.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1025
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1026
	 * @since 5.0.2
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1027
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1028
	 * @param string|false $translations JSON-encoded translation data. Default null.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1029
	 * @param string|false $file         Path to the translation file to load. False if there isn't one.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1030
	 * @param string       $handle       Name of the script to register a translation domain to.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1031
	 * @param string       $domain       The text domain.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1032
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1033
	$translations = apply_filters( 'pre_load_script_translations', null, $file, $handle, $domain );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1034
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1035
	if ( null !== $translations ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1036
		return $translations;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1037
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1038
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1039
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1040
	 * Filters the file path for loading script translations for the given script handle and text domain.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1041
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1042
	 * @since 5.0.2
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1043
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1044
	 * @param string|false $file   Path to the translation file to load. False if there isn't one.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1045
	 * @param string       $handle Name of the script to register a translation domain to.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1046
	 * @param string       $domain The text domain.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1047
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1048
	$file = apply_filters( 'load_script_translation_file', $file, $handle, $domain );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1049
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1050
	if ( ! $file || ! is_readable( $file ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1051
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1052
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1053
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1054
	$translations = file_get_contents( $file );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1055
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1056
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1057
	 * Filters script translations for the given file, script handle and text domain.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1058
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1059
	 * @since 5.0.2
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1060
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1061
	 * @param string $translations JSON-encoded translation data.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1062
	 * @param string $file         Path to the translation file that was loaded.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1063
	 * @param string $handle       Name of the script to register a translation domain to.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1064
	 * @param string $domain       The text domain.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1065
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1066
	return apply_filters( 'load_script_translations', $translations, $file, $handle, $domain );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1067
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1068
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1069
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1070
 * Loads plugin and theme textdomains just-in-time.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1071
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1072
 * When a textdomain is encountered for the first time, we try to load
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1073
 * the translation file from `wp-content/languages`, removing the need
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1074
 * to call load_plugin_texdomain() or load_theme_texdomain().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1075
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1076
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1077
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1078
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1079
 * @see get_translations_for_domain()
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1080
 * @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1081
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1082
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1083
 * @return bool True when the textdomain is successfully loaded, false otherwise.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1084
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1085
function _load_textdomain_just_in_time( $domain ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1086
	global $l10n_unloaded;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1087
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1088
	$l10n_unloaded = (array) $l10n_unloaded;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1089
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1090
	// Short-circuit if domain is 'default' which is reserved for core.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1091
	if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1092
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1093
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1094
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1095
	$translation_path = _get_path_to_translation( $domain );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1096
	if ( false === $translation_path ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1097
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1098
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1099
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1100
	return load_textdomain( $domain, $translation_path );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1101
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1102
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1103
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1104
 * Gets the path to a translation file for loading a textdomain just in time.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1105
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1106
 * Caches the retrieved results internally.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1107
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1108
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1109
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1110
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1111
 * @see _load_textdomain_just_in_time()
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1112
 * @staticvar array $available_translations
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1113
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1114
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1115
 * @param bool   $reset  Whether to reset the internal cache. Used by the switch to locale functionality.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1116
 * @return string|false The path to the translation file or false if no translation file was found.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1117
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1118
function _get_path_to_translation( $domain, $reset = false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1119
	static $available_translations = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1120
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1121
	if ( true === $reset ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1122
		$available_translations = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1123
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1124
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1125
	if ( ! isset( $available_translations[ $domain ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1126
		$available_translations[ $domain ] = _get_path_to_translation_from_lang_dir( $domain );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1127
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1128
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1129
	return $available_translations[ $domain ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1130
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1131
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1132
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1133
 * Gets the path to a translation file in the languages directory for the current locale.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1134
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1135
 * Holds a cached list of available .mo files to improve performance.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1136
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1137
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1138
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1139
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1140
 * @see _get_path_to_translation()
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1141
 * @staticvar array $cached_mofiles
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1142
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1143
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1144
 * @return string|false The path to the translation file or false if no translation file was found.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1145
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1146
function _get_path_to_translation_from_lang_dir( $domain ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1147
	static $cached_mofiles = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1148
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1149
	if ( null === $cached_mofiles ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1150
		$cached_mofiles = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1151
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1152
		$locations = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1153
			WP_LANG_DIR . '/plugins',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1154
			WP_LANG_DIR . '/themes',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1155
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1156
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1157
		foreach ( $locations as $location ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1158
			$mofiles = glob( $location . '/*.mo' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1159
			if ( $mofiles ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1160
				$cached_mofiles = array_merge( $cached_mofiles, $mofiles );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1161
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1162
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1163
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1164
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1165
	$locale = determine_locale();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1166
	$mofile = "{$domain}-{$locale}.mo";
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1167
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1168
	$path = WP_LANG_DIR . '/plugins/' . $mofile;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1169
	if ( in_array( $path, $cached_mofiles ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1170
		return $path;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1171
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1172
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1173
	$path = WP_LANG_DIR . '/themes/' . $mofile;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1174
	if ( in_array( $path, $cached_mofiles ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1175
		return $path;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1176
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1177
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1178
	return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1179
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1180
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1181
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
 * Return the Translations instance for a text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
 * If there isn't one, returns empty Translations instance.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1186
 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1187
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1188
 * @global MO[] $l10n
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1189
 * @staticvar NOOP_Translations $noop_translations
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1190
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1192
 * @return Translations|NOOP_Translations A Translations instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
function get_translations_for_domain( $domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
	global $l10n;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1196
	if ( isset( $l10n[ $domain ] ) || ( _load_textdomain_just_in_time( $domain ) && isset( $l10n[ $domain ] ) ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1197
		return $l10n[ $domain ];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1199
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1200
	static $noop_translations = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1201
	if ( null === $noop_translations ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1202
		$noop_translations = new NOOP_Translations;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1203
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1204
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1205
	return $noop_translations;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
 * Whether there are translations for the text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1212
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1213
 * @global MO[] $l10n
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1214
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
 * @return bool Whether there are translations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
function is_textdomain_loaded( $domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
	global $l10n;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1220
	return isset( $l10n[ $domain ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
 * Translates role name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
 * Since the role names are in the database and not in the source there
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
 * are dummy gettext calls to get them into the POT file and this function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
 * properly translates them back.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1230
 * The before_last_bar() call is needed, because older installations keep the roles
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
 * using the old context format: 'Role name|User role' and just skipping the
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1232
 * content after the last bar is easier than fixing them in the DB. New installations
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
 * won't suffer from that problem.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
 * @since 2.8.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1236
 * @since 5.2.0 Added the `$domain` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1238
 * @param string $name   The role name.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1239
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1240
 *                       Default 'default'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
 * @return string Translated role name on success, original name on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1243
function translate_user_role( $name, $domain = 'default' ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1244
	return translate_with_gettext_context( before_last_bar( $name ), 'User role', $domain );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
 * Get all available languages based on the presence of *.mo files in a given directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
 * The default directory is WP_LANG_DIR.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1253
 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
 * @param string $dir A directory to search for language files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
 *                    Default WP_LANG_DIR.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
 * @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.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
function get_available_languages( $dir = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
	$languages = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1262
	$lang_files = glob( ( is_null( $dir ) ? WP_LANG_DIR : $dir ) . '/*.mo' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1263
	if ( $lang_files ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1264
		foreach ( $lang_files as $lang_file ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1265
			$lang_file = basename( $lang_file, '.mo' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1266
			if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) &&
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1267
				0 !== strpos( $lang_file, 'admin-' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1268
				$languages[] = $lang_file;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1269
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1270
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1273
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1274
	 * Filters the list of available language codes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1275
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1276
	 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1277
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1278
	 * @param array  $languages An array of available language codes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1279
	 * @param string $dir       The directory where the language files were found.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1280
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1281
	return apply_filters( 'get_available_languages', $languages, $dir );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
 * Get installed translations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
 * Looks in the wp-content/languages directory for translations of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
 * plugins or themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
 * @return array Array of language data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
function wp_get_installed_translations( $type ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1296
	if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1298
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
	$dir = 'core' === $type ? '' : "/$type";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1302
	if ( ! is_dir( WP_LANG_DIR ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1304
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1306
	if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1308
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
	$files = scandir( WP_LANG_DIR . $dir );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1311
	if ( ! $files ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1313
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
	$language_data = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
	foreach ( $files as $file ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1318
		if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1319
			continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1320
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1321
		if ( substr( $file, -3 ) !== '.po' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1323
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1324
		if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1326
		}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1327
		if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1329
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
		list( , $textdomain, $language ) = $match;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1332
		if ( '' === $textdomain ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
			$textdomain = 'default';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1334
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
		$language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
	return $language_data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
 * Extract headers from a PO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
 * @param string $po_file Path to PO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
 * @return array PO file headers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
function wp_get_pomo_file_data( $po_file ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1349
	$headers = get_file_data(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1350
		$po_file,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1351
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1352
			'POT-Creation-Date'  => '"POT-Creation-Date',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1353
			'PO-Revision-Date'   => '"PO-Revision-Date',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1354
			'Project-Id-Version' => '"Project-Id-Version',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1355
			'X-Generator'        => '"X-Generator',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1356
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1357
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
	foreach ( $headers as $header => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
		// Remove possible contextual '\n' and closing double quote.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
		$headers[ $header ] = preg_replace( '~(\\\n)?"$~', '', $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
	return $headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1364
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1365
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1366
 * Language selector.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1367
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1368
 * @since 4.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1369
 * @since 4.3.0 Introduced the `echo` argument.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1370
 * @since 4.7.0 Introduced the `show_option_site_default` argument.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1371
 * @since 5.1.0 Introduced the `show_option_en_us` argument.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1372
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1373
 * @see get_available_languages()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1374
 * @see wp_get_available_translations()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1375
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1376
 * @param string|array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1377
 *     Optional. Array or string of arguments for outputting the language selector.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1378
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1379
 *     @type string   $id                           ID attribute of the select element. Default 'locale'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1380
 *     @type string   $name                         Name attribute of the select element. Default 'locale'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1381
 *     @type array    $languages                    List of installed languages, contain only the locales.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1382
 *                                                  Default empty array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1383
 *     @type array    $translations                 List of available translations. Default result of
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1384
 *                                                  wp_get_available_translations().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1385
 *     @type string   $selected                     Language which should be selected. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1386
 *     @type bool|int $echo                         Whether to echo the generated markup. Accepts 0, 1, or their
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1387
 *                                                  boolean equivalents. Default 1.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1388
 *     @type bool     $show_available_translations  Whether to show available translations. Default true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1389
 *     @type bool     $show_option_site_default     Whether to show an option to fall back to the site's locale. Default false.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1390
 *     @type bool     $show_option_en_us            Whether to show an option for English (United States). Default true.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1392
 * @return string HTML content
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1393
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1394
function wp_dropdown_languages( $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1396
	$parsed_args = wp_parse_args(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1397
		$args,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1398
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1399
			'id'                          => 'locale',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1400
			'name'                        => 'locale',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1401
			'languages'                   => array(),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1402
			'translations'                => array(),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1403
			'selected'                    => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1404
			'echo'                        => 1,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1405
			'show_available_translations' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1406
			'show_option_site_default'    => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1407
			'show_option_en_us'           => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1408
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1409
	);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1410
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1411
	// Bail if no ID or no name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1412
	if ( ! $parsed_args['id'] || ! $parsed_args['name'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1413
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1414
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1415
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1416
	// English (United States) uses an empty string for the value attribute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1417
	if ( 'en_US' === $parsed_args['selected'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1418
		$parsed_args['selected'] = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1419
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1420
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1421
	$translations = $parsed_args['translations'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1422
	if ( empty( $translations ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1423
		require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1424
		$translations = wp_get_available_translations();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1425
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1426
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1427
	/*
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1428
	 * $parsed_args['languages'] should only contain the locales. Find the locale in
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1429
	 * $translations to get the native name. Fall back to locale.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1430
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1431
	$languages = array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1432
	foreach ( $parsed_args['languages'] as $locale ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1433
		if ( isset( $translations[ $locale ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1434
			$translation = $translations[ $locale ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1435
			$languages[] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1436
				'language'    => $translation['language'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1437
				'native_name' => $translation['native_name'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1438
				'lang'        => current( $translation['iso'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1439
			);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1440
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1441
			// Remove installed language from available translations.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1442
			unset( $translations[ $locale ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1443
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1444
			$languages[] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1445
				'language'    => $locale,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1446
				'native_name' => $locale,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1447
				'lang'        => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1448
			);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1449
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1450
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1451
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1452
	$translations_available = ( ! empty( $translations ) && $parsed_args['show_available_translations'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1453
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1454
	// Holds the HTML markup.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1455
	$structure = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1456
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1457
	// List installed languages.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1458
	if ( $translations_available ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1459
		$structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1460
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1461
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1462
	// Site default.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1463
	if ( $parsed_args['show_option_site_default'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1464
		$structure[] = sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1465
			'<option value="site-default" data-installed="1"%s>%s</option>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1466
			selected( 'site-default', $parsed_args['selected'], false ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1467
			_x( 'Site Default', 'default site language' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1468
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1469
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1470
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1471
	if ( $parsed_args['show_option_en_us'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1472
		$structure[] = sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1473
			'<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1474
			selected( '', $parsed_args['selected'], false )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1475
		);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1476
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1477
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1478
	// List installed languages.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1479
	foreach ( $languages as $language ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
		$structure[] = sprintf(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1481
			'<option value="%s" lang="%s"%s data-installed="1">%s</option>',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1482
			esc_attr( $language['language'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
			esc_attr( $language['lang'] ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1484
			selected( $language['language'], $parsed_args['selected'], false ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1485
			esc_html( $language['native_name'] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1486
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1488
	if ( $translations_available ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
		$structure[] = '</optgroup>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1491
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
	// List available translations.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
	if ( $translations_available ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1494
		$structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1495
		foreach ( $translations as $translation ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1496
			$structure[] = sprintf(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1497
				'<option value="%s" lang="%s"%s>%s</option>',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
				esc_attr( $translation['language'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
				esc_attr( current( $translation['iso'] ) ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1500
				selected( $translation['language'], $parsed_args['selected'], false ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
				esc_html( $translation['native_name'] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1502
			);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1503
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1504
		$structure[] = '</optgroup>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1505
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1506
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1507
	// Combine the output string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1508
	$output  = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1509
	$output .= join( "\n", $structure );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1510
	$output .= '</select>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1511
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1512
	if ( $parsed_args['echo'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1513
		echo $output;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1514
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1515
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1516
	return $output;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1517
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1518
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1519
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1520
 * Determines whether the current locale is right-to-left (RTL).
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1521
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1522
 * For more information on this and similar theme functions, check out
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1523
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1524
 * Conditional Tags} article in the Theme Developer Handbook.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1525
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1526
 * @since 3.0.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1527
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1528
 * @global WP_Locale $wp_locale
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1529
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1530
 * @return bool Whether locale is RTL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1531
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1532
function is_rtl() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1533
	global $wp_locale;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1534
	if ( ! ( $wp_locale instanceof WP_Locale ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1535
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1536
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1537
	return $wp_locale->is_rtl();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1538
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1539
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1540
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1541
 * Switches the translations according to the given locale.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1542
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1543
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1544
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1545
 * @global WP_Locale_Switcher $wp_locale_switcher
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1546
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1547
 * @param string $locale The locale.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1548
 * @return bool True on success, false on failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1549
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1550
function switch_to_locale( $locale ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1551
	/* @var WP_Locale_Switcher $wp_locale_switcher */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1552
	global $wp_locale_switcher;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1553
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1554
	return $wp_locale_switcher->switch_to_locale( $locale );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1555
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1556
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1557
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1558
 * Restores the translations according to the previous locale.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1559
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1560
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1561
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1562
 * @global WP_Locale_Switcher $wp_locale_switcher
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1563
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1564
 * @return string|false Locale on success, false on error.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1565
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1566
function restore_previous_locale() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1567
	/* @var WP_Locale_Switcher $wp_locale_switcher */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1568
	global $wp_locale_switcher;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1569
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1570
	return $wp_locale_switcher->restore_previous_locale();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1571
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1572
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1573
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1574
 * Restores the translations according to the original locale.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1575
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1576
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1577
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1578
 * @global WP_Locale_Switcher $wp_locale_switcher
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1579
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1580
 * @return string|false Locale on success, false on error.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1581
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1582
function restore_current_locale() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1583
	/* @var WP_Locale_Switcher $wp_locale_switcher */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1584
	global $wp_locale_switcher;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1585
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1586
	return $wp_locale_switcher->restore_current_locale();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1587
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1588
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1589
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1590
 * Whether switch_to_locale() is in effect.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1591
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1592
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1593
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1594
 * @global WP_Locale_Switcher $wp_locale_switcher
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1595
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1596
 * @return bool True if the locale has been switched, false otherwise.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1597
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1598
function is_locale_switched() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1599
	/* @var WP_Locale_Switcher $wp_locale_switcher */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1600
	global $wp_locale_switcher;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1601
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1602
	return $wp_locale_switcher->is_switched();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1603
}