• Resolved makmerghen

    (@makmerghen)


    Hello
    is that possible
    I need to add language selector tab in account page so user can go there and select his default language that will work every time he log in the website

    please let me know how to do that
    best regards

Viewing 15 replies - 1 through 15 (of 22 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    Unfortunately, this requires customization on your end. We don’t have a custom code now so let’s see if others in the forum have done something similar and share their solution here.

    Regards,

    Thread Starter makmerghen

    (@makmerghen)

    I hope too thanks

    Thread Starter makmerghen

    (@makmerghen)

    hello @champsupertramp I got an idea if it possible please help
    there are in each user profile page in back end a language switcher
    so is it possible to do the next
    1- to add to UM registration form drop down switcher (contain English and Arabic to select one) and it is connected with the language switcher that existed in wordpress backend user profile page so if we select while doing registration then this will be selected in user profile page of wordpress
    or
    2- to add also this drop down in UM profile from and also it is connected to the main one of wrodpress profile page

    best regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    You can create the dropdown field with the meta key/field name locale. You need to set the Dropdown options to match the Site Language options values set in the WP Admin > Profile e.g. en_US for the English.

    If you want to display the option as “English” and its option value is “en_US”, you need to use the choices callback option. Please see this doc: https://docs.ultimatemember.com/article/1539-choices-callback-feature-in-um-2-1

    Here’s a sample choices callback code:

    function um_122321_local_choices() { 	
      $languages = array( 
           "en_US" => "English", 
           "ar" => "Arabic" 
      ); 		
      
      return $languages;         
    }

    Regards,

    Thread Starter makmerghen

    (@makmerghen)

    Dear @champsupertramp
    thank you very much it worked

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know.

    Regards,

    Thread Starter makmerghen

    (@makmerghen)

    Dear @champsupertramp
    I used this code to use Ultimate member fields with shortcode to be able to add any field in any page using shortcode

    // Display field data of Ultimate Member
    // e.g. [um_field_data userid="10' field="company_name"]
    add_shortcode( 'um_field_data', 'um_custom_field_shortcode' );
    
    if ( ! function_exists( 'um_custom_field_shortcode' ) ) {
    	function um_custom_field_shortcode( $atts = array() ){
    
    		$defaults = array(
    				'field' => NULL,
    				'userid' => NULL,
    		);
    
    		$atts = wp_parse_args( $atts, $defaults );
    		extract( $atts );
    
    		ob_start();
    
    		$user_id = um_user($atts['userid']);
    		um_fetch_user( $user_id );
    		$meta_value = um_user($atts['field']);
    
    		print_r($meta_value);
    
    	    $shortcode_content = ob_get_contents();
    	    ob_end_clean();
    
    	    return $shortcode_content;
    	}
    }

    it works with field like username , first name , last name
    but unfortunately
    it didn’t work with the language drop down field we created in this post it didn’t appear when I used [um_field_data field=locale]

    please advise
    regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    Please try this one:

    add_shortcode( 'um_field_data', 'um_custom_field_shortcode' );
    
    if ( ! function_exists( 'um_custom_field_shortcode' ) ) {
    	function um_custom_field_shortcode( $atts = array() ){
    
    		$defaults = array(
    				'field' => get_current_user_id(),
    				'userid' => NULL,
    		);
    
    		$atts = wp_parse_args( $atts, $defaults );
    		extract( $atts );
    
    		ob_start();
    
    		$user_id = um_fetch_user($atts['userid']);
    		$meta_value = um_user($atts['field']);
    
    		print_r($meta_value);
    
    	    $shortcode_content = ob_get_contents();
    	    ob_end_clean();
    
    	    return $shortcode_content;
    	}
    }

    Regards,

    Thread Starter makmerghen

    (@makmerghen)

    Dear @champsupertramp thank you for your rely
    the drop down field of the language, it appears only the test of the selected language
    but the drop down didn’t appear to let the current user can change the language

    so please advise how to show the drop down field to do the change
    best regards

    • This reply was modified 2 years, 4 months ago by makmerghen.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    Did you add the Language field to the Profile form so users can change the language? Also, did you add the callback function?

    function um_122321_local_choices() { 	
      $languages = array( 
           "en_US" => "English", 
           "ar" => "Arabic" 
      ); 		
      
      return $languages;         
    }

    Regards,

    Thread Starter makmerghen

    (@makmerghen)

    Dear @champsupertramp I didn’t but I did that now without any result
    I added the callback function but the language name appear en_US not English and ar not Arabic
    also I added the field to profile form in addition to registration form and user can edit it as any field when edit his profiel
    but
    when using [um_field_data field=locale] in any page it appear as text show en_US not to show check box to change the language

    so please advise
    best regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    1. The Locale’s choices callback works on me. Here’s the field setting:
    https://drive.google.com/file/d/17b4OkcOBgR0HAzM6hbejgFx-FSCXjFqP/view?usp=sharing

    2. Your shortcode only displays the current locale. It won’t display the field. You need another profile form and use a custom profile template without the header so it will look like a headerless form.

    Regards,

    Thread Starter makmerghen

    (@makmerghen)

    Dear @champsupertramp
    of point 1 I adjust it and it fixed but I have 2 issues on it
    1- after adding English and Arabic to “edit choice field” of the drop down and save the field and the form and then to open the field again to find edit choice field become empty
    2- if I add to this field Default Value = Arabic and open the registration field I found the language field is empty and no choose for Arabic as I did in the form setting

    regarding point 2 I did it and its work except removing the header and I need only the field
    how to find custom profile template without the header
    thank you and best regards

    • This reply was modified 2 years, 3 months ago by makmerghen.
    • This reply was modified 2 years, 3 months ago by makmerghen.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @makmerghen

    1. Since you are using a choices callback function, you need to modify it in the callback function and not in the choices field settings.

    2. Please try using ar or en_US as a default value and not the language label Arabic or English.

    Regards,

    Thread Starter makmerghen

    (@makmerghen)

    Dear @champsupertramp
    for point one I added the callback function you gave and try to save field without adding any thing in choices field and tried to save then I got error that I need to add choices

    2- I added ar as default value and also didn’t appear

    please advise
    best regards

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘add language switcher in account page’ is closed to new replies.