How to make WordPress Themes or Plugins Translation Ready

Translation Ready Themes Featured Image

It’s no secret that WordPress is used around the world. So it’s a good idea to ensure that themes and plugins can be easily translated into other languages. Adding internationalization and localization support by having a translation ready WordPress theme can greatly increase its market share.

Difference Between Internationalization and Localization

Internationalization is the process of developing a plugin/theme so it can easily be translated into other languages.

Localization describes the subsequent process of translating an internationalized plugin into a new language.

Side Note: It’s worth noting that internationalization is often abbreviated as i18n (because there are 18 letters between the ‘i’ and the ‘n’), and localization is shortened to l10n (because there are 10 letters between the ‘l’ and the ‘n’.)

The localization process can be done using a software called Poedit with three types of language files: the POT file (that contains a list of all translatable messages in the WordPress theme), the .PO file (created when you translate a POT file to a particular language) and the .MO file (a binary file that is created automatically by Poedit and is not human-readable).

Translation Ready Themes

There is some confusion about what a translation-ready theme actually means. So let’s clear up any possible confusion and explain what this entails:

  • Translation ready themes that only come with a .pot file

You can find translation ready themes that only come with a .pot file (and sometimes with an English version of .mo and .po files). These files can be used to translate the theme into other languages. These themes don’t provide translations to other languages, but you have the tools needed to localize the WordPress theme like the Poedit software or the Loco Translate plugin.

For example, in the Jupiter X theme, we provide the jupiterx.pot file and a user can translate the theme to their language.

  • Translation ready themes with translations into other languages

You can find translation ready themes that come with .pot file that also come with translations into other languages. These translations usually have been done by translators, volunteers or any other users.

For example, in the Jupiter 6 theme we provide .po and .mo files for some languages, meaning a customer doesn’t have to translate the theme themselves.

Translation Ready Themes Jupiter 6 Files

Steps to Create a Translation Ready Theme

  1. Create and load the text domain for your WordPress theme.
  2. Enclose the Translatable Text String with the WordPress gettext function.
  3. Create the POT file.

Create and Load the Text Domain

The Text Domain will be a part of the WordPress theme or plugin specification. The following code snippets show the theme and plugin specification with the text domain.

Note: The theme specification will be in the theme’s style.css

/*
 Theme Name: YOUR THEMENAME
 Theme URI: yourdomain/themes/yourthemename/
 …
 …
 Text Domain: yourthemename
 */
/*
 Plugin Name: Plugin Name
 Plugin URI: yourdomain
 …
 …
 Text Domain: yourthemename
 */

Load your theme’s text domain by using the load_theme_textdomain() function. This function has two parameters as the text domain name and the directory path where we will store the .pot, .po, .mo language files. Paste the code seen below in your theme’s functions.php to load the text domain.

load_theme_textdomain( ‘yourthemename’, language_file_path );

Enclose the Translatable Text String with the WordPress gettext Function

WordPress uses the gettext framework function to translate the text string into the specified target language. It has a set of functions in a core translation API file l10n.php located in the wp-includes directory. We have to enclose the text string with the appropriate function. The code below shows how to use the gettext function to localize your theme.

__()
This is one of the most basic translation functions. Like many of its siblings, it takes two parameters: the string to be translated and the text domain.

$name = __( ‘My Stats’, ‘textdomain’ );

It’s used when you want to mark a simple string for translation and return the value to use somewhere else. This is frequently the case within functions – think of registering post types.

_e()

This is almost the same as the function above, except it echoes the value. It can be used when you’re translating in the HTML content directory:

_n()

This function is used when translating strings with a conditional plural in them. This means that you don’t know in advance if the string will use the plural or singular form because it depends on the momentary value of some parameter. A good example would be a comment count.

For example, if a comment count is one, you would need to use a singular form: “One comment.” If a comment count is 0 or more than one, you would use the plural: “Many comments”. This can be done in one go by using the _n() function.

This takes four parameters: the singular form, the plural form, the number to check and the text domain:

$comment_count = get_comments_number();
$comment_count_text = _n( ‘One Comment’, ‘Many Comments’, $comment_count, ‘textdomain’ );

You can read more about the gettext function in the following articles:

https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
https://codex.wordpress.org/I18n_for_WordPress_Developers

Creating the POT file with the Translatable Text String

