wp/wp-includes/l10n.php
author ymh <ymh.work@gmail.com>
Wed, 06 Nov 2013 03:21:17 +0000
changeset 0 d970ebf37754
child 5 5e2f62d02dcd
permissions -rw-r--r--
first import
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() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	global $locale;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	if ( isset( $locale ) )
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
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		 * @since 1.5.2
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 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	// WPLANG is defined in wp-config.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	if ( defined( 'WPLANG' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		$locale = WPLANG;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	// If multisite, check options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
		// Don't check blog option when installing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
			$ms_locale = get_site_option('WPLANG');
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 ( $ms_locale !== false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
			$locale = $ms_locale;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	if ( empty( $locale ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
		$locale = 'en_US';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	// duplicate_hook
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	return apply_filters( 'locale', $locale );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 * Retrieve the translation of $text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 * 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
    64
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
 * <strong>Note:</strong> Don't use translate() directly, use __() or related functions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
 * @return string Translated text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
function translate( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	$translations = get_translations_for_domain( $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	$translations = $translations->translate( $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
	 * Filter text with its translation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	 * @since 2.0.11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	 * @param string $translations Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	 * @param string $text         Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	 * @param string $domain       Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	return apply_filters( 'gettext', $translations, $text, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
 * Remove last item on a pipe-delimited string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
 * 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
    92
 * string will be returned if no pipe '|' characters are found in the string.
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.8.0
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 $string A pipe-delimited string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
 * @return string Either $string or everything before the last pipe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
function before_last_bar( $string ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	$last_bar = strrpos( $string, '|' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	if ( false == $last_bar )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
		return $string;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
		return substr( $string, 0, $last_bar );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 * Retrieve the translation of $text in the context defined in $context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
 * 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
   111
 * text is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
 * @return string Translated text on success, original text on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
function translate_with_gettext_context( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
	$translations = get_translations_for_domain( $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	$translations = $translations->translate( $text, $context );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	 * Filter text with its translation based on context information.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	 * @param string $translations Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	 * @param string $text         Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	 * @param string $context      Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	 * @param string $domain       Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
	return apply_filters( 'gettext_with_context', $translations, $text, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
 * Retrieve the translation of $text. If there is no translation,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
 * or the text domain isn't loaded, the original text is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
 * @return string Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
function __( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	return translate( $text, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
}
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
 * 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
   152
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
 * 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
   154
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
 * @since 2.8.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 on success, original text on failure.
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 esc_attr__( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	return esc_attr( 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 HTML output.
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
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_html__( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	return esc_html( 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
 * Display translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
function _e( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	echo translate( $text, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
 * Display translated text that has been escaped for safe use in an attribute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
function esc_attr_e( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
	echo esc_attr( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
 * Display translated text that has been escaped for safe use in HTML output.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
 * @param string $text   Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
function esc_html_e( $text, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
	echo esc_html( translate( $text, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
 * Retrieve translated string with gettext context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
 * Quite a few times, there will be collisions with similar translatable text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
 * found in more than two places, but with different translated context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
 * By including the context in the pot file, translators can translate the two
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
 * strings differently.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
 * @return string Translated context string without pipe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
function _x( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
	return translate_with_gettext_context( $text, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 * Display translated string with gettext context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
 * @return string Translated context string without pipe.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
function _ex( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	echo _x( $text, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
}
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
 * 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
   252
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
 * @return string Translated text
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
function esc_attr_x( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
	return esc_attr( translate_with_gettext_context( $text, $context, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
}
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
 * 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
   266
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
 * @param string $text    Text to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
 * @param string $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
 * @return string Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
function esc_html_x( $text, $context, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	return esc_html( translate_with_gettext_context( $text, $context, $domain ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
}
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
 * Retrieve the plural or single form based on the supplied amount.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 * 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
   282
 * and either $plural or $single parameters returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
 * If the text domain does exist, then the parameters $single, $plural, and $number
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
 * 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
   286
 * to the 'ngettext' filter hook along with the same parameters. The expected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
 * type will be a string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
 * @param string $single The text that will be used if $number is 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
 * @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
   293
 * @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
   294
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 * @return string Either $single or $plural translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
function _n( $single, $plural, $number, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
	$translations = get_translations_for_domain( $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	$translation = $translations->translate_plural( $single, $plural, $number );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
	 * Filter text with its translation when plural option is available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
	 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
	 * @param string $translation Translated text.
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 string $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      Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
	return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
 * 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
   316
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
 * This is a hybrid of _n() and _x(). It supports contexts and plurals.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
 * @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 int    $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 $context Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
 * @return string Either $single or $plural translated text with context.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
function _nx($single, $plural, $number, $context, $domain = 'default') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	$translations = get_translations_for_domain( $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
	$translation = $translations->translate_plural( $single, $plural, $number, $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
	 * Filter text with its translation while plural option and context are available.
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 $translation Translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	 * @param string $single      The text that will be used if $number is 1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	 * @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
   339
	 * @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
   340
	 * @param string $context     Context information for the translators.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
 * Register plural strings in POT file, but don't translate them.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
 * Used when you want to keep structures with translatable plural
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
 * strings and use them later.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
 * Example:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
 * <code>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
 * $messages = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
 *  	'post' => _n_noop('%s post', '%s posts'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
 *  	'page' => _n_noop('%s pages', '%s pages')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
 * );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
 * ...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
 * $message = $messages[$type];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
 * $usable_text = sprintf( translate_nooped_plural( $message, $count ), $count );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
 * </code>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
 * @param string $singular Single form to be i18ned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
 * @param string $plural   Plural form to be i18ned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
 * @param string $domain   Optional. Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
 * @return array array($singular, $plural)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
function _n_noop( $singular, $plural, $domain = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
	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
   372
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
 * Register plural strings with context in POT file, but don't translate them.
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.8.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
function _nx_noop( $singular, $plural, $context, $domain = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
	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
   381
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
 * Translate the result of _n_noop() or _nx_noop().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
 * @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
   389
 * @param int    $count         Number of objects
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
 * @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
   391
 *                              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
   392
 * @return string Either $single or $plural translated text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
	if ( $nooped_plural['domain'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
		$domain = $nooped_plural['domain'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
	if ( $nooped_plural['context'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
		return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
		return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
 * Load a .mo file into the text domain $domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
 * If the text domain already exists, the translations will be merged. If both
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
 * 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
   409
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
 * 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
   411
 * and will be a MO object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
 * @param string $mofile Path to the .mo file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
 * @return bool True on success, false on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
function load_textdomain( $domain, $mofile ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
	global $l10n;
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
	 * Filter text domain and/or MO file path for loading translations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	 * @param boolean        Whether to override the text domain. Default false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	 * @param string $mofile Path to the MO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	$plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
	if ( true == $plugin_override ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
	 * Fires before the MO translation file is loaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	 * @param string $mofile Path to the .mo file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	do_action( 'load_textdomain', $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	 * Filter MO file path for loading translations for a specific text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	 * @param string $mofile Path to the MO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
	if ( !is_readable( $mofile ) ) return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
	$mo = new MO();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
	if ( !$mo->import_from_file( $mofile ) ) return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
	if ( isset( $l10n[$domain] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
		$mo->merge_with( $l10n[$domain] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
	$l10n[$domain] = &$mo;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
 * Unload translations for a text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
 * @return bool Whether textdomain was unloaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
function unload_textdomain( $domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	global $l10n;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
	 * Filter text text domain for loading translation.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	 * @param boolean        Whether to override unloading the text domain. Default false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	$plugin_override = apply_filters( 'override_unload_textdomain', false, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	if ( $plugin_override )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	 * Fires before the text domain is 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
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	do_action( 'unload_textdomain', $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	if ( isset( $l10n[$domain] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
		unset( $l10n[$domain] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
 * Load default translated strings based on locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
 * Loads the .mo file in WP_LANG_DIR constant path from WordPress root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
 * The translated (.mo) file is named based on the locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
 * @see load_textdomain()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
function load_default_textdomain() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	$locale = get_locale();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
	load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	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
   527
		load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
		return;
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
	if ( is_admin() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
		load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
		load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
 * Load a plugin's translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
 * 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
   543
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
 * 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
   545
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
 * @param string $domain          Unique identifier for retrieving translated strings
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
 * @param string $deprecated      Use the $plugin_rel_path parameter instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
 * @param string $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	$locale = get_locale();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	 * Filter a plugin's locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
	 * @param string $locale The plugin's current locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	$locale = apply_filters( 'plugin_locale', $locale, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
	if ( false !== $plugin_rel_path	) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
		$path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
	} else if ( false !== $deprecated ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
		_deprecated_argument( __FUNCTION__, '2.7' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
		$path = ABSPATH . trim( $deprecated, '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
		$path = WP_PLUGIN_DIR;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
	// Load the textdomain according to the plugin first
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
	$mofile = $domain . '-' . $locale . '.mo';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
	if ( $loaded = load_textdomain( $domain, $path . '/'. $mofile ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
		return $loaded;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
	// Otherwise, load from the languages directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
	$mofile = WP_LANG_DIR . '/plugins/' . $mofile;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	return load_textdomain( $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
 * Load the translated strings for a plugin residing in the mu-plugins directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
 * @param string $domain             Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
 * @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
   590
 *                                   Default empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
 * @return bool True when textdomain is successfully loaded, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	// duplicate_hook
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
	$path = trailingslashit( WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
	// Load the textdomain according to the plugin first
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
	$mofile = $domain . '-' . $locale . '.mo';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	if ( $loaded = load_textdomain( $domain, $path . $mofile ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
		return $loaded;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
	// Otherwise, load from the languages directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
	$mofile = WP_LANG_DIR . '/plugins/' . $mofile;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	return load_textdomain( $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
 * Load the theme's translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
 * 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
   612
 * will be included in the translated strings by the $domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
 * The .mo files must be named based on the locale exactly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
 * @param string $path   Optional. Path to the directory containing the .mo file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
 *                       Default false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
 * @return bool True when textdomain is successfully loaded, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
function load_theme_textdomain( $domain, $path = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
	$locale = get_locale();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	 * Filter a theme's locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	 * @param string $locale The theme's current locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	$locale = apply_filters( 'theme_locale', $locale, $domain );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	if ( ! $path )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
		$path = get_template_directory();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
	// Load the textdomain according to the theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	$mofile = "{$path}/{$locale}.mo";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	if ( $loaded = load_textdomain( $domain, $mofile ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
		return $loaded;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	// Otherwise, load from the languages directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	$mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	return load_textdomain( $domain, $mofile );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
 * Load the child themes translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
 * If the current locale exists as a .mo file in the child themes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
 * root directory, it will be included in the translated strings by the $domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
 * The .mo files must be named based on the locale exactly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
 * @return bool True when the theme textdomain is successfully loaded, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
function load_child_theme_textdomain( $domain, $path = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	if ( ! $path )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
		$path = get_stylesheet_directory();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	return load_theme_textdomain( $domain, $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 * Return the Translations instance for a text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
 * If there isn't one, returns empty Translations instance.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
 * @return Translations A Translations instance.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
function get_translations_for_domain( $domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
	global $l10n;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
	if ( !isset( $l10n[$domain] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
		$l10n[$domain] = new NOOP_Translations;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
	return $l10n[$domain];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
 * Whether there are translations for the text domain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
 * @return bool Whether there are translations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
function is_textdomain_loaded( $domain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
	global $l10n;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
	return isset( $l10n[$domain] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
 * Translates role name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
 * 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
   699
 * 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
   700
 * properly translates them back.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
 * The before_last_bar() call is needed, because older installs keep the roles
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
 * using the old context format: 'Role name|User role' and just skipping the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
 * 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
   705
 * won't suffer from that problem.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
 * @param string $name The role name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
 * @return string Translated role name on success, original name on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
function translate_user_role( $name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	return translate_with_gettext_context( before_last_bar($name), 'User role' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
 * 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
   718
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
 * The default directory is WP_LANG_DIR.
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
 * @param string $dir A directory to search for language files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
 *                    Default WP_LANG_DIR.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
 * @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
   726
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
function get_available_languages( $dir = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
	$languages = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
	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
   731
		$lang_file = basename($lang_file, '.mo');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
		if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
			0 !== strpos( $lang_file, 'admin-' ))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
			$languages[] = $lang_file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
	return $languages;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
 * Get installed translations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
 * Looks in the wp-content/languages directory for translations of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
 * plugins or themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
 * @param string $type What to search for. Accepts 'plugins', 'themes', 'core'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
 * @return array Array of language data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
function wp_get_installed_translations( $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
	if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
	$dir = 'core' === $type ? '' : "/$type";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
	if ( ! is_dir( WP_LANG_DIR ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
	if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	$files = scandir( WP_LANG_DIR . $dir );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
	if ( ! $files )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
		return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
	$language_data = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	foreach ( $files as $file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
		if ( '.' === $file[0] || is_dir( $file ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
		if ( substr( $file, -3 ) !== '.po' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		if ( ! preg_match( '/(?:(.+)-)?([A-Za-z_]{2,6}).po/', $file, $match ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
		list( , $textdomain, $language ) = $match;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
		if ( '' === $textdomain )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
			$textdomain = 'default';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
		$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
   781
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
	return $language_data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
 * Extract headers from a PO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
 * @param string $po_file Path to PO file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
 * @return array PO file headers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
function wp_get_pomo_file_data( $po_file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
	$headers = get_file_data( $po_file, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
		'POT-Creation-Date'  => '"POT-Creation-Date',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
		'PO-Revision-Date'   => '"PO-Revision-Date',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
		'Project-Id-Version' => '"Project-Id-Version',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
		'X-Generator'        => '"X-Generator',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	foreach ( $headers as $header => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
		// Remove possible contextual '\n' and closing double quote.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
		$headers[ $header ] = preg_replace( '~(\\\n)?"$~', '', $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
	return $headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
}