{"id":69623,"date":"2016-12-28T08:38:05","date_gmt":"2016-12-28T08:38:05","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=69623"},"modified":"2016-12-28T08:38:05","modified_gmt":"2016-12-28T08:38:05","slug":"make-string-translatable-class-prestashop","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/","title":{"rendered":"How to make a string translatable in any class of Prestashop"},"content":{"rendered":"<p>Sometimes, we need to create a global function that have some strings\u00a0and we must\u00a0translate these strings. Basically for making our strings translatable, we use l() function of Prestashop&#8217;s Module class. So suppose if\u00a0our string\u00a0is &#8216;Product name is required.&#8217; then we use &#8211;<\/p>\n<pre class=\"brush:php\">$this-&gt;l('Product name is required.');<\/pre>\n<p>But it\u00a0works only in our Prestashop controllers or module&#8217;s main\u00a0class.\u00a0So in this blog, we will learn that how to use l() function in classes of our Prestashop module for making our strings translatable.<\/p>\n<p>In Prestashop, l() function is defined in Module class i.e.<\/p>\n<pre class=\"brush:php\">\/*\r\n* 2007-2016 PrestaShop\r\n*\r\n* NOTICE OF LICENSE\r\n*\r\n* This source file is subject to the Open Software License (OSL 3.0)\r\n* that is bundled with this package in the file LICENSE.txt.\r\n* It is also available through the world-wide-web at this URL:\r\n* http:\/\/opensource.org\/licenses\/osl-3.0.php\r\n* If you did not receive a copy of the license and are unable to\r\n* obtain it through the world-wide-web, please send an email\r\n* to license@prestashop.com so we can send you a copy immediately.\r\n*\r\n* DISCLAIMER\r\n*\r\n* Do not edit or add to this file if you wish to upgrade PrestaShop to newer\r\n* versions in the future. If you wish to customize PrestaShop for your\r\n* needs please refer to http:\/\/www.prestashop.com for more information.\r\n*\r\n*  @author PrestaShop SA &lt;contact@prestashop.com&gt;\r\n*  @copyright  2007-2016 PrestaShop SA\r\n*  @license    http:\/\/opensource.org\/licenses\/osl-3.0.php  Open Software License (OSL 3.0)\r\n*  International Registered Trademark &amp; Property of PrestaShop SA\r\n*\/\r\n\r\nabstract class ModuleCore\r\n{\r\n    public function l($string, $specific = false)\r\n    {\r\n        if (self::$_generate_config_xml_mode) {\r\n            return $string;\r\n        }\r\n\r\n        return Translate::getModuleTranslation($this, $string, ($specific) ? $specific : $this-&gt;name);\r\n    }\r\n}<\/pre>\n<p><strong>Parameters of l() function &#8211;<\/strong><\/p>\n<ol>\n<li>$string &#8211; First parameter in l() function will be our string.<\/li>\n<li>$specific &#8211; Second parameter is a\u00a0source name that will be\u00a0our class name in which we will implement l() function. This parameter is optional that means if you didn&#8217;t set this parameter then Prestashop\u00a0will take by default &#8211;\n<pre class=\"brush:php\">$this-&gt;name<\/pre>\n<\/li>\n<\/ol>\n<p>So if we want to use\u00a0l()\u00a0function in any class for making our string\u00a0translatable then we\u00a0can implement with following way &#8211;<\/p>\n<p>Suppose we have a class in our module that is &#8216;Product&#8217; And here if want to use l() function in this class then we can\u00a0implement below code in any function of Product class.<\/p>\n<pre class=\"brush:php\">$objDemoModule = new DemoModule();\r\n$objDemoModule-&gt;l('Product name is required.', 'Product');<\/pre>\n<p>Here DemoModule\u00a0is our main\u00a0class that extends Prestashop Module class. So we make an object of this class that call l() function with it. First parameter of l() function is our string and second parameter is our class name where we implement this function.<\/p>\n<p>After this, we can see in Prestashop translations,\u00a0A section of our class name &#8216;Product&#8217; will display with our string\u00a0&#8216;Product name is\u00a0\u00a0required.&#8217; So here we can translate this string.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, we need to create a global function that have some strings\u00a0and we must\u00a0translate these strings. Basically for making our strings translatable, we use l() function of Prestashop&#8217;s Module class. So suppose if\u00a0our string\u00a0is &#8216;Product name is required.&#8217; then we use &#8211; $this-&gt;l(&#8216;Product name is required.&#8217;); But it\u00a0works only in our Prestashop controllers or module&#8217;s <a href=\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":82,"featured_media":69431,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[209],"tags":[],"class_list":["post-69623","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-prestashop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to make a string translatable in any Class of Prestashop<\/title>\n<meta name=\"description\" content=\"How to make a string translatable in any class using Prestashop Module class l() function\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to make a string translatable in any Class of Prestashop\" \/>\n<meta property=\"og:description\" content=\"How to make a string translatable in any class using Prestashop Module class l() function\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-28T08:38:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Neeraj\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Neeraj\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/\"},\"author\":{\"name\":\"Neeraj\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/741818aa2ccafbb9688f6108bfd94273\"},\"headline\":\"How to make a string translatable in any class of Prestashop\",\"datePublished\":\"2016-12-28T08:38:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/\"},\"wordCount\":296,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png\",\"articleSection\":[\"prestashop\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/\",\"url\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/\",\"name\":\"How to make a string translatable in any Class of Prestashop\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png\",\"datePublished\":\"2016-12-28T08:38:05+00:00\",\"description\":\"How to make a string translatable in any class using Prestashop Module class l() function\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to make a string translatable in any class of Prestashop\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/741818aa2ccafbb9688f6108bfd94273\",\"name\":\"Neeraj\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f45246e2a6b765786af5b102a8adbc375466c87b477afa9d5c7bf6777d4f2566?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f45246e2a6b765786af5b102a8adbc375466c87b477afa9d5c7bf6777d4f2566?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Neeraj\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/neeraj751\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to make a string translatable in any Class of Prestashop","description":"How to make a string translatable in any class using Prestashop Module class l() function","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:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/","og_locale":"en_US","og_type":"article","og_title":"How to make a string translatable in any Class of Prestashop","og_description":"How to make a string translatable in any class using Prestashop Module class l() function","og_url":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-12-28T08:38:05+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png","type":"image\/png"}],"author":"Neeraj","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Neeraj","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/"},"author":{"name":"Neeraj","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/741818aa2ccafbb9688f6108bfd94273"},"headline":"How to make a string translatable in any class of Prestashop","datePublished":"2016-12-28T08:38:05+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/"},"wordCount":296,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png","articleSection":["prestashop"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/","url":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/","name":"How to make a string translatable in any Class of Prestashop","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png","datePublished":"2016-12-28T08:38:05+00:00","description":"How to make a string translatable in any class using Prestashop Module class l() function","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/make-string-translatable-class-prestashop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to make a string translatable in any class of Prestashop"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/741818aa2ccafbb9688f6108bfd94273","name":"Neeraj","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f45246e2a6b765786af5b102a8adbc375466c87b477afa9d5c7bf6777d4f2566?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f45246e2a6b765786af5b102a8adbc375466c87b477afa9d5c7bf6777d4f2566?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Neeraj"},"url":"https:\/\/webkul.com\/blog\/author\/neeraj751\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/69623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/82"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=69623"}],"version-history":[{"count":4,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/69623\/revisions"}],"predecessor-version":[{"id":161380,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/69623\/revisions\/161380"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/69431"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=69623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=69623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=69623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}