wp/wp-includes/l10n.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Translation API
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
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
 * Get the current locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * If the locale is set, then it will filter the locale in the 'locale' filter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * hook and return the value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * If the locale is not set already, then the WPLANG constant is used if it is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * defined. Then it is filtered through the 'locale' filter hook and the value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * for the locale global set and the locale is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * The process to get the locale should only be done once, but the locale will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * always be filtered using the 'locale' hook.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 * @return string The locale of the blog or from the 'locale' hook.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
function get_locale() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
	global $locale, $wp_local_package;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
	if ( isset( $locale ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		 * Filter WordPress install's locale ID.
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
		 * @since 1.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		 * @param string $locale The locale ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
		return apply_filters( 'locale', $locale );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
	if ( isset( $wp_local_package ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
		$locale = $wp_local_package;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
	// WPLANG was defined in wp-config.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
	if ( defined( 'WPLANG' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		$locale = WPLANG;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	// If multisite, check options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
		// Don't check blog option when installing.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
		if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
			$ms_locale = get_site_option( 'WPLANG' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
		if ( $ms_locale !== false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
			$locale = $ms_locale;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
		$db_locale = get_option( 'WPLANG' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
		if ( $db_locale !== false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
			$locale = $db_locale;
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
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
	if ( empty( $locale ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
		$locale = 'en_US';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
	/** This filter is documented in wp-includes/l10n.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	return apply_filters( 'locale', $locale );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
 * Retrieve the translation of $text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
 * 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
    78
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
 * *Note:* Don't use {@see translate()} directly, use `{@see __()} or related functions.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
 * @return string Translated text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
function translate( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	$translations = get_translations_for_domain( $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	$translations = $translations->translate( $text );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	 * Filter text with its translation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	 * @since 2.0.11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	 * @param string $translations Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	 * @param string $text         Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	 * @param string $domain       Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	return apply_filters( 'gettext', $translations, $text, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 * Remove last item on a pipe-delimited string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
 * 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
   107
 * string will be returned if no pipe '|' characters are found in the string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
 * @param string $string A pipe-delimited string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
 * @return string Either $string or everything before the last pipe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
function before_last_bar( $string ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	$last_bar = strrpos( $string, '|' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	if ( false == $last_bar )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		return substr( $string, 0, $last_bar );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
 * Retrieve the translation of $text in the context defined in $context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
 * If there is no translation, or the text domain isn't loaded the original
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
 * text is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
 * @return string Translated text on success, original text on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
function translate_with_gettext_context( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
	$translations = get_translations_for_domain( $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
	$translations = $translations->translate( $text, $context );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
	 * Filter text with its translation based on context information.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	 * @param string $translations Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	 * @param string $text         Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	 * @param string $context      Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
	 * @param string $domain       Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	return apply_filters( 'gettext_with_context', $translations, $text, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
 * Retrieve the translation of $text. If there is no translation,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
 * or the text domain isn't loaded, the original text is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
 * @return string Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
function __( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	return translate( $text, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
 * 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
   167
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
 * 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
   169
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
 * @return string Translated text on success, original text on failure.
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 esc_attr__( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	return esc_attr( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
 * 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
   182
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 * 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
   184
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
 * @return string Translated text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
function esc_html__( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	return esc_html( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
 * Display translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
function _e( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
	echo translate( $text, $domain );
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
 * Display translated text that has been escaped for safe use in an attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
function esc_attr_e( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
	echo esc_attr( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
 * Display translated text that has been escaped for safe use in HTML output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
function esc_html_e( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
	echo esc_html( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
 * Retrieve translated string with gettext context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
 * Quite a few times, there will be collisions with similar translatable text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
 * found in more than two places, but with different translated context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 * By including the context in the pot file, translators can translate the two
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 * strings differently.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
 * @return string Translated context string without pipe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
function _x( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
	return translate_with_gettext_context( $text, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
 * Display translated string with gettext context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 * @return string Translated context string without pipe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
function _ex( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	echo _x( $text, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 * 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
   267
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
 * @return string Translated text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
function esc_attr_x( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	return esc_attr( translate_with_gettext_context( $text, $context, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 * 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
   281
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
 * @return string Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
function esc_html_x( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
	return esc_html( translate_with_gettext_context( $text, $context, $domain ) );
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
 * Retrieve the plural or single form based on the supplied amount.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 * If the text domain is not set in the $l10n list, then a comparison will be made
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 * and either $plural or $single parameters returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
 * If the text domain does exist, then the parameters $single, $plural, and $number
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
 * will first be passed to the text domain's ngettext method. Then it will be passed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
 * to the 'ngettext' filter hook along with the same parameters. The expected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
 * type will be a string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
 * @param string $single The text that will be used if $number is 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
 * @param string $plural The text that will be used if $number is not 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
 * @param int    $number The number to compare against to use either $single or $plural.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
 * @return string Either $single or $plural translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
function _n( $single, $plural, $number, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
	$translations = get_translations_for_domain( $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	$translation = $translations->translate_plural( $single, $plural, $number );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
	 * Filter text with its translation when plural option is available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
	 * @param string $translation Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
	 * @param string $single      The text that will be used if $number is 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
	 * @param string $plural      The text that will be used if $number is not 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	 * @param string $number      The number to compare against to use either $single or $plural.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
	return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
 * Retrieve the plural or single form based on the supplied amount with gettext context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
 * This is a hybrid of _n() and _x(). It supports contexts and plurals.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
 * @param string $single  The text that will be used if $number is 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
 * @param string $plural  The text that will be used if $number is not 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 * @param int    $number  The number to compare against to use either $single or $plural.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
 * @return string Either $single or $plural translated text with context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
function _nx($single, $plural, $number, $context, $domain = 'default') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
	$translations = get_translations_for_domain( $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
	$translation = $translations->translate_plural( $single, $plural, $number, $context );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
	 * Filter text with its translation while plural option and context are available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
	 * @param string $translation Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
	 * @param string $single      The text that will be used if $number is 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
	 * @param string $plural      The text that will be used if $number is not 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
	 * @param string $number      The number to compare against to use either $single or $plural.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
	 * @param string $context     Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
	return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
 * Register plural strings in POT file, but don't translate them.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
 * Used when you want to keep structures with translatable plural
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
 * strings and use them later.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
 * Example:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
 *     $messages = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
 *      	'post' => _n_noop( '%s post', '%s posts' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
 *      	'page' => _n_noop( '%s pages', '%s pages' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
 *     );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
 *     ...
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
 *     $message = $messages[ $type ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
 *     $usable_text = sprintf( translate_nooped_plural( $message, $count ), $count );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
 * @param string $singular Single form to be i18ned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
 * @param string $plural   Plural form to be i18ned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
 * @param string $domain   Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
 * @return array array($singular, $plural)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
function _n_noop( $singular, $plural, $domain = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
	return array( 0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null, 'domain' => $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
 * Register plural strings with context in POT file, but don't translate them.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
 * @since 2.8.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
 * @param string $singular
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
 * @param string $plural
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
 * @param string $context
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
 * @param string|null $domain
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
 * @return array
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
function _nx_noop( $singular, $plural, $context, $domain = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
	return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
 * Translate the result of _n_noop() or _nx_noop().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
 * @param array  $nooped_plural Array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
 * @param int    $count         Number of objects
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
 * @param string $domain        Optional. Text domain. Unique identifier for retrieving translated strings. If $nooped_plural contains
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
 *                              a text domain passed to _n_noop() or _nx_noop(), it will override this value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
 * @return string Either $single or $plural translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	if ( $nooped_plural['domain'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
		$domain = $nooped_plural['domain'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
	if ( $nooped_plural['context'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
		return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
		return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
 * Load a .mo file into the text domain $domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
 * If the text domain already exists, the translations will be merged. If both
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
 * 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
   428
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
 * 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
   430
 * and will be a MO object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
 * @param string $mofile Path to the .mo file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
 * @return bool True on success, false on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
function load_textdomain( $domain, $mofile ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	global $l10n;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	 * Filter text domain and/or MO file path for loading translations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   446
	 * @param bool   $override Whether to override the text domain. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
	 * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
	 * @param string $mofile   Path to the MO file.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	$plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	if ( true == $plugin_override ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
	 * Fires before the MO translation file is loaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
	 * @param string $mofile Path to the .mo file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
	do_action( 'load_textdomain', $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
	 * Filter MO file path for loading translations for a specific text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
	 * @param string $mofile Path to the MO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
	$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
	if ( !is_readable( $mofile ) ) return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	$mo = new MO();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	if ( !$mo->import_from_file( $mofile ) ) return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	if ( isset( $l10n[$domain] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
		$mo->merge_with( $l10n[$domain] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	$l10n[$domain] = &$mo;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
 * Unload translations for a text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
 * @return bool Whether textdomain was unloaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
function unload_textdomain( $domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	global $l10n;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
	 * Filter the text domain for loading translation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
	 * @param bool   $override Whether to override unloading the text domain. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
	 * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
	$plugin_override = apply_filters( 'override_unload_textdomain', false, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	if ( $plugin_override )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	 * Fires before the text domain is unloaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
	do_action( 'unload_textdomain', $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	if ( isset( $l10n[$domain] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
		unset( $l10n[$domain] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
 * Load default translated strings based on locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
 * Loads the .mo file in WP_LANG_DIR constant path from WordPress root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
 * The translated (.mo) file is named based on the locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
 * @see load_textdomain()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
 * @since 1.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
 * @param string $locale Optional. Locale to load. Default is the value of {@see get_locale()}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
 * @return bool Whether the textdomain was loaded.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   543
function load_default_textdomain( $locale = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   544
	if ( null === $locale ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
		$locale = get_locale();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   546
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   548
	// Unload previously loaded strings so we can switch translations.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   549
	unload_textdomain( 'default' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
	$return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists(  WP_LANG_DIR . "/admin-$locale.mo" ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
		load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
		return $return;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
	if ( is_admin() || defined( 'WP_INSTALLING' ) || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
		load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
		load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   565
	return $return;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
 * Load a plugin's translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
 * 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
   572
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
 * 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
   574
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
 * @param string $domain          Unique identifier for retrieving translated strings
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
 * @param string $deprecated      Use the $plugin_rel_path parameter instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
 * @param string $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   580
 *                                Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   581
 * @return bool True when textdomain is successfully loaded, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	$locale = get_locale();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	 * Filter a plugin's locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	 * @param string $locale The plugin's current locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
	$locale = apply_filters( 'plugin_locale', $locale, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	if ( false !== $plugin_rel_path	) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
		$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   597
	} elseif ( false !== $deprecated ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
		_deprecated_argument( __FUNCTION__, '2.7' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
		$path = ABSPATH . trim( $deprecated, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
		$path = WP_PLUGIN_DIR;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
	// Load the textdomain according to the plugin first
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	$mofile = $domain . '-' . $locale . '.mo';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
	if ( $loaded = load_textdomain( $domain, $path . '/'. $mofile ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
		return $loaded;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
	// Otherwise, load from the languages directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
	$mofile = WP_LANG_DIR . '/plugins/' . $mofile;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	return load_textdomain( $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
 * Load the translated strings for a plugin residing in the mu-plugins directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
 * @param string $domain             Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
 * @param string $mu_plugin_rel_path Relative to WPMU_PLUGIN_DIR directory in which the .mo file resides.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
 *                                   Default empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
 * @return bool True when textdomain is successfully loaded, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   625
	/** This filter is documented in wp-includes/l10n.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	$path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
	// Load the textdomain according to the plugin first
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	$mofile = $domain . '-' . $locale . '.mo';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	if ( $loaded = load_textdomain( $domain, $path . $mofile ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
		return $loaded;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	// Otherwise, load from the languages directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	$mofile = WP_LANG_DIR . '/plugins/' . $mofile;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	return load_textdomain( $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
 * Load the theme's translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
 * 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
   643
 * will be included in the translated strings by the $domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
 * The .mo files must be named based on the locale exactly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
 * @param string $path   Optional. Path to the directory containing the .mo file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
 *                       Default false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
 * @return bool True when textdomain is successfully loaded, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
function load_theme_textdomain( $domain, $path = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
	$locale = get_locale();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	 * Filter a theme's locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	 * @since 3.0.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
	 * @param string $locale The theme's current locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	$locale = apply_filters( 'theme_locale', $locale, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	if ( ! $path )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
		$path = get_template_directory();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
	// Load the textdomain according to the theme
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   670
	$mofile = untrailingslashit( $path ) . "/{$locale}.mo";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
	if ( $loaded = load_textdomain( $domain, $mofile ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		return $loaded;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	// Otherwise, load from the languages directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
	$mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
	return load_textdomain( $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
 * Load the child themes translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
 * If the current locale exists as a .mo file in the child themes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
 * root directory, it will be included in the translated strings by the $domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
 * The .mo files must be named based on the locale exactly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
 * @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
   690
 * @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
   691
 *                       Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
 * @return bool True when the theme textdomain is successfully loaded, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
function load_child_theme_textdomain( $domain, $path = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
	if ( ! $path )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
		$path = get_stylesheet_directory();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
	return load_theme_textdomain( $domain, $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
 * Return the Translations instance for a text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
 * If there isn't one, returns empty Translations instance.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   705
 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   706
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
 * @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
   708
 * @return NOOP_Translations A Translations instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
function get_translations_for_domain( $domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
	global $l10n;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	if ( !isset( $l10n[$domain] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		$l10n[$domain] = new NOOP_Translations;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
	return $l10n[$domain];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
 * Whether there are translations for the text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
 * @return bool Whether there are translations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
function is_textdomain_loaded( $domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
	global $l10n;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
	return isset( $l10n[$domain] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
 * Translates role name.
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 the role names are in the database and not in the source there
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
 * 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
   736
 * properly translates them back.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
 * The before_last_bar() call is needed, because older installs keep the roles
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
 * using the old context format: 'Role name|User role' and just skipping the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
 * content after the last bar is easier than fixing them in the DB. New installs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
 * won't suffer from that problem.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
 * @since 2.8.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
 * @param string $name The role name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
 * @return string Translated role name on success, original name on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
function translate_user_role( $name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
	return translate_with_gettext_context( before_last_bar($name), 'User role' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
 * 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
   754
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
 * The default directory is WP_LANG_DIR.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
 * @param string $dir A directory to search for language files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
 *                    Default WP_LANG_DIR.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
 * @return array An array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
function get_available_languages( $dir = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
	$languages = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	foreach( (array)glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ) as $lang_file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
		$lang_file = basename($lang_file, '.mo');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
		if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
			0 !== strpos( $lang_file, 'admin-' ))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
			$languages[] = $lang_file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	return $languages;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
 * Get installed translations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
 * Looks in the wp-content/languages directory for translations of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
 * plugins or themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
 * @return array Array of language data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
function wp_get_installed_translations( $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
	if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
	$dir = 'core' === $type ? '' : "/$type";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
	if ( ! is_dir( WP_LANG_DIR ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
	if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
	$files = scandir( WP_LANG_DIR . $dir );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	if ( ! $files )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
	$language_data = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
	foreach ( $files as $file ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   806
		if ( '.' === $file[0] || is_dir( $file ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
			continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   808
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   809
		if ( substr( $file, -3 ) !== '.po' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   811
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   812
		if ( ! preg_match( '/(?:(.+)-)?([A-Za-z_]{2,6}).po/', $file, $match ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   814
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   815
		if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) )  {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   817
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
		list( , $textdomain, $language ) = $match;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
		if ( '' === $textdomain ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
			$textdomain = 'default';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
		$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
   824
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
	return $language_data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
 * Extract headers from a PO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
 * @param string $po_file Path to PO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
 * @return array PO file headers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
function wp_get_pomo_file_data( $po_file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
	$headers = get_file_data( $po_file, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
		'POT-Creation-Date'  => '"POT-Creation-Date',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
		'PO-Revision-Date'   => '"PO-Revision-Date',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
		'Project-Id-Version' => '"Project-Id-Version',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
		'X-Generator'        => '"X-Generator',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
	foreach ( $headers as $header => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
		// Remove possible contextual '\n' and closing double quote.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
		$headers[ $header ] = preg_replace( '~(\\\n)?"$~', '', $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
	return $headers;
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
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   850
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   851
 * Language selector.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   852
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   853
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   854
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   855
 * @see get_available_languages()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   856
 * @see wp_get_available_translations()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   857
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   858
 * @param string|array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   859
 *     Optional. Array or string of arguments for outputting the language selector.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   860
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   861
 *     @type string  $id                           ID attribute of the select element. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   862
 *     @type string  $name                         Name attribute of the select element. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   863
 *     @type array   $languages                    List of installed languages, contain only the locales.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
 *                                                 Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
 *     @type array   $translations                 List of available translations. Default result of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   866
 *                                                 {@see wp_get_available_translations()}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   867
 *     @type string  $selected                     Language which should be selected. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   868
 *     @type bool    $show_available_translations  Whether to show available translations. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   869
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   870
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   871
function wp_dropdown_languages( $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   872
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   873
	$args = wp_parse_args( $args, array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   874
		'id'           => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   875
		'name'         => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   876
		'languages'    => array(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
		'translations' => array(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
		'selected'     => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
		'show_available_translations' => true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
	) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   881
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
	$translations = $args['translations'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   883
	if ( empty( $translations ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   884
		require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   885
		$translations = wp_get_available_translations();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   886
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   887
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   888
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   889
	 * $args['languages'] should only contain the locales. Find the locale in
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   890
	 * $translations to get the native name. Fall back to locale.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   891
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   892
	$languages = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   893
	foreach ( $args['languages'] as $locale ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   894
		if ( isset( $translations[ $locale ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   895
			$translation = $translations[ $locale ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   896
			$languages[] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   897
				'language'    => $translation['language'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   898
				'native_name' => $translation['native_name'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   899
				'lang'        => current( $translation['iso'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   900
			);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   901
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   902
			// Remove installed language from available translations.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   903
			unset( $translations[ $locale ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   904
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
			$languages[] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   906
				'language'    => $locale,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   907
				'native_name' => $locale,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   908
				'lang'        => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   909
			);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   910
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   911
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   912
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   913
	$translations_available = ( ! empty( $translations ) && $args['show_available_translations'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   914
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   915
	printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   916
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   917
	// Holds the HTML markup.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
	$structure = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   919
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   920
	// List installed languages.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   921
	if ( $translations_available ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   922
		$structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   923
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   924
	$structure[] = '<option value="" lang="en" data-installed="1">English (United States)</option>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   925
	foreach ( $languages as $language ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   926
		$structure[] = sprintf(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   927
			'<option value="%s" lang="%s"%s data-installed="1">%s</option>',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   928
			esc_attr( $language['language'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   929
			esc_attr( $language['lang'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   930
			selected( $language['language'], $args['selected'], false ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   931
			esc_html( $language['native_name'] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   932
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   933
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   934
	if ( $translations_available ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   935
		$structure[] = '</optgroup>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   936
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   937
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   938
	// List available translations.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   939
	if ( $translations_available ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   940
		$structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   941
		foreach ( $translations as $translation ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   942
			$structure[] = sprintf(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   943
				'<option value="%s" lang="%s"%s>%s</option>',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   944
				esc_attr( $translation['language'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   945
				esc_attr( current( $translation['iso'] ) ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   946
				selected( $translation['language'], $args['selected'], false ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   947
				esc_html( $translation['native_name'] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   948
			);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   949
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   950
		$structure[] = '</optgroup>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   951
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   952
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   953
	echo join( "\n", $structure );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   954
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   955
	echo '</select>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   956
}