{"id":1190,"date":"2019-04-21T18:09:42","date_gmt":"2019-04-21T21:09:42","guid":{"rendered":"https:\/\/felipeelia.com.br\/?p=1190"},"modified":"2019-07-04T19:59:46","modified_gmt":"2019-07-04T22:59:46","slug":"how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml","status":"publish","type":"post","link":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/","title":{"rendered":"How to Translate Theme Options inside Customizer with Polylang and WPML"},"content":{"rendered":"\n

As I said in my first post<\/a> here, after months thinking about it, I\u2019ve finally decided to turn this blog multilingual in an attempt to get more clients among Codeable<\/a>‘s target audience. I had to decide between turning this WordPress installation into a multisite one or using a plugin and, after this twitter thread<\/a>, I gave Polylang<\/a> a chance.<\/p>\n\n\n\n\n\n\n

I used to work with WPML<\/a> but as Polylang has a free version, it was my first choice. As the blog theme is a simple one I didn’t face any difficulty, unless how to translate an option I have in Customizer. Are you seeing the Creative Commons license in the footer? Yes, that is a Customizer field, built this way:<\/p>\n\n\n\n

function felipeelia_customize_register( $wp_customize ) {\n\t$wp_customize->add_section(\n\t\t'felipeelia_rodape',\n\t\tarray(\n\t\t\t'title'    => 'Rodap\u00e9',\n\t\t\t'priority' => 125,\n\t\t)\n\t);\n\t$wp_customize->add_setting(\n\t\t'copyright',\n\t\tarray(\n\t\t\t'default'    => '',\n\t\t\t'capability' => 'edit_theme_options',\n\t\t)\n\t);\n\t$wp_customize->add_control(\n\t\t'copyright',\n\t\tarray(\n\t\t\t'label'    => 'Copyright',\n\t\t\t'section'  => 'felipeelia_rodape',\n\t\t\t'settings' => 'copyright',\n\t\t\t'type'     => 'textarea',\n\t\t)\n\t);\n}\nadd_action( 'customize_register', 'felipeelia_customize_register' );<\/code><\/pre>\n\n\n\n

That code creates a Copyright<\/em> field in the Rodap\u00e9 (Footer)<\/em> Customizer section. To show it I use the following code in my footer.php<\/em>:<\/p>\n\n\n\n

<?php echo get_theme_mod( 'copyright' ); ?><\/code><\/pre>\n\n\n\n

I needed to translate that and I didn’t know how. Actually, I had a guess, but I didn’t work on anything like that before. A long time ago, WPML created a file pattern called wpml-config.php<\/strong>, that allows plugins and themes to declare which post types, taxonomies, and admin texts should be translated. Theme mods<\/em> fall in that “admin text” section. As it already was the pattern at that time, Polylang also uses the same file<\/strong>. Yeah, with their competitor’s name.<\/p>\n\n\n\n

Everything kept in the wp_options<\/em> tables fall in the admin text section. Theme mods, these we call with get_theme_mod<\/a>, are stored in an option called theme_mods_THEMENAME<\/em> and its value is a serialized associative array, i.e., an array with named keys that passes through PHP serialize<\/a> function before being saved. At the end of the day, all I had to do was create a file called wpml-config.xml<\/em> in my theme root directory<\/strong> with the following content:<\/p>\n\n\n\n

<wpml-config>\n    <admin-texts>\n        <key name=\"theme_mods_felipeelia\">\n            <key name=\"copyright\" \/>\n        <\/key>\n    <\/admin-texts>\n<\/wpml-config><\/code><\/pre>\n\n\n\n

Note that felipeelia<\/em>, in this case, is my theme slug<\/p>\n\n\n\n

If you found this content useful, please share it and leave a comment. That always helps a lot \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"

Read how to translate your theme options in Customizer with Polylang and WPML through the wpml-config.xml file<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[91],"tags":[110],"yoast_head":"\nHow to Translate Theme Options inside Customizer with Polylang and WPML | Felipe Elia<\/title>\n<meta name=\"description\" content=\"Como tornar as op\u00e7\u00f5es do Personalizar do seu tema traduz\u00edveis pelo Polylang e WPML com o arquivo wpml-config.xml\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Translate Theme Options inside Customizer with Polylang and WPML | Felipe Elia\" \/>\n<meta property=\"og:description\" content=\"Como tornar as op\u00e7\u00f5es do Personalizar do seu tema traduz\u00edveis pelo Polylang e WPML com o arquivo wpml-config.xml\" \/>\n<meta property=\"og:url\" content=\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/\" \/>\n<meta property=\"og:site_name\" content=\"Felipe Elia\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/felipe.elia\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/felipe.elia\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-21T21:09:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-07-04T22:59:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/felipeelia.com.br\/wp-content\/uploads\/2019\/04\/traduzir-opcoes-de-tema-personalizar-polylang-wpml.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1280\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Felipe Elia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/felipe_elia\" \/>\n<meta name=\"twitter:site\" content=\"@felipe_elia\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Felipe Elia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/\"},\"author\":{\"name\":\"Felipe Elia\",\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292\"},\"headline\":\"How to Translate Theme Options inside Customizer with Polylang and WPML\",\"datePublished\":\"2019-04-21T21:09:42+00:00\",\"dateModified\":\"2019-07-04T22:59:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/\"},\"wordCount\":348,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292\"},\"keywords\":[\"Themes\"],\"articleSection\":[\"WordPress\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/\",\"url\":\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/\",\"name\":\"How to Translate Theme Options inside Customizer with Polylang and WPML | Felipe Elia\",\"isPartOf\":{\"@id\":\"https:\/\/felipeelia.com.br\/#website\"},\"datePublished\":\"2019-04-21T21:09:42+00:00\",\"dateModified\":\"2019-07-04T22:59:46+00:00\",\"description\":\"Como tornar as op\u00e7\u00f5es do Personalizar do seu tema traduz\u00edveis pelo Polylang e WPML com o arquivo wpml-config.xml\",\"breadcrumb\":{\"@id\":\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"In\u00edcio\",\"item\":\"https:\/\/felipeelia.dev\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Translate Theme Options inside Customizer with Polylang and WPML\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/felipeelia.com.br\/#website\",\"url\":\"https:\/\/felipeelia.com.br\/\",\"name\":\"Felipe Elia\",\"description\":\"Programa\u00e7\u00e3o com WordPress de um jeito f\u00e1cil, do b\u00e1sico ao avan\u00e7ado\",\"publisher\":{\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/felipeelia.com.br\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-BR\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292\",\"name\":\"Felipe Elia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/felipeelia.dev\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg\",\"contentUrl\":\"https:\/\/felipeelia.dev\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg\",\"width\":400,\"height\":400,\"caption\":\"Felipe Elia\"},\"logo\":{\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/image\/\"},\"description\":\"Associate Director of Platform Engineering na 10up, WordPress Core Contributor, Global Polyglots Mentor na comunidade internacional do WordPress e Locale Manager na comunidade WordPress Brasil.\",\"sameAs\":[\"https:\/\/www.facebook.com\/felipe.elia\",\"https:\/\/www.instagram.com\/felipe.elia\/\",\"https:\/\/www.linkedin.com\/in\/felipeelia\/\",\"https:\/\/twitter.com\/https:\/\/twitter.com\/felipe_elia\",\"https:\/\/www.youtube.com\/channel\/UCD_26rOE3ClALcZreTkyIoQ\"],\"url\":\"https:\/\/felipeelia.com.br\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Translate Theme Options inside Customizer with Polylang and WPML | Felipe Elia","description":"Como tornar as op\u00e7\u00f5es do Personalizar do seu tema traduz\u00edveis pelo Polylang e WPML com o arquivo wpml-config.xml","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/","og_locale":"pt_BR","og_type":"article","og_title":"How to Translate Theme Options inside Customizer with Polylang and WPML | Felipe Elia","og_description":"Como tornar as op\u00e7\u00f5es do Personalizar do seu tema traduz\u00edveis pelo Polylang e WPML com o arquivo wpml-config.xml","og_url":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/","og_site_name":"Felipe Elia","article_publisher":"https:\/\/www.facebook.com\/felipe.elia","article_author":"https:\/\/www.facebook.com\/felipe.elia","article_published_time":"2019-04-21T21:09:42+00:00","article_modified_time":"2019-07-04T22:59:46+00:00","og_image":[{"width":1920,"height":1280,"url":"https:\/\/felipeelia.com.br\/wp-content\/uploads\/2019\/04\/traduzir-opcoes-de-tema-personalizar-polylang-wpml.jpg","type":"image\/jpeg"}],"author":"Felipe Elia","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/felipe_elia","twitter_site":"@felipe_elia","twitter_misc":{"Escrito por":"Felipe Elia","Est. tempo de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/#article","isPartOf":{"@id":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/"},"author":{"name":"Felipe Elia","@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292"},"headline":"How to Translate Theme Options inside Customizer with Polylang and WPML","datePublished":"2019-04-21T21:09:42+00:00","dateModified":"2019-07-04T22:59:46+00:00","mainEntityOfPage":{"@id":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/"},"wordCount":348,"commentCount":2,"publisher":{"@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292"},"keywords":["Themes"],"articleSection":["WordPress"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/","url":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/","name":"How to Translate Theme Options inside Customizer with Polylang and WPML | Felipe Elia","isPartOf":{"@id":"https:\/\/felipeelia.com.br\/#website"},"datePublished":"2019-04-21T21:09:42+00:00","dateModified":"2019-07-04T22:59:46+00:00","description":"Como tornar as op\u00e7\u00f5es do Personalizar do seu tema traduz\u00edveis pelo Polylang e WPML com o arquivo wpml-config.xml","breadcrumb":{"@id":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/felipeelia.dev\/how-to-translate-theme-options-inside-customizer-with-polylang-and-wpml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"In\u00edcio","item":"https:\/\/felipeelia.dev\/"},{"@type":"ListItem","position":2,"name":"How to Translate Theme Options inside Customizer with Polylang and WPML"}]},{"@type":"WebSite","@id":"https:\/\/felipeelia.com.br\/#website","url":"https:\/\/felipeelia.com.br\/","name":"Felipe Elia","description":"Programa\u00e7\u00e3o com WordPress de um jeito f\u00e1cil, do b\u00e1sico ao avan\u00e7ado","publisher":{"@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/felipeelia.com.br\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-BR"},{"@type":["Person","Organization"],"@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292","name":"Felipe Elia","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/image\/","url":"https:\/\/felipeelia.dev\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg","contentUrl":"https:\/\/felipeelia.dev\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg","width":400,"height":400,"caption":"Felipe Elia"},"logo":{"@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/image\/"},"description":"Associate Director of Platform Engineering na 10up, WordPress Core Contributor, Global Polyglots Mentor na comunidade internacional do WordPress e Locale Manager na comunidade WordPress Brasil.","sameAs":["https:\/\/www.facebook.com\/felipe.elia","https:\/\/www.instagram.com\/felipe.elia\/","https:\/\/www.linkedin.com\/in\/felipeelia\/","https:\/\/twitter.com\/https:\/\/twitter.com\/felipe_elia","https:\/\/www.youtube.com\/channel\/UCD_26rOE3ClALcZreTkyIoQ"],"url":"https:\/\/felipeelia.com.br\/author\/admin\/"}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"ocean-thumb-m":false,"ocean-thumb-ml":false,"ocean-thumb-l":false,"yarpp-thumbnail":false},"uagb_author_info":{"display_name":"Felipe Elia","author_link":"https:\/\/felipeelia.com.br\/author\/admin\/"},"uagb_comment_info":2,"uagb_excerpt":"Read how to translate your theme options in Customizer with Polylang and WPML through the wpml-config.xml file","_links":{"self":[{"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/posts\/1190"}],"collection":[{"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/comments?post=1190"}],"version-history":[{"count":0,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/posts\/1190\/revisions"}],"wp:attachment":[{"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/media?parent=1190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/categories?post=1190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/tags?post=1190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}