Skip to content

Commit

Permalink
Complete overhaul of how translations and internationalization is han…
Browse files Browse the repository at this point in the history
…dled in the framework. All textdomains should be hardcoded strings. Therefore, the previous method of using a function across both the framework and themes built from it won't work. See: http://markjaquith.wordpress.com/2011/10/06/translating-wordpress-plugins-and-themes-dont-get-clever/

The framework and its extensions now use unique textdomains.  However, the framework filters 'gettext' to load theme translations to handle text from the framework and extensions.  This method will only work is the theme appropriately uses the template directory as its textdomain.  It's a bit of a compromise, but hooks do exist for themes to correct any changes they want to make.

Added the i18n.php file to separate language functions.  Added a few functions to facilitate this major change.

git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@900 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information
greenshady committed Oct 6, 2011
1 parent 5883da0 commit abfcf47
Show file tree
Hide file tree
Showing 29 changed files with 365 additions and 397 deletions.
12 changes: 5 additions & 7 deletions admin/meta-box-post-seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function hybrid_meta_box_post_add_seo( $post_type, $post ) {

/* Only add meta box if current user can edit, add, or delete meta for the post. */
if ( current_user_can( 'edit_post_meta', $post->ID ) || current_user_can( 'add_post_meta', $post->ID ) || current_user_can( 'delete_post_meta', $post->ID ) )
add_meta_box( 'hybrid-core-post-seo', __( 'SEO', hybrid_get_textdomain() ), 'hybrid_meta_box_post_display_seo', $post_type, 'normal', 'high' );
add_meta_box( 'hybrid-core-post-seo', __( 'SEO', 'hybrid-core' ), 'hybrid_meta_box_post_display_seo', $post_type, 'normal', 'high' );
}

/**
Expand All @@ -36,24 +36,22 @@ function hybrid_meta_box_post_add_seo( $post_type, $post ) {
*/
function hybrid_meta_box_post_display_seo( $object, $box ) {

$domain = hybrid_get_textdomain(); ?>

<?php wp_nonce_field( basename( __FILE__ ), 'hybrid-core-post-seo' ); ?>
wp_nonce_field( basename( __FILE__ ), 'hybrid-core-post-seo' ); ?>

<p>
<label for="hybrid-document-title"><?php _e( 'Document Title:', $domain ); ?></label>
<label for="hybrid-document-title"><?php _e( 'Document Title:', 'hybrid-core' ); ?></label>
<br />
<input type="text" name="hybrid-document-title" id="hybrid-document-title" value="<?php echo esc_attr( get_post_meta( $object->ID, 'Title', true ) ); ?>" size="30" tabindex="30" style="width: 99%;" />
</p>

<p>
<label for="hybrid-meta-description"><?php _e( 'Meta Description:', $domain ); ?></label>
<label for="hybrid-meta-description"><?php _e( 'Meta Description:', 'hybrid-core' ); ?></label>
<br />
<textarea name="hybrid-meta-description" id="hybrid-meta-description" cols="60" rows="2" tabindex="30" style="width: 99%;"><?php echo esc_textarea( get_post_meta( $object->ID, 'Description', true ) ); ?></textarea>
</p>

<p>
<label for="hybrid-meta-keywords"><?php _e( 'Meta Keywords:', $domain ); ?></label>
<label for="hybrid-meta-keywords"><?php _e( 'Meta Keywords:', 'hybrid-core' ); ?></label>
<br />
<input type="text" name="hybrid-meta-keywords" id="hybrid-meta-keywords" value="<?php echo esc_attr( get_post_meta( $object->ID, 'Keywords', true ) ); ?>" size="30" tabindex="30" style="width: 99%;" />
</p>
Expand Down
4 changes: 2 additions & 2 deletions admin/meta-box-post-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function hybrid_meta_box_post_add_template( $post_type, $post ) {

/* Only add meta box if current user can edit, add, or delete meta for the post. */
if ( ( 'page' !== $post_type ) && ( current_user_can( 'edit_post_meta', $post->ID ) || current_user_can( 'add_post_meta', $post->ID ) || current_user_can( 'delete_post_meta', $post->ID ) ) )
add_meta_box( 'hybrid-core-post-template', __( 'Template', hybrid_get_textdomain() ), 'hybrid_meta_box_post_display_template', $post_type, 'side', 'default' );
add_meta_box( 'hybrid-core-post-template', __( 'Template', 'hybrid-core' ), 'hybrid_meta_box_post_display_template', $post_type, 'side', 'default' );
}

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ function hybrid_meta_box_post_display_template( $object, $box ) {
<?php } ?>
</select>
<?php } else { ?>
<?php _e( 'No templates exist for this post type.', hybrid_get_textdomain() ); ?>
<?php _e( 'No templates exist for this post type.', 'hybrid-core' ); ?>
<?php } ?>
</p>
<?php
Expand Down
14 changes: 6 additions & 8 deletions admin/meta-box-theme-about.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ function hybrid_meta_box_theme_add_about() {

/* Get theme information. */
$prefix = hybrid_get_prefix();
$domain = hybrid_get_textdomain();
$theme_data = hybrid_get_theme_data();

/* Adds the About box for the parent theme. */
add_meta_box( 'hybrid-core-about-theme', sprintf( __( 'About %1$s', $domain ), $theme_data['Title'] ), 'hybrid_meta_box_theme_display_about', hybrid_get_settings_page_name(), 'side', 'high' );
add_meta_box( 'hybrid-core-about-theme', sprintf( __( 'About %1$s', 'hybrid-core' ), $theme_data['Title'] ), 'hybrid_meta_box_theme_display_about', hybrid_get_settings_page_name(), 'side', 'high' );

/* If the user is using a child theme, add an About box for it. */
if ( is_child_theme() ) {
$child_data = hybrid_get_theme_data( 'stylesheet' );
add_meta_box( 'hybrid-core-about-child', sprintf( __( 'About %1$s', $domain ), $child_data['Title'] ), 'hybrid_meta_box_theme_display_about', hybrid_get_settings_page_name(), 'side', 'high' );
add_meta_box( 'hybrid-core-about-child', sprintf( __( 'About %1$s', 'hybrid-core' ), $child_data['Title'] ), 'hybrid_meta_box_theme_display_about', hybrid_get_settings_page_name(), 'side', 'high' );
}
}

