Looks familiar, doesn’t it? The JavaScript i18n API mirrors the translation functions that you would normally use in PHP. Let’s start by taking a look at a translation function in JS: _( 'Hello World!', 'text-domain' ) Now that we have a clear understanding of how translations work in WordPress, let’s take a look at exactly how we can translate strings in JavaScript. If you are translating a plugin, you will want to use load_plugin_textdomain().
![install poedit bluehost install poedit bluehost](https://www.hostingreviewbox.com/wp-content/uploads/2015/11/bluehost-1.jpg)
If you are translating a theme, you will want to use load_theme_textdomain(). Register your language file – WordPress has a few functions you can use to register your language file so it can be found.
![install poedit bluehost install poedit bluehost](https://d33wubrfki0l68.cloudfront.net/365fb7c2b3f1975c53702faee119fa41110e1ce2/664a2/images/screenshots/screenshot-help.jpg)
While your users would normally be the ones doing this, you should do this to thoroughly test that your translation is working. Set the language – you can tell WordPress what language you want to use by going to Settings > General in the WordPress admin and selecting the desired language from the Site Language dropdown.However, nothing is going to be translated unless WordPress knows what language is in use and where the language file is located:
![install poedit bluehost install poedit bluehost](https://wpshapere.com/blog/wp-content/uploads/2021/01/install-poedit-directory.jpg)
There are a number of ways to do this, but if you use a tool like Poedit both of these files can be generated simultaneously.Īt this point, we’ve prepped for translation and have a file that will allow WordPress to translate the strings via code. mo (machine object) file in order to dynamically translate the text via code. The translator will take the file, translate the strings, and save the translated strings into a. pot file to a translator for translation into the language(s) of choice. Localization, the next step in the process, starts when you provide the. WordPress uses the text domain to tell the difference between the translation for your theme or plugin and that of another.įinally, an automated tool is used to locate and compile all of the text strings with your text domain into a. Text Domain – a namespace, or unique identifier, under which all of your translated strings are managed. Essentially, all of these functions allow you to provide a text string to be translated and what is called a text domain. Internationalization starts by utilizing the translation functions that WordPress provides. Localization is the process of leveraging that preparation and actually performing the translation. The logic behind this is that you take the first and last letter of the word, count the remaining letters and put that number in between.Īt the most basic level, internationalization is the process of preparing a theme or plugin for translation. It is common to see the abbreviations i18n and l10n when referring to internationalization and localization. There are two steps in the translation process: Internationalization and localization. Internationalization and Localization Overview
![install poedit bluehost install poedit bluehost](https://documentation.laborator.co/wp-content/uploads/2017/01/poedit-screenshot.jpg)
Our goal today is to document the entire process from start to finish. Most examples will give you a piece of the puzzle, but not the entire picture.
#Install poedit bluehost how to#
Thankfully, with the dawn of Gutenberg, we now have the new WordPress i18n npm library.Īt the time of this writing, it is a bit hard to find examples of how to properly translate JavaScript strings in WordPress from start to finish. Unfortunately, this approach doesn’t scale well and makes for some messy code. Traditionally, WordPress developers have utilized the wp_localize_script() function for passing translated strings from PHP into JavaScript. As of 2018, we now have a similar process for translating strings in JavaScript. Since 2007, WordPress has supported the translation of text strings in PHP.