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