textdomain_loaded[ $domain ] ) && true === $hoot->textdomain_loaded[ $domain ] ) ? true : false; } /** * Loads an empty MO file for the framework textdomain. This will be overwritten. The framework domain * will be merged with the theme domain. * * @since 1.0.0 * @access public * @param string $domain The name of the framework's textdomain. * @return bool Whether the MO file was loaded. */ function hoot_load_framework_textdomain( $domain ) { return load_textdomain( $domain, '' ); } /** * Gets the parent theme textdomain. This allows the framework to recognize the proper textdomain of the * parent theme. * * Important! Do not use this for translation functions in your theme. Hardcode your textdomain string. * Your theme's textdomain should match your theme's folder name. * * @since 1.0.0 * @access public * @global object $hoot * @return string The textdomain of the theme. */ function hoot_get_parent_textdomain() { global $hoot; /* If the global textdomain isn't set, define it. Plugin/theme authors may also define a custom textdomain. */ if ( empty( $hoot->parent_textdomain ) ) { $theme = wp_get_theme( get_template() ); $textdomain = $theme->get( 'TextDomain' ) ? $theme->get( 'TextDomain' ) : get_template(); $hoot->parent_textdomain = sanitize_key( apply_filters( 'hoot_parent_textdomain', $textdomain ) ); } /* Return the expected textdomain of the parent theme. */ return $hoot->parent_textdomain; } /** * Gets the child theme textdomain. This allows the framework to recognize the proper textdomain of the * child theme. * * Important! Do not use this for translation functions in your theme. Hardcode your textdomain string. * Your theme's textdomain should match your theme's folder name. * * @since 1.0.0 * @access public * @global object $hoot * @return string The textdomain of the child theme. */ function hoot_get_child_textdomain() { global $hoot; /* If a child theme isn't active, return an empty string. */ if ( !is_child_theme() ) return ''; /* If the global textdomain isn't set, define it. Plugin/theme authors may also define a custom textdomain. */ if ( empty( $hoot->child_textdomain ) ) { $theme = wp_get_theme(); $textdomain = $theme->get( 'TextDomain' ) ? $theme->get( 'TextDomain' ) : get_stylesheet(); $hoot->child_textdomain = sanitize_key( apply_filters( 'hoot_child_textdomain', $textdomain ) ); } /* Return the expected textdomain of the child theme. */ return $hoot->child_textdomain; } /** * Filters the 'load_textdomain_mofile' filter hook so that we can change the directory and file name * of the mofile for translations. This allows child themes to have a folder called /languages with * translations of their parent theme so that the translations aren't lost on a parent theme upgrade. * * @since 1.0.0 * @access public * @param string $mofile File name of the .mo file. * @param string $domain The textdomain currently being filtered. * @return string */ function hoot_load_textdomain_mofile( $mofile, $domain ) { /* If the $domain is for the parent or child theme, search for a $domain-$locale.mo file. */ if ( $domain == hoot_get_parent_textdomain() || $domain == hoot_get_child_textdomain() ) { /* Check for a $domain-$locale.mo file in the parent and child theme root and /languages folder. */ $locale = get_locale(); $locate_mofile = locate_template( array( "languages/{$domain}-{$locale}.mo", "{$domain}-{$locale}.mo" ) ); /* If a mofile was found based on the given format, set $mofile to that file name. */ if ( !empty( $locate_mofile ) ) $mofile = $locate_mofile; } /* Return the $mofile string. */ return $mofile; } /** * Gets the language for the currently-viewed page. It strips the region from the locale if needed * and just returns the language code. * * @since 1.0.0 * @access public * @param string $locale * @return string */ function hoot_get_language( $locale = '' ) { if ( empty( $locale ) ) $locale = get_locale(); return preg_replace( '/(.*?)_.*?$/i', '$1', $locale ); } /** * Gets the region for the currently viewed page. It strips the language from the locale if needed. * Note that not all locales will have a region, so this might actually return the same thing as * `hoot_get_language()`. * * @since 1.0.0 * @access public * @param string $locale * @return string */ function hoot_get_region( $locale = '' ) { if ( empty( $locale ) ) $locale = get_locale(); return preg_replace( '/.*?_(.*?)$/i', '$1', $locale ); }