WordPress.org

Forums

[resolved] Internationalize Posted On (10 posts)

  1. Guido
    Member
    Posted 12 months ago #

    Hi,

    I'm working on a update of my theme and want to make the Posted On internationalized, so translators are able to change position of date.

    My old code was:

    <?php _e('Posted on ', 'themename'); ?><a href="<?php the_permalink(); ?>"><?php echo get_the_date(); ?></a>

    Works fine but translators are not able to change position of date.
    So, this is my new code:

    <?php printf( __( 'Posted on %s', 'themename' ), '<a href="<?php the_permalink(); ?>"><?php echo get_the_date(); ?></a>' );  ?>

    But date is not displayed anymore, what am I doing wrong?

    Guido

  2. Jose Castaneda
    THEME COFFEE MONKEY
    Posted 12 months ago #

    Try:

    $string = __( "Posted on <a href='%1$s'>%2$s</a>", 'theme-domain' );
    printf( $string, get_the_permanlink(), get_the_date() );
  3. Guido
    Member
    Posted 12 months ago #

    Thanks.
    Guess I need to add this in functions file and call it from there?

    If yes, what's the best way to call it?

    Guido

  4. Jose Castaneda
    THEME COFFEE MONKEY
    Posted 12 months ago #

    Unfortunately I don't know how your theme is structured/coded. I can only guess but it will be with some meta information or post related information.

  5. Guido
    Member
    Posted 12 months ago #

    Ok, when I add a function to it:

    function themename_posted_on() {
    $string = __( "Posted on <a href='%1$s'>%2$s</a>", 'themename' ); printf( $string, get_permalink(), get_the_date() );
    }

    How should I load this function in frontend?
    Sorry, I am not are hardcore programmer ;-)

    Guido

  6. Guido
    Member
    Posted 12 months ago #

    After hours of trying I guess adding a function to this is not the way to handle this.

    Guido

  7. Jose Castaneda
    THEME COFFEE MONKEY
    Posted 12 months ago #

    You don't really need to wrap it in a function definition. If you are going with something like that then you could try:

    function post_date(){
        printf( __(  "Posted on <a href='%s'>%s</a>", 'theme-domain' ),
            get_the_permalink(),
            get_the_date( get_option( 'date_format' )
             ) );
    }

    Do keep in mind that the first parameter will only work with WP3.9+ because of the get_the_permalink function being introduced in 3.9. It will cause a fatal error to an undefined function in prior versions. :)

  8. Guido
    Member
    Posted 12 months ago #

    Thanks.
    Meanwhile I also got support at my themes.trac page:
    https://themes.trac.wordpress.org/ticket/17044#comment:50

    Solved :-) !

    Guido

  9. Jose Castaneda
    THEME COFFEE MONKEY
    Posted 12 months ago #

    Awesome. Glad you got it sorted out.

  10. Jose Castaneda
    THEME COFFEE MONKEY
    Posted 12 months ago #

    Awesome. Glad you got it sorted out.

Reply

You must log in to post.

About this Topic