Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 10 replies, has 2 voices.

Last updated by Dorian 9 years, 3 months ago.

Assigned support staff: sarah.n.

Author Posts
October 18, 2012 at 5:07 am #80424

Dorian

Hello,
My site is in English and Chinese (orig. language being English).

The date format for Chinese posts is erroneous: while the individual strings are translated (October translated as "十月" etc.), their order still follows the English one, instead of the Chinese.

For example, "October 18, 2012" should be rendered as "2012年10月18日" -- but on the site, it is translated as "十月18,2012". (see for ex. hidden link)

What is weirder is that if I modify the date format through the Dashboard (to "2012/10/18" for instance), nothing changes -- neither in English nor in Chinese.

Besides, I went through the String Translation module of WPML, and the relevant date strings (for the WordPress package at least) seem to be translated correctly (i.e. right order etc.)

It looks like it's my theme messing around (no problem with other themes), but I don't know where/how to correct this issue...?

Cheers,
Dorian

October 18, 2012 at 7:28 am #80453

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Hello Dorian,

Can you please locate the code in your theme that outputs the date and paste it here?

October 19, 2012 at 7:04 am #80655

Dorian

Hi Sarah,
Actually your question put me on a track I should've though of by myself -- in the Chinese code part of the theme templates, I simply replace "the_time('F d, Y')" with "the_time('y年m月d日')", and things are good.

However, there is still one time output with which I'm not sure how to deal with: in the link provided above, you'll notice, in the widget column to the right, a widget called "Recent Posts". The dates in this one are always in English.

The code generating this widget is, I think:

	echo '<li id="thumbwidget">'; 
		echo '<h3>'.$title.'</h3>';
		echo '<ul>';
			while  ($recent_posts->have_posts()) : $recent_posts->the_post(); ?>
            <li>
            	<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">	
				<?php if ( has_post_thumbnail() ) {
						the_post_thumbnail('thumbnail');
					} else { ?>
						<img src="<?php get_template_directory_uri(); ?>/images/small-pic.png" alt="No Post Image for <?php the_title(); ?>" />
                <?php }	?>
                </a>
                <p><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php echo ShortenTitle(get_the_title()); ?></a><br />
                <span><?php the_time('F d, Y'); ?></span></p>
            </li>
            <?php endwhile;
		echo '</ul>';
		echo '</li>';
		}
	}
	function update( $new_instance, $old_instance ) {  
		$instance = $old_instance; 
		
		/* Strip tags (if needed) and update the widget settings. */
		$instance['title'] = strip_tags( $new_instance['title'] );
		$instance['show'] = strip_tags( $new_instance['show'] );

		return $instance;
	}

(extracted from my theme (Seso) > inc > widgets.php

How should I use WPML to output multilingually the date string set in this widgets file?

Best,
Dorian

October 19, 2012 at 9:03 am #80682

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Hello Dorian,

Thank you for returning to this thread with your reply.

The code that outputs the date in the above widget is:

<?php the_time('F d, Y'); ?>

I would suggest you try replacing that bit of code with this:

<?php if(ICL_LANGUAGE_CODE == 'zh'){the_time('y年m月d日')}else{the_time('F d, Y');}?>

Let me know how this works for you.

October 19, 2012 at 9:17 am #80687

Dorian

Hi Sarah,
Unfortunately this doesn't work -- my site just produces a blank page with this code.
Would there be an "echo" technique I could use? I remember having seen this somewhere on the support here...

Best,
D-

October 19, 2012 at 11:23 am #80707

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Dorian,

Please paste the entire template code from widgets.php for me in http://pastebin.com/

October 19, 2012 at 11:31 am #80711

Dorian

Hi Sarah,
Here goes: http://pastebin.com/dEsFaMHr

October 19, 2012 at 11:58 am #80719

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Thank you Dorian,

I've edited it for you: http://pastebin.com/7S9kztHa

Please replace the time parameters for:

if($sitepress->get_current_language() == 'zh') {
	$get_the_time = get_the_time('F d, Y');
}

to those you want for the chinese version.

Let me know if this works.

October 19, 2012 at 3:55 pm #80771

Dorian

Thanks for your help Sarah, but if I replace that bit of code by the one you suggest, the widget breaks: only the title of the first post of the list is shown, but the date isn't, and neither are the other posts... See here (bottom-right corner) for instance: hidden link

At least I hope I didn't make any mistake in following your instructions -- the final codeline should be this, right?

<span><?php if($sitepress->get_current_language() == 'zh') {$get_the_time = get_the_time('y年m月d日');}?></span>
October 22, 2012 at 6:45 am #80884

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Dorian,

Did you take the edited code from the link I provided? Did you upload the entire file?

If you have and it still does not work please email me temporary wp-admin and FTP login credentials so I can assist you further.

You can email the information to [email]. Please do not forget to include the topic of this thread in the subject line as referense!

October 23, 2012 at 9:56 am #81231

Dorian

Hadn't copied the whole file -- works fine now.
Thanks a lot Sarah!