• In my simple case (bbpress and profile editing page) I need translations be loaded on frontend, as they are loaded only in admin user will se alway english texts, so do little patch for that.

    8a9,10
    >  * Text Domain: basic-user-avatars
    >  * Domain Path: /languages/
    49a52
    > 		add_action( 'after_setup_theme',         array( $this, 'after_setup_theme'        )        );
    66a70,77
    > 	 * Load translations
    > 	 */
    > 	public function after_setup_theme() {
    > 		// Load the textdomain so we can support other languages
    > 		load_plugin_textdomain( 'basic-user-avatars', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
    > 	}
    >
    > 	/**
    73,75d83
    < 		// Load the textdomain so we can support other languages
    < 		load_plugin_textdomain( 'basic-user-avatars', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
    <

    https://wordpress.org/plugins/basic-user-avatars/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,
    I am not a coder and therefore I cannot provide any further support to the following.

    If you want to use translation files for this plugin that work in the back- and front-end, then you will need to do add the following code to the init.php (version 1.0.0), at least it worked for me:

    Have a look at the parts that start with “Author: snowbeachking”.

    class basic_user_avatars {
    
    	private $user_id_being_edited;
    
    	/**
    	 * Initialize all the things
    	 *
    	 * @since 1.0.0
    	 */
    	public function __construct() {
    
    		// Actions
    		add_action( 'admin_init',                array( $this, 'admin_init'               )        );
    		add_action( 'show_user_profile',         array( $this, 'edit_user_profile'        )        );
    		add_action( 'edit_user_profile',         array( $this, 'edit_user_profile'        )        );
    		add_action( 'personal_options_update',   array( $this, 'edit_user_profile_update' )        );
    		add_action( 'edit_user_profile_update',  array( $this, 'edit_user_profile_update' )        );
    		add_action( 'bbp_user_edit_after_about', array( $this, 'bbpress_user_profile'     )        );
    		// Author: snowbeachking
    		// Calling load_plugin_textdomain() during the init action and not earlier.
    		add_action( 'init',                      array( $this, 'load_plugin_textdomain'   )        );
    
    		// Shortcode
    		add_shortcode( 'basic-user-avatars',     array( $this, 'shortcode'                )        );
    
    		// Filters
    		add_filter( 'get_avatar',                array( $this, 'get_avatar'               ), 10, 5 );
    		add_filter( 'avatar_defaults',           array( $this, 'avatar_defaults'          )        );
    
    	}
    
    	/**
    	 * Start the admin engine.
    	 *
    	 * @since 1.0.0
    	 */
    	public function admin_init() {
    
            /**
             * Author: snowbeachking
             * Disabled, because by the time you want to hook into the load_textdomain() function, it will be
             * too late already since the load_plugin_textdomain() call gets done immediately when the plugin
             * is loaded.
             * That is why we call load_plugin_textdomain() during the init action and not earlier.
             */
            // Load the textdomain so we can support other languages
    		// load_plugin_textdomain( 'basic-user-avatars', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
    
    		// Register/add the Discussion setting to restrict avatar upload capabilites
    		register_setting( 'discussion', 'basic_user_avatars_caps', array( $this, 'sanitize_options' ) );
    		add_settings_field( 'basic-user-avatars-caps', __( 'Local Avatar Permissions', 'basic-user-avatars' ), array( $this, 'avatar_settings_field' ), 'discussion', 'avatars' );
    	}
    
    	/**
    	 * Author: snowbeachking
    	 * load_plugin_textdomain() is called and gets told to load the applicable mo-files from the
    	 * subdirectory languages of the plugin’s directory or the default WordPress languages directory for
    	 * plugin translations.
    	 */
        public function load_plugin_textdomain() {
           load_plugin_textdomain( 'basic-user-avatars', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
        }

    Thank you very much for the tip. The plugin works like a charm, love it’s simplicity. Maybe the author should update the plugin with your code in the next version.

    In case somebody is interested in how I did it for the german translation:

    I di dthe updates as described above, after that I copied a .po file from another plugin into the /languages folder of the plugin and renamed it to basic-user-avatars-de_DE.po. There was one language string hardcoded in the file init.php, the value of the submit button of the frontend upload form, somewhere around Line 333. Simply replace that value with
    <?php _e( 'Update avatar', 'basic-user-avatars' ); ?>

    As the next step, open the .po file (should be with your locale instead of de_DE of course) in Poedit. It will show a lot of depreceated strings (from the plugin where this file was copied) and some new strings. Translate these and save the file. The needed .mo file will be generated automatically.

    Last step: Upload the directory /language from the plugin directory to your webspace, reload your page and you’re good to go 😉

    If the author is interested, I gladly chip in my translation. Simply drop me a line where do sent the files.

    Glad that it was useful to you.

    I have an update with even less code to be added. 😉

    class basic_user_avatars {
    
    	private $user_id_being_edited;
    
    	/**
    	 * Initialize all the things
    	 *
    	 * @since 1.0.0
    	 */
    	public function __construct() {
    
    		/**
    		 * Contributed by snowbeachking - Part 1 of 2
    		 * Description: The "load_plugin_textdomain" function loads the plugin's translated strings.
    		 * If the path is not given then it will be the root of the plugin directory or the default WordPress
    		 * languages directory for the .mo plugin translation files.
    		 * Calling the function as early as the plugins_loaded action to enable the localization of the
    		 * front end as well.
    		 */
    		/* BEGIN Part 1 of 2 */
    		load_plugin_textdomain( 'basic-user-avatars' );
    		/* END Part 1 of 2 */
    
    		// Actions
    		add_action( 'admin_init',                array( $this, 'admin_init'               )        );
    		add_action( 'show_user_profile',         array( $this, 'edit_user_profile'        )        );
    		add_action( 'edit_user_profile',         array( $this, 'edit_user_profile'        )        );
    		add_action( 'personal_options_update',   array( $this, 'edit_user_profile_update' )        );
    		add_action( 'edit_user_profile_update',  array( $this, 'edit_user_profile_update' )        );
    		add_action( 'bbp_user_edit_after_about', array( $this, 'bbpress_user_profile'     )        );
    
    		// Shortcode
    		add_shortcode( 'basic-user-avatars',     array( $this, 'shortcode'                )        );
    
    		// Filters
    		add_filter( 'get_avatar',                array( $this, 'get_avatar'               ), 10, 5 );
    		add_filter( 'avatar_defaults',           array( $this, 'avatar_defaults'          )        );
    
    	}
    
    	/**
    	 * Start the admin engine.
    	 *
    	 * @since 1.0.0
    	 */
    	public function admin_init() {
    
    		/**
    		 * Contributed by snowbeachking - Part 2 of 2
    		 * Description: Disabled, because by the time you want to hook into the "load_plugin_textdomain" function,
    		 * it will be too late already since the "load_plugin_textdomain" call gets done immediately
    		 * when the plugin is loaded.
    		 */
    		// Load the textdomain so we can support other languages
    		/* BEGIN Part 2 of 2 */
    		/* load_plugin_textdomain( 'basic-user-avatars', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); */
    		/* END Part 2 of 2 */

    Hi you have do add the follow code at beginn of the init.php That works.

    `class basic_user_avatars {

    private $user_id_being_edited;

    /**
    * Initialize all the things
    *
    * @since 1.0.0
    */
    public function __construct() {

    // Actions
    add_action( ‘admin_init’, array( $this, ‘admin_init’ ) );
    add_action( ‘show_user_profile’, array( $this, ‘edit_user_profile’ ) );
    add_action( ‘edit_user_profile’, array( $this, ‘edit_user_profile’ ) );
    add_action( ‘personal_options_update’, array( $this, ‘edit_user_profile_update’ ) );
    add_action( ‘edit_user_profile_update’, array( $this, ‘edit_user_profile_update’ ) );
    add_action( ‘bbp_user_edit_after_about’, array( $this, ‘bbpress_user_profile’ ) );
    add_action( ‘plugins_loaded’, array( $this, ‘localization_init’ ) );

    // Shortcode
    add_shortcode( ‘basic-user-avatars’, array( $this, ‘shortcode’ ) );

    // Filters
    add_filter( ‘get_avatar’, array( $this, ‘get_avatar’ ), 10, 5 );
    add_filter( ‘avatar_defaults’, array( $this, ‘avatar_defaults’ ) );

    }

    function localization_init() {
    $path = dirname(plugin_basename(__FILE__)) . ‘/languages/’;
    load_plugin_textdomain( ‘basic-user-avatars’, false, $path );
    }

    /**
    * Start the admin engine.
    *

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Translation in frontend’ is closed to new replies.