After applying appropriate gettext functions for all the translatable text strings of your theme files, create a .POT template file. This template will be the base consisting of all the translatable strings. This file will be referred to create language mapping file .po, .mo pair for each language translation. You can use any popular tool to create this file for getting the theme’s translatable strings.

Read more about making translation ready plugins in the WordPress Codex page.

Wrapping up:

One of the goals of WordPress is to make it easy for users across the world to publish content.
In this article, we took a look at the basics of translations, what a text domain is, the functions we can use and how to create translation files.

We hope this was helpful to you. Please share your experiences in the comments below!😉

Best Plugins for WordPress Meta Box

wordpress meta box featured image

WordPress uses a powerful and flexible framework that has wonderful features to help users create a website easily and quickly. WordPress provides necessary features for creating and editing content, but perhaps for a lot of websites, we need to add more information or data. In this situation, WordPress provides a Meta Box feature.

What is a WordPress Meta Box?

WordPress Meta Box is a group of custom fields which allows you to add more information to posts, pages and custom posts types. You can add custom meta boxes via custom codes in your theme/plugin, or use one of the following plugins for easier and faster workflow.

In this article, let’s cover three of the most popular WordPress Meta Box plugins.

Create WordPress Meta Box with Advanced Custom Fields Plugin

WordPress Meta Box 1

Nowadays, this Advanced Custom Fields is the most popular plugin for creating custom fields. The visual builder allows you to add fields to WordPress edit screens conveniently. Furthermore, with the builder, you can add fields all over your WordPress website including posts, pages, user, media, comments, and taxonomies.

Features

  • Simple & Intuitive
  • Powerful Functions
  • Over 30 Field Types
  • Extensive Documentation
  • Millions of Users

Field Types

  • Basic (Text, Text Area, Number, Range, Email, Url, Password)
  • Content (Image, File, Wysiwyg Editor, oEmbed)
  • Choice (Select, Checkbox, Radio Button, Button Group, True / False)
  • Relational (Link, Post Object, Page Link, Relationship, Taxonomy, User)
  • jQuery (Google Map, Date Picker, Date Time Picker, Time Picker, Color Picker)
  • Layout (Message, Accordion, Tab, Group)

Creating a WordPress Meta Box

Now that you have some information about Advanced Custom Fields plugin, it’s time to create four fields for an author of a post, then add the fields to the end of the post edit screen.

Author fields

  • Author age
  • Author profession
  • Author hobby
  • Author wish

1. From the left sidebar of WordPress admin menu, click on Custom Fields > Add New.

WordPress Meta Box 2

2. Click on the Add Field button for creating fields.

WordPress Meta Box 3

3. Fill out the Field Label, Field Name, Field Type and other fields based on your needs.

WordPress Meta Box 4

4. Add three other fields similar to the above step then click on Publish/Update button.

WordPress Meta Box 5

For showing the created fields in the edit post screen, configure the Location settings as shown below.

WordPress Meta Box 6

6. Edit a post to see the fields.

WordPress Meta Box 6

7. For showing the value of these fields, read this article about displaying values in your theme.

Useful Resources:

Awesome ACF lists many extensions for this plugin. For this article, let’s mention some of them.

Admin Columns allows you to display ACF custom fields for posts (post meta) and users (user meta) as columns on your list overview.

Automatically generates the code you need to implement ACF fields in your themes.

Add a Font Awesome icon field type to Advanced Custom Fields.

Allows you to add a Date and Time Picker field type.

Create flexible and developer-friendly forms using the power of Advanced Custom Fields.

Create a WordPress Meta Box with Meta Box plugin

WordPress Meta Box Plugin

Another powerful and lightweight plugin for creating unlimited custom fields is Meta Box. with this plugin, we can add custom fields to post, page, forms, etc. Furthermore, this plugin has over 40 field types.

The free version of Meta Box Plugin doesn’t have an admin page in WordPress dashboard. For creating a meta box, you need to use an Online Generator tool. This tool generates necessary codes to register a meta box in your child theme.

Features

  • Supports 40+ custom field types
  • Powerful options for custom fields
  • Lightweight and well-coded
  • Developer friendly

