equal
deleted
inserted
replaced
29 */ |
29 */ |
30 function get_locale() { |
30 function get_locale() { |
31 global $locale, $wp_local_package; |
31 global $locale, $wp_local_package; |
32 |
32 |
33 if ( isset( $locale ) ) { |
33 if ( isset( $locale ) ) { |
34 /** |
34 /** This filter is documented in wp-includes/l10n.php */ |
35 * Filters the locale ID of the WordPress installation. |
|
36 * |
|
37 * @since 1.5.0 |
|
38 * |
|
39 * @param string $locale The locale ID. |
|
40 */ |
|
41 return apply_filters( 'locale', $locale ); |
35 return apply_filters( 'locale', $locale ); |
42 } |
36 } |
43 |
37 |
44 if ( isset( $wp_local_package ) ) { |
38 if ( isset( $wp_local_package ) ) { |
45 $locale = $wp_local_package; |
39 $locale = $wp_local_package; |
74 |
68 |
75 if ( empty( $locale ) ) { |
69 if ( empty( $locale ) ) { |
76 $locale = 'en_US'; |
70 $locale = 'en_US'; |
77 } |
71 } |
78 |
72 |
79 /** This filter is documented in wp-includes/l10n.php */ |
73 /** |
|
74 * Filters the locale ID of the WordPress installation. |
|
75 * |
|
76 * @since 1.5.0 |
|
77 * |
|
78 * @param string $locale The locale ID. |
|
79 */ |
80 return apply_filters( 'locale', $locale ); |
80 return apply_filters( 'locale', $locale ); |
81 } |
81 } |
82 |
82 |
83 /** |
83 /** |
84 * Retrieves the locale of a user. |
84 * Retrieves the locale of a user. |
932 * The .mo files must be named based on the locale exactly. |
932 * The .mo files must be named based on the locale exactly. |
933 * |
933 * |
934 * @since 1.5.0 |
934 * @since 1.5.0 |
935 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first. |
935 * @since 4.6.0 The function now tries to load the .mo file from the languages directory first. |
936 * |
936 * |
937 * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
937 * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
938 * @param string $path Optional. Path to the directory containing the .mo file. |
938 * @param string|false $path Optional. Path to the directory containing the .mo file. |
939 * Default false. |
939 * Default false. |
940 * @return bool True when textdomain is successfully loaded, false otherwise. |
940 * @return bool True when textdomain is successfully loaded, false otherwise. |
941 */ |
941 */ |
942 function load_theme_textdomain( $domain, $path = false ) { |
942 function load_theme_textdomain( $domain, $path = false ) { |
943 /** |
943 /** |
944 * Filters a theme's locale. |
944 * Filters a theme's locale. |
972 * |
972 * |
973 * The .mo files must be named based on the locale exactly. |
973 * The .mo files must be named based on the locale exactly. |
974 * |
974 * |
975 * @since 2.9.0 |
975 * @since 2.9.0 |
976 * |
976 * |
977 * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
977 * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
978 * @param string $path Optional. Path to the directory containing the .mo file. |
978 * @param string|false $path Optional. Path to the directory containing the .mo file. |
979 * Default false. |
979 * Default false. |
980 * @return bool True when the theme textdomain is successfully loaded, false otherwise. |
980 * @return bool True when the theme textdomain is successfully loaded, false otherwise. |
981 */ |
981 */ |
982 function load_child_theme_textdomain( $domain, $path = false ) { |
982 function load_child_theme_textdomain( $domain, $path = false ) { |
983 if ( ! $path ) { |
983 if ( ! $path ) { |
984 $path = get_stylesheet_directory(); |
984 $path = get_stylesheet_directory(); |
996 * @see WP_Scripts::set_translations() |
996 * @see WP_Scripts::set_translations() |
997 * |
997 * |
998 * @param string $handle Name of the script to register a translation domain to. |
998 * @param string $handle Name of the script to register a translation domain to. |
999 * @param string $domain Optional. Text domain. Default 'default'. |
999 * @param string $domain Optional. Text domain. Default 'default'. |
1000 * @param string $path Optional. The full file path to the directory containing translation files. |
1000 * @param string $path Optional. The full file path to the directory containing translation files. |
1001 * @return string|false False if the script textdomain could not be loaded, the translated strings |
1001 * @return string|false The translated strings in JSON encoding on success, |
1002 * in JSON encoding otherwise. |
1002 * false if the script textdomain could not be loaded. |
1003 */ |
1003 */ |
1004 function load_script_textdomain( $handle, $domain = 'default', $path = null ) { |
1004 function load_script_textdomain( $handle, $domain = 'default', $path = null ) { |
1005 $wp_scripts = wp_scripts(); |
1005 $wp_scripts = wp_scripts(); |
1006 |
1006 |
1007 if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { |
1007 if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { |
1038 $site_url = wp_parse_url( site_url() ); |
1038 $site_url = wp_parse_url( site_url() ); |
1039 |
1039 |
1040 // If the host is the same or it's a relative URL. |
1040 // If the host is the same or it's a relative URL. |
1041 if ( |
1041 if ( |
1042 ( ! isset( $content_url['path'] ) || strpos( $src_url['path'], $content_url['path'] ) === 0 ) && |
1042 ( ! isset( $content_url['path'] ) || strpos( $src_url['path'], $content_url['path'] ) === 0 ) && |
1043 ( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] ) |
1043 ( ! isset( $src_url['host'] ) || ! isset( $content_url['host'] ) || $src_url['host'] === $content_url['host'] ) |
1044 ) { |
1044 ) { |
1045 // Make the src relative the specific plugin or theme. |
1045 // Make the src relative the specific plugin or theme. |
1046 if ( isset( $content_url['path'] ) ) { |
1046 if ( isset( $content_url['path'] ) ) { |
1047 $relative = substr( $src_url['path'], strlen( $content_url['path'] ) ); |
1047 $relative = substr( $src_url['path'], strlen( $content_url['path'] ) ); |
1048 } else { |
1048 } else { |
1055 |
1055 |
1056 $relative = array_slice( $relative, 2 ); // Remove plugins/<plugin name> or themes/<theme name>. |
1056 $relative = array_slice( $relative, 2 ); // Remove plugins/<plugin name> or themes/<theme name>. |
1057 $relative = implode( '/', $relative ); |
1057 $relative = implode( '/', $relative ); |
1058 } elseif ( |
1058 } elseif ( |
1059 ( ! isset( $plugins_url['path'] ) || strpos( $src_url['path'], $plugins_url['path'] ) === 0 ) && |
1059 ( ! isset( $plugins_url['path'] ) || strpos( $src_url['path'], $plugins_url['path'] ) === 0 ) && |
1060 ( ! isset( $src_url['host'] ) || $src_url['host'] === $plugins_url['host'] ) |
1060 ( ! isset( $src_url['host'] ) || ! isset( $plugins_url['host'] ) || $src_url['host'] === $plugins_url['host'] ) |
1061 ) { |
1061 ) { |
1062 // Make the src relative the specific plugin. |
1062 // Make the src relative the specific plugin. |
1063 if ( isset( $plugins_url['path'] ) ) { |
1063 if ( isset( $plugins_url['path'] ) ) { |
1064 $relative = substr( $src_url['path'], strlen( $plugins_url['path'] ) ); |
1064 $relative = substr( $src_url['path'], strlen( $plugins_url['path'] ) ); |
1065 } else { |
1065 } else { |
1070 |
1070 |
1071 $languages_path = WP_LANG_DIR . '/plugins'; |
1071 $languages_path = WP_LANG_DIR . '/plugins'; |
1072 |
1072 |
1073 $relative = array_slice( $relative, 1 ); // Remove <plugin name>. |
1073 $relative = array_slice( $relative, 1 ); // Remove <plugin name>. |
1074 $relative = implode( '/', $relative ); |
1074 $relative = implode( '/', $relative ); |
1075 } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) { |
1075 } elseif ( ! isset( $src_url['host'] ) || ! isset( $site_url['host'] ) || $src_url['host'] === $site_url['host'] ) { |
1076 if ( ! isset( $site_url['path'] ) ) { |
1076 if ( ! isset( $site_url['path'] ) ) { |
1077 $relative = trim( $src_url['path'], '/' ); |
1077 $relative = trim( $src_url['path'], '/' ); |
1078 } elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) { |
1078 } elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) { |
1079 // Make the src relative to the WP root. |
1079 // Make the src relative to the WP root. |
1080 $relative = substr( $src_url['path'], strlen( $site_url['path'] ) ); |
1080 $relative = substr( $src_url['path'], strlen( $site_url['path'] ) ); |
1127 * @since 5.0.2 |
1127 * @since 5.0.2 |
1128 * |
1128 * |
1129 * @param string|false $file Path to the translation file to load. False if there isn't one. |
1129 * @param string|false $file Path to the translation file to load. False if there isn't one. |
1130 * @param string $handle Name of the script to register a translation domain to. |
1130 * @param string $handle Name of the script to register a translation domain to. |
1131 * @param string $domain The text domain. |
1131 * @param string $domain The text domain. |
1132 * @return string|false The JSON-encoded translated strings for the given script handle and text domain. False if there are none. |
1132 * @return string|false The JSON-encoded translated strings for the given script handle and text domain. |
|
1133 * False if there are none. |
1133 */ |
1134 */ |
1134 function load_script_translations( $file, $handle, $domain ) { |
1135 function load_script_translations( $file, $handle, $domain ) { |
1135 /** |
1136 /** |
1136 * Pre-filters script translations for the given file, script handle and text domain. |
1137 * Pre-filters script translations for the given file, script handle and text domain. |
1137 * |
1138 * |
1615 $structure[] = '</optgroup>'; |
1616 $structure[] = '</optgroup>'; |
1616 } |
1617 } |
1617 |
1618 |
1618 // Combine the output string. |
1619 // Combine the output string. |
1619 $output = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) ); |
1620 $output = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) ); |
1620 $output .= join( "\n", $structure ); |
1621 $output .= implode( "\n", $structure ); |
1621 $output .= '</select>'; |
1622 $output .= '</select>'; |
1622 |
1623 |
1623 if ( $parsed_args['echo'] ) { |
1624 if ( $parsed_args['echo'] ) { |
1624 echo $output; |
1625 echo $output; |
1625 } |
1626 } |