Permalink
Browse files

Updates Hybrid Core's i18n functionality to properly allow themes to …

…translate Hybrid Core's strings.

git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@1010 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information...
1 parent 45d8cd0 commit e551e8158f74e01dd8545b6580874810655ffd50 greenshady committed Mar 9, 2012
Showing with 28 additions and 8 deletions.
  1. +19 −3 functions/i18n.php
  2. +9 −5 hybrid.php
View
@@ -13,6 +13,22 @@
*/
/**
+ * Checks if a textdomain's translation files have been loaded. This function behaves differently from
+ * WordPress core's is_textdomain_loaded(), which will return true after any translation function is run over
+ * a text string with the given domain. The purpose of this function is to simply check if the translation files
+ * are loaded.
+ *
+ * @since 1.3.0
+ * @access private This is only used internally by the framework for checking translations.
+ * @param string $domain The textdomain to check translations for.
+ */
+function hybrid_is_textdomain_loaded( $domain ) {
+ global $hybrid;
+
+ return ( isset( $hybrid->textdomain_loaded[$domain] ) && true === $hybrid->textdomain_loaded[$domain] ) ? true : false;
+}
+
+/**
* Loads the framework's translation files. The function first checks if the parent theme or child theme
* has the translation files housed in their '/languages' folder. If not, it sets the translation file the the
* framework '/languages' folder.
@@ -142,7 +158,7 @@ function hybrid_load_textdomain_mofile( $mofile, $domain ) {
function hybrid_gettext( $translated, $text, $domain ) {
/* Check if 'hybrid-core' is the current textdomain, there's no mofile for it, and the theme has a mofile. */
- if ( 'hybrid-core' == $domain && !is_textdomain_loaded( 'hybrid-core' ) && is_textdomain_loaded( hybrid_get_parent_textdomain() ) ) {
+ if ( 'hybrid-core' == $domain && !hybrid_is_textdomain_loaded( 'hybrid-core' ) && hybrid_is_textdomain_loaded( hybrid_get_parent_textdomain() ) ) {
/* Get the translations for the theme. */
$translations = &get_translations_for_domain( hybrid_get_parent_textdomain() );
@@ -174,11 +190,11 @@ function hybrid_extensions_gettext( $translated, $text, $domain ) {
if ( current_theme_supports( $domain ) ) {
/* If the framework mofile is loaded, use its translations. */
- if ( is_textdomain_loaded( 'hybrid-core' ) )
+ if ( hybrid_is_textdomain_loaded( 'hybrid-core' ) )
$translations = &get_translations_for_domain( 'hybrid-core' );
/* If the theme mofile is loaded, use its translations. */
- elseif ( is_textdomain_loaded( hybrid_get_parent_textdomain() ) )
+ elseif ( hybrid_is_textdomain_loaded( hybrid_get_parent_textdomain() ) )
$translations = &get_translations_for_domain( hybrid_get_parent_textdomain() );
/* If translations were found, translate the text. */
View
@@ -24,7 +24,7 @@
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package HybridCore
- * @version 1.3.0-beta-2
+ * @version 1.3.0-beta-3
* @author Justin Tadlock <justin@justintadlock.com>
* @copyright Copyright (c) 2008 - 2012, Justin Tadlock
* @link http://themehybrid.com/hybrid-core
@@ -162,16 +162,20 @@ function core() {
* @since 1.2.0
*/
function i18n() {
+ global $hybrid;
+
+ /* Get parent and child theme textdomains. */
+ $parent_textdomain = hybrid_get_parent_textdomain();
+ $child_textdomain = hybrid_get_child_textdomain();
/* Load the framework textdomain. */
- hybrid_load_framework_textdomain( 'hybrid-core' );
+ $hybrid->textdomain_loaded['hybrid-core'] = hybrid_load_framework_textdomain( 'hybrid-core' );
/* Load theme textdomain. */
- load_theme_textdomain( hybrid_get_parent_textdomain() );
+ $hybrid->textdomain_loaded[$parent_textdomain] = load_theme_textdomain( $parent_textdomain );
/* Load child theme textdomain. */
- if ( is_child_theme() )
- load_child_theme_textdomain( hybrid_get_child_textdomain() );
+ $hybrid->textdomain_loaded[$child_textdomain] = is_child_theme() ? load_child_theme_textdomain( $child_textdomain ) : false;
/* Get the user's locale. */
$locale = get_locale();

0 comments on commit e551e81

Please sign in to comment.