{"id":69360,"date":"2016-12-26T15:16:52","date_gmt":"2016-12-26T15:16:52","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=69360"},"modified":"2022-02-08T05:54:14","modified_gmt":"2022-02-08T05:54:14","slug":"translate-dates-in-prestashop","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/","title":{"rendered":"How to translate Dates in Prestashop"},"content":{"rendered":"<p>Many time we need to show dates in different languages in our shop. So it is necessary that date should show in the chosen language of the customer. So In this blog we will learn how to translate dates in prestashop.<\/p>\n<p>As we know locale format is <strong>languageCode_countryCode<\/strong> . where <strong>languageCode<\/strong> is in lowercase letters and\u00a0<strong>countryCode\u00a0<\/strong>is in uppercase letters.<\/p>\n<p>So first we will create the locale code for the language which customer chose as his language. As we know in prestashop\u00a0we always have a context object set on every page. you can use this object by two methods.<\/p>\n<pre class=\"brush:php\">$context = Context::getContext();\n\nOr\n\n\/\/ On every controller you can get the value of context object like this\n\n$context = $this-&gt;context;\n\n<\/pre>\n<p>Now get the locale of the language set in the context language. you can get the locale with the help of below code-<\/p>\n<pre class=\"brush:php\">$langLocale = $this-&gt;context-&gt;language-&gt;locale;<\/pre>\n<p>locale is in the format <strong>languageCode-countryCode <\/strong>. So to get locale from locale, we just have to replace character hyphen(-) with underscore (_) . Lets do this with help of following lines of code-<\/p>\n<pre class=\"brush:php\">$explodeLocale = explode('-', $langLocale);\n$localeOfContextLanguage = $explodeLocale[0].'_'.Tools::strtoupper($explodeLocale[1]);<\/pre>\n<p>Now\u00a0$localeOfContextLanguage is having the locale according to the language which customer has selected.<\/p>\n<p>now lets set the locale for the environment &#8211;<\/p>\n<pre class=\"brush:php\">setlocale(LC_ALL, $localeOfContextLanguage.'.UTF-8', $localeOfContextLanguage);<\/pre>\n<p class=\"brush:php\">Note : Make sure the locale you are passing in the setLocale() should be installed on your server to work.<\/p>\n<p>for more information on setlocale please visit the link \u2013\u00a0<a href=\"http:\/\/php.net\/manual\/en\/function.setlocale.php\">http:\/\/php.net\/manual\/en\/function.setlocale.php<\/a><\/p>\n<p>Lets you have a valiable names $dateToDisplay taking date value and you want to show this date variable&#8217;s \u00a0value to the customer in the format\u00a0\u2013 \u00a0<strong>Saturday, 10 December, 2016 .<\/strong><\/p>\n<p>For this after doing the above process you just have to assign this date variable to the tpl file as done in the below lie of code-<\/p>\n<pre class=\"brush:php\">$this-&gt;context-&gt;smarty-&gt;assign('dateToDisplay', $dateToDisplay);<\/pre>\n<p>and show the date in your tpl file . On your tpl file use the code like this-<\/p>\n<pre class=\"brush:php\">{$dateToDisplay|date_format:\"%A, %e %B}<\/pre>\n<p>Now this date will be shown translated according to the customer&#8217;s chosen language. So this is all you have to do for translating dates in prestashop\u00a0and you can use it for many purposes on your shop.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many time we need to show dates in different languages in our shop. So it is necessary that date should show in the chosen language of the customer. So In this blog we will learn how to translate dates in prestashop. As we know locale format is languageCode_countryCode . where languageCode is in lowercase letters <a href=\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":83,"featured_media":69431,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[209],"tags":[4252,4249,4257,2065,4250,4251,4256],"class_list":["post-69360","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-prestashop","tag-date-in-multiple-languages","tag-date-translation","tag-how-to-translate-dates","tag-prestashop","tag-prestashop-date","tag-prestashop-date-translation","tag-translate-dates-in-prestashop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to translate dates in Prestashop according to customer&#039;s language<\/title>\n<meta name=\"description\" content=\"we need to translate dates according to customer&#039;s chosen language. In this blog, we will learn how to translate dates in PrestaShop.\" \/>\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\/translate-dates-in-prestashop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to translate dates in Prestashop according to customer&#039;s language\" \/>\n<meta property=\"og:description\" content=\"we need to translate dates according to customer&#039;s chosen language. In this blog, we will learn how to translate dates in PrestaShop.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/translate-dates-in-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-26T15:16:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-08T05:54:14+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=\"Sumit\" \/>\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=\"Sumit\" \/>\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\/translate-dates-in-prestashop\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/\"},\"author\":{\"name\":\"Sumit\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/3e45ec35749afa62aa598a5e1766d2b9\"},\"headline\":\"How to translate Dates in Prestashop\",\"datePublished\":\"2016-12-26T15:16:52+00:00\",\"dateModified\":\"2022-02-08T05:54:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/\"},\"wordCount\":329,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png\",\"keywords\":[\"date in multiple languages\",\"date translation\",\"How to translate Dates\",\"prestashop\",\"prestashop date\",\"prestashop date translation\",\"translate Dates in Prestashop\"],\"articleSection\":[\"prestashop\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/\",\"url\":\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/\",\"name\":\"How to translate dates in Prestashop according to customer's language\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png\",\"datePublished\":\"2016-12-26T15:16:52+00:00\",\"dateModified\":\"2022-02-08T05:54:14+00:00\",\"description\":\"we need to translate dates according to customer's chosen language. In this blog, we will learn how to translate dates in PrestaShop.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/translate-dates-in-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\/translate-dates-in-prestashop\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to translate Dates in 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\/3e45ec35749afa62aa598a5e1766d2b9\",\"name\":\"Sumit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0e50336dc34ad31135238f210897d19d09edbdb9be2f7974a85de3ecdef16bf6?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\/0e50336dc34ad31135238f210897d19d09edbdb9be2f7974a85de3ecdef16bf6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Sumit\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/sumit201\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to translate dates in Prestashop according to customer's language","description":"we need to translate dates according to customer's chosen language. In this blog, we will learn how to translate dates in PrestaShop.","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\/translate-dates-in-prestashop\/","og_locale":"en_US","og_type":"article","og_title":"How to translate dates in Prestashop according to customer's language","og_description":"we need to translate dates according to customer's chosen language. In this blog, we will learn how to translate dates in PrestaShop.","og_url":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-12-26T15:16:52+00:00","article_modified_time":"2022-02-08T05:54:14+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":"Sumit","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Sumit","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/"},"author":{"name":"Sumit","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/3e45ec35749afa62aa598a5e1766d2b9"},"headline":"How to translate Dates in Prestashop","datePublished":"2016-12-26T15:16:52+00:00","dateModified":"2022-02-08T05:54:14+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/"},"wordCount":329,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png","keywords":["date in multiple languages","date translation","How to translate Dates","prestashop","prestashop date","prestashop date translation","translate Dates in Prestashop"],"articleSection":["prestashop"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/","url":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/","name":"How to translate dates in Prestashop according to customer's language","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/Prestashop-Code-Snippet-1.png","datePublished":"2016-12-26T15:16:52+00:00","dateModified":"2022-02-08T05:54:14+00:00","description":"we need to translate dates according to customer's chosen language. In this blog, we will learn how to translate dates in PrestaShop.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/translate-dates-in-prestashop\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/translate-dates-in-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\/translate-dates-in-prestashop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to translate Dates in 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\/3e45ec35749afa62aa598a5e1766d2b9","name":"Sumit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0e50336dc34ad31135238f210897d19d09edbdb9be2f7974a85de3ecdef16bf6?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\/0e50336dc34ad31135238f210897d19d09edbdb9be2f7974a85de3ecdef16bf6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Sumit"},"url":"https:\/\/webkul.com\/blog\/author\/sumit201\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/69360","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\/83"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=69360"}],"version-history":[{"count":22,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/69360\/revisions"}],"predecessor-version":[{"id":321676,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/69360\/revisions\/321676"}],"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=69360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=69360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=69360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}