Skip to content

Commit

Permalink
Addition of child theme textdomain functionality. First pass.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@743 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information
greenshady committed May 25, 2011
1 parent 2cf229c commit 9398f0a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
34 changes: 28 additions & 6 deletions functions/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ function hybrid_get_prefix() {
}

/**
* Defines the theme textdomain. This allows the framework to recognize the proper textdomain
* of the theme. Theme developers building from the framework should use their template name
* (i.e., directory name) as their textdomain within template files.
* Defines the theme textdomain. This allows the framework to recognize the proper textdomain of the
* parent theme. Theme developers building from the framework should use this function in their templates
* to easily define the correct textdomain.
*
* @since 0.7.0
* @uses get_template() Defines the theme textdomain based on the theme directory.
* @uses get_template() Defines the theme textdomain based on the template directory.
* @global object $hybrid The global Hybrid object.
* @return string $hybrid->textdomain The textdomain of the theme.
*/
Expand All @@ -49,6 +49,28 @@ function hybrid_get_textdomain() {
return $hybrid->textdomain;
}

/**
* Returns the textdomain for the child theme.
*
* @since 1.2.0
* @uses get_stylesheet() Defines the child theme textdomain based on the stylesheet directory.
* @global object $hybrid The global Hybrid object.
* @return string $hybrid->child_theme_textdomain The textdomain of the child theme.
*/
function hybrid_get_child_theme_textdomain() {
global $hybrid;

/* 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( $hybrid->child_theme_textdomain ) )
$hybrid->child_theme_textdomain = sanitize_key( apply_filters( hybrid_get_prefix() . '_child_theme_textdomain', get_stylesheet() ) );

return $hybrid->child_theme_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
Expand All @@ -60,8 +82,8 @@ function hybrid_get_textdomain() {
*/
function hybrid_load_textdomain( $mofile, $domain ) {

/* If the $domain is for the parent theme, search for a $domain-$locale.mo file. */
if ( $domain == hybrid_get_textdomain() ) {
/* If the $domain is for the parent or child theme, search for a $domain-$locale.mo file. */
if ( $domain == hybrid_get_textdomain() || $domain == hybrid_get_child_theme_textdomain() ) {

/* Check for a $domain-$locale.mo file in the parent and child theme root and /languages folder. */
$locale = get_locale();
Expand Down
7 changes: 4 additions & 3 deletions hybrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ function core() {

/* Load the context-based functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'context.php' );

/* Load the bbPress functions. */
if ( class_exists( 'bbPress' ) ) require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'bbpress.php' );
}

/**
Expand All @@ -166,6 +163,10 @@ function locale() {
/* Load theme textdomain. */
load_theme_textdomain( hybrid_get_textdomain() );

/* Load child theme textdomain. */
if ( is_child_theme() )
load_child_theme_textdomain( hybrid_get_child_theme_textdomain() );

/* Get the user's locale. */
$locale = get_locale();

Expand Down

0 comments on commit 9398f0a

Please sign in to comment.