{"id":6224,"date":"2017-01-11T16:26:12","date_gmt":"2017-01-11T21:26:12","guid":{"rendered":"https:\/\/themespress.ca\/?p=6224"},"modified":"2022-09-03T20:52:56","modified_gmt":"2022-09-04T00:52:56","slug":"configuring-language-files-wordpress-plugin","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/configuring-language-files-wordpress-plugin\/","title":{"rendered":"Configuring Language Files in a WordPress Plugin"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>With this tutorial, we will show you how to configure language files in a WordPress plugin.<\/p>\n<p>If it&#8217;s not already the case, first we need to adapt our WordPress&#8217; core file this way:<\/p>\n<p>Your file can be index.php for example, but it needs to be in the <strong>root folder of your WordPress plugin<\/strong>. We cannot add all details in a WordPress core plugin. Edit it with your parameters of your WordPress plugin.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-9058366\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-9058366\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/* \nPlugin Name: Le nom du Plugin \nPlugin URI: https:www.mondomaine.com\/ \nDescription: Explication en une phrase de votre plugin et de ses caract&eacute;ristiques. \nVersion: La version actuelle (Ex:2.0) \nAuthor: Votre Nom ou nom d&#039;auteur \nAuthor URI: L&#039;adresse du site Web de l&#039;auteur \n*\/ <\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>By adding the following code snippet, we will also secure your file:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-8201992\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-8201992\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">if ( ! defined( &#039;ABSPATH&#039; ) ) { \n  exit; \n} <\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Then we need to create a folder called <strong>languages<\/strong> where we will include all of our .mo and .po files for the required languages. Afterwards, we need to create a new function which will execute the language files:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-5804630\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-5804630\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/**************************************** Load folders Language ************************************\/ \nfunction via_woocommerce_classement_load_plugin_textdomain() { \n$domain = &#039;woocommerce-classement&#039;; \n$locale = apply_filters( &#039;plugin_locale&#039;, get_locale(), $domain ); \nif ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . &#039;\/&#039; . $domain . &#039;-&#039; . $locale . &#039;.mo&#039; ) ) { \n  return $loaded; \n} \nelse { \n  load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . &#039;\/languages\/&#039; ); } \n} \nadd_action( &#039;init&#039;, &#039;via_woocommerce_classement_load_plugin_textdomain&#039; );<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>In the function, we can see that the variable $domain = &#8216;woocommerce-classement&#8217;; is storing the plugin name. It is vital to change it by the name of the WordPress plugin folder. Finally, make sure that your language folder exists.<\/p>\n<p>Now all that there&#8217;s left to do is edit your language files with <a href=\"https:\/\/poedit.net\/\" target=\"_blank\" rel=\"noopener\">Poedit<\/a>.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p><strong>Here&#8217;s how the code snippet should look:<\/strong><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-5548577\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-5548577\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php \n\/* \nPlugin Name: Le nom du Plugin \nPlugin URI: https:www.mondomaine.com\/ \nDescription: Explication en une phrase de votre plugin et de ses caract&eacute;ristiques. \nVersion: La version actuelle (Ex:2.0) \nAuthor: Votre Nom ou nom d&#039;auteur \nAuthor URI: L&#039;adresse du site Web de l&#039;auteur \n*\/ \n\nif ( ! defined( &#039;ABSPATH&#039; ) ) { \n  exit; \n} \n\n\/**************************************** Load folders Language ************************************\/ \nfunction via_woocommerce_classement_load_plugin_textdomain() { \n$domain = &#039;woocommerce-classement&#039;; \n$locale = apply_filters( &#039;plugin_locale&#039;, get_locale(), $domain ); \nif ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . &#039;\/&#039; . $domain . &#039;-&#039; . $locale . &#039;.mo&#039; ) ) { \n  return $loaded; \n} \nelse { \n  load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . &#039;\/languages\/&#039; ); } \n} \nadd_action( &#039;init&#039;, &#039;via_woocommerce_classement_load_plugin_textdomain&#039; );<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will show you how to configure language files in a WordPress plugin. If it's not already the case, first we need to adapt our WordPress' core<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/configuring-language-files-wordpress-plugin\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4584,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[313],"class_list":["post-6224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-plugins"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6224"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6224\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4584"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}