+ /**
+ * Filter a theme's locale.
+ *
+ * @since 3.0.0
+ *
+ * @param string $locale The theme's current locale.
+ * @param string $domain Text domain. Unique identifier for retrieving translated strings.
+ */
+ $locale = apply_filters( 'theme_locale', $locale, $domain );
+
+ if ( ! $path )
+ $path = get_template_directory();
+
+ // Load the textdomain according to the theme
+ $mofile = "{$path}/{$locale}.mo";
+ if ( $loaded = load_textdomain( $domain, $mofile ) )
+ return $loaded;
+
+ // Otherwise, load from the languages directory
+ $mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo";
+ return load_textdomain( $domain, $mofile );
+}
+
+/**
+ * Load the child themes translated strings.
+ *
+ * If the current locale exists as a .mo file in the child themes
+ * root directory, it will be included in the translated strings by the $domain.
+ *
+ * The .mo files must be named based on the locale exactly.
+ *
+ * @since 2.9.0
+ *
+ * @param string $domain Text domain. Unique identifier for retrieving translated strings.
+ * @return bool True when the theme textdomain is successfully loaded, false otherwise.
+ */
+function load_child_theme_textdomain( $domain, $path = false ) {
+ if ( ! $path )
+ $path = get_stylesheet_directory();
+ return load_theme_textdomain( $domain, $path );
+}
+
+/**
+ * Return the Translations instance for a text domain.
+ *
+ * If there isn't one, returns empty Translations instance.
+ *
+ * @param string $domain Text domain. Unique identifier for retrieving translated strings.
+ * @return Translations A Translations instance.
+ */
+function get_translations_for_domain( $domain ) {
+ global $l10n;
+ if ( !isset( $l10n[$domain] ) ) {
+ $l10n[$domain] = new NOOP_Translations;
+ }
+ return $l10n[$domain];
+}
+
+/**
+ * Whether there are translations for the text domain.
+ *
+ * @since 3.0.0
+ * @param string $domain Text domain. Unique identifier for retrieving translated strings.
+ * @return bool Whether there are translations.
+ */
+function is_textdomain_loaded( $domain ) {
+ global $l10n;
+ return isset( $l10n[$domain] );
+}
+
+/**
+ * Translates role name.
+ *
+ * Since the role names are in the database and not in the source there
+ * are dummy gettext calls to get them into the POT file and this function
+ * properly translates them back.
+ *
+ * The before_last_bar() call is needed, because older installs keep the roles
+ * using the old context format: 'Role name|User role' and just skipping the
+ * content after the last bar is easier than fixing them in the DB. New installs
+ * won't suffer from that problem.
+ *
+ * @since 2.8.0
+ *
+ * @param string $name The role name.
+ * @return string Translated role name on success, original name on failure.
+ */
+function translate_user_role( $name ) {
+ return translate_with_gettext_context( before_last_bar($name), 'User role' );
+}
+
+/**
+ * Get all available languages based on the presence of *.mo files in a given directory.
+ *
+ * The default directory is WP_LANG_DIR.
+ *
+ * @since 3.0.0
+ *
+ * @param string $dir A directory to search for language files.
+ * Default WP_LANG_DIR.
+ * @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.
+ */
+function get_available_languages( $dir = null ) {
+ $languages = array();
+
+ foreach( (array)glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ) as $lang_file ) {
+ $lang_file = basename($lang_file, '.mo');
+ if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) &&
+ 0 !== strpos( $lang_file, 'admin-' ))
+ $languages[] = $lang_file;
+ }