[wp-hackers] Default language/post language patch

Craig Hartel milquetoast at telus.net
Sun Jul 25 02:12:01 UTC 2004


I'm very encouraged to see people taking up the internationalization aspect of 
WP. One needs only to spend a short time on the forums and you quickly realize 
that WP is popular all across THIS planet and is not being developed as an 
Anglo-centric product. Good for you folks!

These kind of developments add significant credence to the WP vision. I 
appreciate this even more than sending spammers to a site to pay for their 
comments! LMAO.

Kudos!
Craig.
NuclearMoose.



Kitty wrote:
> Ok this is a revision of my earlier patch. It adds the default language
> information to the blog, but also adds a per-post default language
> setting.
> 
> I think this is a simple and complete solution that should be rolled
> into 1.3 for multi-language support. I think this is important enough to
> be part of the WP core, and shouldn't be left to a plugin.
> 
> If there's interest, I'll prepare a patch file for v1.2. Just ask.
> 
> If anyone is interesting in applying this patch, (Linux instructions) cd
> to your wordpress folder (current CVS only), then type the command: 
> patch -p0 < /path/to/.diff/file
> 
> And you should see a report of the following files patched:
> -index.php
> Adds template tags for default language, and post language.
> 
> -wp-admin/edit-form-advanced.php
> Adds the editing box for the per-post language.
> 
> -wp-admin/options-writing.php
> Adds the admin editing box for setting the default blog language.
> 
> -wp-admin/post.php
> Adds the necessary code so that the per-post language can be saved.
> 
> -wp-admin/upgrade-functions.php
> Adds the code to add the default option, and the column to the posts
> table to store the language. DB default is English.
> 
> -wp-admin/wp-admin.css
> Changes so that the 'Post Language' box looks the same as the others.
> 
> -wp-includes/functions.php
> Adds function 'blog_language()' for displaying the default language in
> the <HTML> tag. A XHTML 1.1 compatible output is commented out for
> future use.
> Adds function 'the_language()' for adding language info to the
> storycontent div.
> 
> Examples:
> Old index.php:
> <html xmlns="http://www.w3.org/1999/xhtml">
> <div class="storycontent">
> 
> New index.php:
> <html xmlns="http://www.w3.org/1999/xhtml"  lang="en" xml:lang="en">
> <div class="storycontent" lang="fr">
> 
> Also attached are 2 sceenshots, of the new interface (I've edited them
> down to save bandwidth.)
> 
> This patch as text of this email has been added to Mosquito.
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ------------------------------------------------------------------------
> 
> Index: index.php
> ===================================================================
> RCS file: /cvsroot/cafelog/wordpress/index.php,v
> retrieving revision 1.78
> diff -u -3 -r1.78 index.php
> --- index.php	10 Jul 2004 23:34:46 -0000	1.78
> +++ index.php	24 Jul 2004 23:16:02 -0000
> @@ -3,7 +3,7 @@
>  require('./wp-blog-header.php');
>  ?>
>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> -<html xmlns="http://www.w3.org/1999/xhtml">
> +<html xmlns="http://www.w3.org/1999/xhtml"  <?php blog_language(); ?>>
>  
>  <head profile="http://gmpg.org/xfn/1">
>  	<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
> @@ -39,7 +39,7 @@
>  	 <h3 class="storytitle" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h3>
>  	<div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> &#8212; <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
>  	
> -	<div class="storycontent">
> +	<div class="storycontent" <?php the_language() ?>>
>  		<?php the_content(); ?>
>  	</div>
>  	
> Index: wp-admin/edit-form-advanced.php
> ===================================================================
> RCS file: /cvsroot/cafelog/wordpress/wp-admin/edit-form-advanced.php,v
> retrieving revision 1.28
> diff -u -3 -r1.28 edit-form-advanced.php
> --- wp-admin/edit-form-advanced.php	14 Jul 2004 21:37:05 -0000	1.28
> +++ wp-admin/edit-form-advanced.php	24 Jul 2004 23:16:02 -0000
> @@ -46,6 +46,7 @@
>  $saveasdraft = '<input name="save" type="submit" id="save" tabindex="6" value="' . __('Save and Continue Editing') . '" />';
>  
>  if (empty($post_status)) $post_status = 'draft';
> +if (empty($post_language)) $post_language = get_settings('default_blog_language');
>  
>  ?>
>  
> @@ -93,11 +94,16 @@
>  <legend><?php _e('Post Slug') ?></legend>
>  <div><input name="post_name" type="text" size="17" id="post_name" value="<?php echo $post_name ?>" /></div>
>  </fieldset>
> +<div style="clear:both">
>      <fieldset id="postpassworddiv">
>        <legend><a href="http://wordpress.org/docs/reference/post/#post_password" title="<?php _e('Help on post password') ?>"><?php _e('Post Password') ?></a></legend> 
>  	  <div><input name="post_password" type="text" size="13" id="post_password" value="<?php echo $post_password ?>" /></div>
>      </fieldset>
> -
> +    <fieldset id="postlanguagediv">
> +      <legend><a href="http://wordpress.org/docs/reference/post/#post_language" title="<?php _e('Help on post Language') ?>"><?php _e('Post Language') ?></a></legend> 
> +	  <div><input name="post_language" type="text" size="2" maxlength="2" id="post_language" value="<?php echo $post_language ?>" /></div>
> +    </fieldset>
> +</div>
>  <br />
>  <fieldset style="clear:both">
>  <legend><a href="http://wordpress.org/docs/reference/post/#excerpt" title="<?php _e('Help with excerpts') ?>"><?php _e('Excerpt') ?></a></legend>
> Index: wp-admin/options-writing.php
> ===================================================================
> RCS file: /cvsroot/cafelog/wordpress/wp-admin/options-writing.php,v
> retrieving revision 1.21
> diff -u -3 -r1.21 options-writing.php
> --- wp-admin/options-writing.php	15 Jun 2004 23:24:35 -0000	1.21
> +++ wp-admin/options-writing.php	24 Jul 2004 23:16:03 -0000
> @@ -48,7 +48,7 @@
>    <h2>Writing Options</h2> 
>    <form name="form1" method="post" action="options.php"> 
>      <input type="hidden" name="action" value="update" /> 
> -    <input type="hidden" name="page_options" value="'default_post_edit_rows','use_smilies','use_balanceTags','advanced_edit','ping_sites','mailserver_url', 'mailserver_port','mailserver_login','mailserver_pass','default_category', 'default_email_category'" /> 
> +    <input type="hidden" name="page_options" value="'default_post_edit_rows','use_smilies','use_balanceTags','advanced_edit','ping_sites','mailserver_url', 'mailserver_port','mailserver_login','mailserver_pass','default_category', 'default_email_category', 'default_blog_language'" /> 
>      <table width="100%" cellspacing="2" cellpadding="5" class="editform"> 
>        <tr valign="top">
>          <th scope="row"> <?php _e('When starting a post, show:') ?> </th>
> @@ -87,6 +87,11 @@
>  ?>
>         			</select></td>
>         		</tr>
> +		<tr valign="top">
> +			<th scope="row"><?php _e('Default blog language:') ?></th>
> +			<td><input name="default_blog_language" id="default_blog_language" value="<?php echo get_settings('default_blog_language') ?>" size="2" maxlength="2" /> <a href="http://www.oasis-open.org/cover/iso639a.html"><?php _e('Lookup your language code.')?></a>
> +			</td>
> +		<tr>
>      </table> 
>      <fieldset class="options">
>  	<legend><?php _e('Update Services') ?></legend>
> Index: wp-admin/post.php
> ===================================================================
> RCS file: /cvsroot/cafelog/wordpress/wp-admin/post.php,v
> retrieving revision 1.70
> diff -u -3 -r1.70 post.php
> --- wp-admin/post.php	24 Jul 2004 03:22:49 -0000	1.70
> +++ wp-admin/post.php	24 Jul 2004 23:16:04 -0000
> @@ -71,6 +71,7 @@
>  		$ping_status = $_POST['ping_status'];
>  		if (empty($ping_status)) $ping_status = get_settings('default_ping_status');
>  		$post_password = $_POST['post_password'];
> +		if (empty($post_language)) $post_language = get_settings('default_blog_language');
>  		
>  		if (empty($post_name))
>  			$post_name = sanitize_title($post_title, $post_ID);
> @@ -111,15 +112,15 @@
>  
>  	if((get_settings('use_geo_positions')) && (strlen($latstr) > 2) && (strlen($lonstr) > 2) ) {
>  	$postquery ="INSERT INTO $wpdb->posts
> -			(ID, post_author, post_date, post_date_gmt, post_content, post_title, post_lat, post_lon, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt)
> +			(ID, post_author, post_date, post_date_gmt, post_content, post_title, post_lat, post_lon, post_excerpt,  post_status, comment_status, ping_status, post_password, post_language, post_name, to_ping, post_modified, post_modified_gmt)
>  			VALUES
> -			('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', $post_latf, $post_lonf,'$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt')
> +			('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', $post_latf, $post_lonf,'$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_language', '$post_name', '$trackback', '$now', '$now_gmt')
>  			";
>  	} else {
>  	$postquery ="INSERT INTO $wpdb->posts
> -			(ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt)
> +			(ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_language, post_name, to_ping, post_modified, post_modified_gmt)
>  			VALUES
> -			('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt')
> +			('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_language', '$post_name', '$trackback', '$now', '$now_gmt')
>  			";
>  	}
>  
> @@ -229,6 +230,7 @@
>  		$comment_status = $postdata->comment_status;
>  		$ping_status = $postdata->ping_status;
>  		$post_password = $postdata->post_password;
> +		$post_language = $postdata->post_language;
>  		$to_ping = $postdata->to_ping;
>  		$pinged = $postdata->pinged;
>  		$post_name = $postdata->post_name;
> @@ -302,6 +304,7 @@
>  		if (empty($ping_status)) $ping_status = 'closed';
>  		//if (!$_POST['ping_status']) $ping_status = get_settings('default_ping_status');
>  		$post_password = $_POST['post_password'];
> +		$post_language = $_POST['post_language'];
>  		$post_name = sanitize_title($_POST['post_name'], $post_ID);
>  		if (empty($post_name)) $post_name = sanitize_title($post_title);
>  		$trackback = $_POST['trackback_url'];
> @@ -357,6 +360,7 @@
>  			comment_status = '$comment_status',
>  			ping_status = '$ping_status',
>  			post_password = '$post_password',
> +			post_language = '$post_language',
>  			post_name = '$post_name',
>  			to_ping = '$trackback',
>  			post_modified = '$now',
> Index: wp-admin/upgrade-functions.php
> ===================================================================
> RCS file: /cvsroot/cafelog/wordpress/wp-admin/upgrade-functions.php,v
> retrieving revision 1.64
> diff -u -3 -r1.64 upgrade-functions.php
> --- wp-admin/upgrade-functions.php	15 Jul 2004 23:31:06 -0000	1.64
> +++ wp-admin/upgrade-functions.php	24 Jul 2004 23:16:07 -0000
> @@ -877,6 +877,12 @@
>          $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_description, option_admin_level) VALUES('default_email_category', 1, '1', 'by default posts by email will have this category', 8)");
>      }
>  
> +	if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'default_blog_language'")) {
> +        $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_description, option_admin_level) VALUES('default_blog_language', 1, 'en', 'by default this will identify the language of your blog', 8)");
> +    }
> +	
> +	maybe_add_column($wpdb->posts, 'post_language', "ALTER TABLE `$wpdb->posts` ADD `post_language` VARCHAR( 2 ) DEFAULT 'en' NOT NULL ;");
> +	
>  	if(!$wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = 'recently_edited'")) {
>          $wpdb->query("INSERT INTO $wpdb->options (option_name, option_type, option_value, option_admin_level) VALUES ('recently_edited', 3, '', 8)");
>      }
> Index: wp-admin/wp-admin.css
> ===================================================================
> RCS file: /cvsroot/cafelog/wordpress/wp-admin/wp-admin.css,v
> retrieving revision 1.58
> diff -u -3 -r1.58 wp-admin.css
> --- wp-admin/wp-admin.css	23 Jul 2004 07:50:21 -0000	1.58
> +++ wp-admin/wp-admin.css	24 Jul 2004 23:16:07 -0000
> @@ -426,7 +426,7 @@
>  	width: 10.4em;
>  }
>  
> -#titlediv, #poststatusdiv, #commentstatusdiv, #slugdiv, #postpassworddiv, #namediv, #uridiv, #emaildiv {
> +#titlediv, #poststatusdiv, #commentstatusdiv, #slugdiv, #postpassworddiv, #postlanguagediv, #namediv, #uridiv, #emaildiv {
>  	float: left;
>  	height: 6em;
>  	margin-right: 5px;
> Index: wp-includes/functions.php
> ===================================================================
> RCS file: /cvsroot/cafelog/wordpress/wp-includes/functions.php,v
> retrieving revision 1.133
> diff -u -3 -r1.133 functions.php
> --- wp-includes/functions.php	23 Jul 2004 09:26:37 -0000	1.133
> +++ wp-includes/functions.php	24 Jul 2004 23:16:10 -0000
> @@ -1865,4 +1865,15 @@
>      return $wp_query_state->home;
>  }
>  
> +function blog_language() {
> +	$lang = get_settings('default_blog_language');
> +	// This is for XHTML 1.0:
> +	echo 'lang="'.$lang.'" xml:lang="'.$lang.'"';
> +	// This is for XHTML 1.1:
> +	//	echo 'xml:lang="'.$lang.'"';
> +}
> +function the_language() {
> +	global $post;
> +	echo 'lang="'.$post->post_language.'"';
> +}
>  ?>
> \ No newline at end of file
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> hackers mailing list
> hackers at wordpress.org
> http://wordpress.org/mailman/listinfo/hackers_wordpress.org
> 
> 
> ------------------------------------------------------------------------
> 
> Incoming mail is certified Virus Free.
> Checked by AVG Anti-Virus (http://www.grisoft.com).
> Version: 7.0.253 / Virus Database: 263.4.8 - Release Date: 7/22/2004
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : /pipermail/hackers_wordpress.org/attachments/20040724/f8298504/signature.bin


More information about the hackers mailing list