Expand All @@ -48,39 +47,38 @@ function hybrid_meta_box_theme_display_about( $object, $box ) {

/* Get theme information. */
$prefix = hybrid_get_prefix();
$domain = hybrid_get_textdomain();

/* Grab theme information for the parent/child theme. */
$theme_data = ( ( 'hybrid-core-about-child' == $box['id'] ) ? hybrid_get_theme_data( 'stylesheet' ) : hybrid_get_theme_data() ); ?>

<table class="form-table">
<tr>
<th>
<?php _e( 'Theme:', $domain ); ?>
<?php _e( 'Theme:', 'hybrid-core' ); ?>
</th>
<td>
<a href="<?php echo $theme_data['URI']; ?>" title="<?php echo $theme_data['Title']; ?>"><?php echo $theme_data['Title']; ?></a>
</td>
</tr>
<tr>
<th>
<?php _e( 'Version:', $domain ); ?>
<?php _e( 'Version:', 'hybrid-core' ); ?>
</th>
<td>
<?php echo $theme_data['Version']; ?>
</td>
</tr>
<tr>
<th>
<?php _e( 'Author:', $domain ); ?>
<?php _e( 'Author:', 'hybrid-core' ); ?>
</th>
<td>
<?php echo $theme_data['Author']; ?>
</td>
</tr>
<tr>
<th>
<?php _e( 'Description:', $domain ); ?>
<?php _e( 'Description:', 'hybrid-core' ); ?>
</th>
<td>
<?php echo $theme_data['Description']; ?>
Expand Down
4 changes: 2 additions & 2 deletions admin/meta-box-theme-footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
function hybrid_meta_box_theme_add_footer() {

add_meta_box( 'hybrid-core-footer', __( 'Footer settings', hybrid_get_textdomain() ), 'hybrid_meta_box_theme_display_footer', hybrid_get_settings_page_name(), 'normal', 'high' );
add_meta_box( 'hybrid-core-footer', __( 'Footer settings', 'hybrid-core' ), 'hybrid_meta_box_theme_display_footer', hybrid_get_settings_page_name(), 'normal', 'high' );
}

/**
Expand All @@ -44,7 +44,7 @@ function hybrid_meta_box_theme_display_footer() {
); ?>

<p>
<span class="description"><?php _e( 'You can add custom <acronym title="Hypertext Markup Language">HTML</acronym> and/or shortcodes, which will be automatically inserted into your theme.', hybrid_get_textdomain() ); ?></span>
<span class="description"><?php _e( 'You can add custom <acronym title="Hypertext Markup Language">HTML</acronym> and/or shortcodes, which will be automatically inserted into your theme.', 'hybrid-core' ); ?></span>
</p>

<?php }
Expand Down
14 changes: 6 additions & 8 deletions admin/theme-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function hybrid_settings_page_init() {
/* Get theme information. */
$theme = hybrid_get_theme_data();
$prefix = hybrid_get_prefix();
$domain = hybrid_get_textdomain();

/* Register theme settings. */
register_setting(
Expand All @@ -41,8 +40,8 @@ function hybrid_settings_page_init() {

/* Create the theme settings page. */
$hybrid->settings_page = add_theme_page(
sprintf( esc_html__( '%1$s Theme Settings', $domain ), $theme['Name'] ), // Settings page name.
esc_html__( 'Theme Settings', $domain ), // Menu item name.
sprintf( esc_html__( '%1$s Theme Settings', 'hybrid-core' ), $theme['Name'] ), // Settings page name.
esc_html__( 'Theme Settings', 'hybrid-core' ), // Menu item name.
hybrid_settings_page_capability(), // Required capability.
'theme-settings', // Screen name.
'hybrid_settings_page' // Callback function.
Expand Down Expand Up @@ -158,13 +157,12 @@ function hybrid_settings_page() {

/* Get the theme information. */
$prefix = hybrid_get_prefix();
$domain = hybrid_get_textdomain();
$theme_data = hybrid_get_theme_data(); ?>

<div class="wrap">

<?php screen_icon(); ?>
<h2><?php printf( __( '%1$s Theme Settings', $domain ), $theme_data['Name'] ); ?></h2>
<h2><?php printf( __( '%1$s Theme Settings', 'hybrid-core' ), $theme_data['Name'] ); ?></h2>
<?php settings_errors(); ?>

<div class="hybrid-core-settings-wrap">
Expand All @@ -181,7 +179,7 @@ function hybrid_settings_page() {
<div class="post-box-container column-3 advanced"><?php do_meta_boxes( hybrid_get_settings_page_name(), 'advanced', null ); ?></div>
</div>

<?php submit_button( esc_attr__( 'Update Settings', $domain ) ); ?>
<?php submit_button( esc_attr__( 'Update Settings', 'hybrid-core' ) ); ?>

</form>

Expand Down Expand Up @@ -235,11 +233,11 @@ function hybrid_settings_page_contextual_help() {

/* Add the Documentation URI. */
if ( !empty( $theme['Documentation URI'] ) )
$help .= '<li><a href="' . esc_url( $theme['Documentation URI'] ) . '">' . __( 'Documentation', hybrid_get_textdomain() ) . '</a></li>';
$help .= '<li><a href="' . esc_url( $theme['Documentation URI'] ) . '">' . __( 'Documentation', 'hybrid-core' ) . '</a></li>';

/* Add the Support URI. */
if ( !empty( $theme['Support URI'] ) )
$help .= '<li><a href="' . esc_url( $theme['Support URI'] ) . '">' . __( 'Support', hybrid_get_textdomain() ) . '</a></li>';
$help .= '<li><a href="' . esc_url( $theme['Support URI'] ) . '">' . __( 'Support', 'hybrid-core' ) . '</a></li>';

/* Close the unordered list for the help text. */
$help .= '</ul>';
Expand Down
33 changes: 12 additions & 21 deletions classes/widget-archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,16 @@
*/
class Hybrid_Widget_Archives extends WP_Widget {

/**
* Textdomain for the widget.
* @since 0.7.0
*/
var $textdomain;

/**
* Set up the widget's unique name, ID, class, description, and other options.
* @since 1.2.0
*/
function __construct() {

/* Set the widget textdomain. */
$this->textdomain = hybrid_get_textdomain();

/* Set up the widget options. */
$widget_options = array(
'classname' => 'archives',
'description' => esc_html__( 'An advanced widget that gives you total control over the output of your archives.', $this->textdomain )
'description' => esc_html__( 'An advanced widget that gives you total control over the output of your archives.', 'hybrid-core' )
);

/* Set up the widget control options. */
Expand All @@ -47,7 +38,7 @@ function __construct() {
/* Create the widget. */
$this->WP_Widget(
'hybrid-archives', // $this->id_base
__( 'Archives', $this->textdomain ), // $this->name
__( 'Archives', 'hybrid-core' ), // $this->name
$widget_options, // $this->widget_options
$control_options // $this->control_options
);
Expand Down Expand Up @@ -86,19 +77,19 @@ function widget( $args, $instance ) {

/* Create a title for the drop-down based on the archive type. */
if ( 'yearly' == $args['type'] )
$option_title = esc_html__( 'Select Year', $this->textdomain );
$option_title = esc_html__( 'Select Year', 'hybrid-core' );

elseif ( 'monthly' == $args['type'] )
$option_title = esc_html__( 'Select Month', $this->textdomain );
$option_title = esc_html__( 'Select Month', 'hybrid-core' );

elseif ( 'weekly' == $args['type'] )
$option_title = esc_html__( 'Select Week', $this->textdomain );
$option_title = esc_html__( 'Select Week', 'hybrid-core' );

elseif ( 'daily' == $args['type'] )
$option_title = esc_html__( 'Select Day', $this->textdomain );
$option_title = esc_html__( 'Select Day', 'hybrid-core' );

elseif ( 'postbypost' == $args['type'] || 'alpha' == $args['type'] )
$option_title = esc_html__( 'Select Post', $this->textdomain );
$option_title = esc_html__( 'Select Post', 'hybrid-core' );

/* Output the <select> element and each <option>. */
echo '<p><select name="archive-dropdown" onchange=\'document.location.href=this.options[this.selectedIndex].value;\'>';
Expand Down Expand Up @@ -147,7 +138,7 @@ function form( $instance ) {

/* Set up the default form values. */
$defaults = array(
'title' => esc_attr__( 'Archives', $this->textdomain ),
'title' => esc_attr__( 'Archives', 'hybrid-core' ),
'limit' => 10,
'type' => 'monthly',
'format' => 'html',
Expand All @@ -160,15 +151,15 @@ function form( $instance ) {
$instance = wp_parse_args( (array) $instance, $defaults );

/* Create an array of archive types. */
$type = array( 'alpha' => esc_attr__( 'Alphabetical', $this->textdomain ), 'daily' => esc_attr__( 'Daily', $this->textdomain ), 'monthly' => esc_attr__( 'Monthly', $this->textdomain ),'postbypost' => esc_attr__( 'Post By Post', $this->textdomain ), 'weekly' => esc_attr__( 'Weekly', $this->textdomain ), 'yearly' => esc_attr__( 'Yearly', $this->textdomain ) );
$type = array( 'alpha' => esc_attr__( 'Alphabetical', 'hybrid-core' ), 'daily' => esc_attr__( 'Daily', 'hybrid-core' ), 'monthly' => esc_attr__( 'Monthly', 'hybrid-core' ),'postbypost' => esc_attr__( 'Post By Post', 'hybrid-core' ), 'weekly' => esc_attr__( 'Weekly', 'hybrid-core' ), 'yearly' => esc_attr__( 'Yearly', 'hybrid-core' ) );

/* Create an array of archive formats. */
$format = array( 'custom' => esc_attr__( 'Custom', $this->textdomain ), 'html' => esc_attr__( 'HTML', $this->textdomain ), 'option' => esc_attr__( 'Option', $this->textdomain ) );
$format = array( 'custom' => esc_attr__( 'Custom', 'hybrid-core' ), 'html' => esc_attr__( 'HTML', 'hybrid-core' ), 'option' => esc_attr__( 'Option', 'hybrid-core' ) );
?>

<div class="hybrid-widget-controls columns-2">
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', $this->textdomain ); ?></label>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'hybrid-core' ); ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" />
</p>
<p>
Expand Down Expand Up @@ -204,7 +195,7 @@ function form( $instance ) {
</p>
<p>
<label for="<?php echo $this->get_field_id( 'show_post_count' ); ?>">
<input class="checkbox" type="checkbox" <?php checked( $instance['show_post_count'], true ); ?> id="<?php echo $this->get_field_id( 'show_post_count' ); ?>" name="<?php echo $this->get_field_name( 'show_post_count' ); ?>" /> <?php _e( 'Show post count?', $this->textdomain ); ?> <code>show_post_count</code></label>
<input class="checkbox" type="checkbox" <?php checked( $instance['show_post_count'], true ); ?> id="<?php echo $this->get_field_id( 'show_post_count' ); ?>" name="<?php echo $this->get_field_name( 'show_post_count' ); ?>" /> <?php _e( 'Show post count?', 'hybrid-core' ); ?> <code>show_post_count</code></label>
</p>
</div>
<div style="clear:both;">&nbsp;</div>
Expand Down
Loading

0 comments on commit abfcf47

Please sign in to comment.