Translating WordPress Themes
I've been working on a new WordPress theme for a few weeks. Now I'm at the point where I can start worrying about the last finishing touches before I can start dogfooding it. One of the things left in the to-do list is internationalizing the theme. Making sure that it's translated to Spanish and that it is ready for people who want to translate it to other languages to do so. In this post, we'll concentrate on theme i18n (internationalization) for a theme. Gutenberg and blocks will be discussed in a separate post. ## Translating Themes For the translations to work, you have to make sure that `textdomain` is set on your styles.css main stylesheet. You also have to change the way that you write the strings using PHP. ### Textdomain When building the CSS stylesheet for your theme, make sure that you add a `Text Domain` field to the header of the stylesheet. Wordpress will use it as the text domain to tie all translations to. A minimal example of the theme header looks like this: ```css /*! Theme Name: rivendellweb Version: 1.0.0 Text Domain: rivendellweb */ ``` ### Changing how you write strings In order to translate our themes, we need to change the way we write our strings. Using echo on its own, like this: ```php Edit on Github