Translate your WordPress Site for Each Users |
X

Congrats, You are Subscribed to Receive Updates.

Translate your WordPress Site for Each Users


Translate your WordPress Site for Each Users. Translating a WordPress site based on User choice is really easy with your theme development,  Here Let me explain you step by step to make your WordPress site perfectly viewed based on your registered users preferred language.

Screenshot_2016-4-13 19.11.41

we need to create language files such as .PO and .MO files for translating from one language to another.  Here I am taking Tamil(தமிழ்)`ta_IN` as my customization language to make it work on WordPress now.

Steps :

  1. Download POEdit From here.
  2. Install and create your own PO and  MO files by using it.

Screenshot_2016-4-13 19.21.15

After compiling PO and MO files you are almost ready to apply it on live.  now, you have to upload it on the current active themes directory by creating a separate folder.

Here I made a folder  “languages” and uploaded mine files.

Screenshot_2016-4-13 19.28.0

Now, you need to write all your theme words like this.

  __( 'Next', 'Kvcodes' )
  __( 'Previous', 'Kvcodes' )

Now, you can verify whether the language is working or not.

define("WPLANG", "ta_IN");

Place this code on wp-config.php.  And write the following function on theme `functions.php`.

/*****************************************
*Kvcodes Languages - Setup
****************************************/
if ( ! function_exists( 'kvcodes_setup' ) ) :

	function kvcodes_setup() {
		load_theme_textdomain( 'kvcodes', get_template_directory() . '/languages' );
	}
endif; // kvcodes_setup

Than you can check it on your browser.  This is constant method, which will not help you to create translations based on users.

Here is the function for language hook.  Just undo the `wp-config.php` added line.  Than add the following function on `functions.php`.

add_filter( 'locale', 'kvcodes_default_language' );
function kvcodes_default_language( $locale ){	
    return 'ta_IN';
}

The above one will hook the  Tamil language in default.  you have to create a drop down on registered users profile page and ask them to select their language.  And than save it as user meta.  You can retrieve the language code and hook the language file based on the users choice.  So it will  work for every users.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar