WordPress.org

Ready to get started?Download WordPress

Forums

BAW Login/Logout menu
[Plugin: BAW Login Logout Menu] [PATCH] Translation support for #bawloginout# (6 posts)

  1. Daedalon
    Member
    Posted 1 year ago #

    Dear Julio,

    BAW Login/Logout Menu supports qTranslate's quicktags excellently in #bawregister#. When having [:en]Register[:fi]Rekisteröidy as the menu text then "Register" is displayed for non-logged-in users who use the site in English, "Rekisteröidy" for non-logged-in users who use the site in Finnish.

    However, in #bawloginout# this doesn't work. I've tried varying combinations, but none of them works as intended.

    [:en]Log in|Log out[:fi]Kirjaudu sisään|Kirjaudu ulos displays for non-logged-in users "(English) Log in" and for logged-in users "Log outKirjaudu sisään", both regardless of the language.

    [:en]Log in[:fi]Kirjaudu sisään|[:en]Log out[:fi]Kirjaudu ulos displays for non-logged-in users "Kirjaudu sisään" and for logged-in-users "Kirjaudu sisään", both regardless of the language.

    With the following patch BAWLL will use WP core translations for this field, and having Log in|Log out as the menu item name will result in correct text in all translations that are currently installed. In bawllm.php, find line 35:

    $item->title = bawllm_loginout_title( $item->title ) ; break;

    and replace it with

    $item->title = __( bawllm_loginout_title( $item->title ) ); break;

    The only change is wrapping the title in the automatically translating __() function, in case anyone is wondering.

    Possibly the line number 182 can be updated to similarly change the name of type_label from "Connection" to any language through __(), not only French.

    http://wordpress.org/extend/plugins/baw-login-logout-menu/

  2. Daedalon
    Member
    Posted 1 year ago #

    If the same change is applied to all the other shortcodes as well, they too will support automatic translations from WP core without the need for a separate plugin like qTranslate. At the moment the other shortcodes don't make any adjustments in the $item->title, so those lines would need to be added with the appropriate enclosing __() functions.

  3. Julio Potier
    Member
    Plugin Author

    Posted 1 year ago #

    mmm i see, but __() waits for a string, not a variable. if i do this, i'm doing it wrong :o
    So, i'll think about that but not sure to implement that.
    I'll think also for a solution for this ;)

    See you !

  4. Daedalon
    Member
    Posted 1 year ago #

    As I understand the documentation of __(), the above patch is as __() is intended to be used:

    Usage

    <?php $translated_text = __( $text, $domain ); ?>

  5. Daedalon
    Member
    Posted 1 year ago #

    To add WP core translation support for all the BAWLLM items, replace in bawllm.php these lines 30-38:

    case '#bawloginout#' :
    									$item_redirect = explode( '|', $item_redirect );
    									if( count( $item_redirect ) != 2 )
    										$item_redirect[1] = $item_redirect[0];
    									$item->url = is_user_logged_in() ? wp_logout_url( $item_redirect[1] ) : wp_login_url( $item_redirect[0] );
    									$item->title = bawllm_loginout_title( $item->title ) ; break;
    			case '#bawlogin#' : 	$item->url = wp_login_url( $item_redirect ); break;
    			case '#bawlogout#' : 	$item->url = wp_logout_url( $item_redirect ); break;
    			case '#bawregister#' : 	if( is_user_logged_in() ) $item = null; else $item->url = site_url( 'wp-login.php?action=register', 'login' ); break;

    with

    case '#bawloginout#':
    				$item_redirect = explode( '|', $item_redirect );
    				if( count( $item_redirect ) != 2 )
    				$item_redirect[1] = $item_redirect[0];
    				$item->url = is_user_logged_in() ? wp_logout_url( $item_redirect[1] ) : wp_login_url( $item_redirect[0] );
    				$item->title = __( bawllm_loginout_title( $item->title ) );
    				break;
    			case '#bawlogin#':
    				$item->url = wp_login_url( $item_redirect );
    				$item->title = __( bawllm_loginout_title( $item->title ) );
    				break;
    			case '#bawlogout#':
    				$item->url = wp_logout_url( $item_redirect );
    				$item->title = __( bawllm_loginout_title( $item->title ) );
    				break;
    			case '#bawregister#':
    				if( is_user_logged_in() ) {
    					$item = null;
    				} else {
    					$item->url = site_url( 'wp-login.php?action=register', 'login' );
    					$item->title = __( bawllm_loginout_title( $item->title ) );
    				}
    				break;
  6. Daedalon
    Member
    Posted 1 year ago #

    Julio, what do you think, would it be safer to change the line 49 from

    $item->url = site_url( 'wp-login.php?action=register', 'login' );

    to

    $item->url = wp_login_url() . '?action=register';?

    It's too bad that WP doesn't have a built-in wp_registration_url(). That would enable sites to choose to have an URL like example.com/register/ that would be referred to by all the plugins and themes.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.