Field Types

  • Input fields (Text, Number, URL, Email, Range, Text List)
  • Basic fields (Checkbox, Checkbox List, Button, Password, Radio, Select, Select Advanced Textarea, Hidden, Image Select)
  • Advanced Fields (Color Picker, OEmbed, Slider, WYSIWYG, Autocomplete, Fieldset Text, Map, Heading, Divider)
  • Date & Time Fields (Date, Date-Time, Time)
  • WordPress Fields (Post, Taxonomy, Taxonomy Advanced, User)
  • Media Fields (HTML File, File Input, File Advanced, Image Advanced, HTML Image, Video)

How to Create a WordPress meta box

Now, it’s time to create four fields for an author of a post in Meta Box plugin.

Author Fields

  • Autor Phone Number
  • Autor Email
  • Autor Birthday
  • Autor Site Address

1. Go to the Online Generator tool.

2. In the General tab, set the Function Name and Text Domain.

3. In the Meta Box tab, set the ID and Title of your meta box. Configure the other options to show the meta box at an appropriate place.

4. In the Fields tab, create the fields as explained below:

Field 1: Create Field with Number Type and set ID to author_phone_number and NAME to Author Phone Number.

Field 2: Create Field with Email Type and set ID to author_email and NAME to Author Email.

Field 3: Create Field with Date Type and set ID to author_birthday and NAME to Author Birthday.

Field 4: Create Field with Url Type and set ID to author_website and NAME to Author Website.

5. For generating codes, click on the Generate button. Click on the Copy link to copy codes to the clipboard.

6. Go to Function.php of your child theme then paste the codes and save it.
7. Edit a post to see the fields.

8. For showing the value of these fields, read this article about displaying fields.

Useful Resources:

The Meta Box website has a dedicated page for extensions. For this article, let’s mention some of them:

Create and manage custom post types and taxonomies quickly with an easy-to-use interface.

Pull all meta values from posts and terms into the WP REST API responses.

Create and manage custom taxonomies in WordPress with a user-friendly interface.

Add WordPress custom fields to comments in WordPress. It supports all field types and options.

Create WordPress Meta Box with Pods plugin

WordPress Meta Box Pods Plugin

Pods is a framework to manage all your custom content needs in ONE location. This plugin allows you to create and edit custom post types, taxonomy, fields, and even extend existing WordPress objects like users, media, posts, and pages.

Features:

  • Create a type of content in WordPress
  • Extend existing content types
  • Different field types and build your own with extensible field type classes
  • Importers to help your transition from other plugins

Field Types

  • Date / Time (Date, Time, both)
  • Number (Plain Number, Currency)
  • Text (Plain Text, Website, Phone, E-mail, Password)
  • Paragraph Text (Plain Paragraph, WYSIWYG, Code)
  • Color Picker
  • Yes / No
  • File / Image / Video
  • Avatars
  • Relationships

Create a WordPress Meta Box

Now, let’s add a meta box with some author fields in WordPress pages.

Author fields:

  • Author age
  • Author position

1. From the left sidebar of WordPress admin menu, click on Pods Admin > Add New.
2. In the new screen, choose Extend Existing.

3. Set content Type to Post Types (Posts, Pages, Etc) and Post Type to Pages then click on Next Step.

4. Add a Text field type and set the label to Author Age then set Name to author_age.

5. Add a Text field type and set the label to Author Position then set Name to author_position. Click on Save Pod button to save your fields.

6. Edit a post to see the fields.

Useful Extensions:

Pods plugin is a developer-friendly framework so some developers develop extensions to enhance the plugin. For this article, let’s mention some of them:

Easily select Pods fields in Beaver-Themer field connections from a dropdown based on the currently displayed item (CPT).

This extension provides the ability to sync entries from a Form Submission and Entry Edit screen.

This extension provides optimal performance with Pods sites on hosts with no object caching or low limits.

Conclusion

In this article, we introduced three plugins to help you to create, manage and extend WordPress Meta Box easily and quickly. The ACF plugin is the most popular plugin at the moment. Some popular themes like Jupiter X rely on ACF to manage the Meta Box and custom fields.

There are also some other plugins in the WordPress Community for managing Meta Box. Feel free to share your favorite one with us in the comment section!

Top Caching Plugins and How to Use Them for your WordPress Website

Your site speed is one of the key factors that contributes to the success of your website. Let’s reiterate that the average attention span of an average user is approximately 8 seconds, which means that you have about 3 to 4 seconds to grab their attention. But, what if your website loads longer than that? Bam! You’ve just lost a potential lead.

Continue reading