Answers.Body: <p>Completely, 100% untested, but I think you'd be able to pull it off with a pretty simple <a href="https://pluginfactory.io/" rel="nofollow">plugin</a> that added a new <a href="http://twig.sensiolabs.org/doc/filters/index.html" rel="nofollow">Twig filter</a> (check the Twig Extensions switch).</p>
  
  <p>From a template you'd something like:</p>
  
  <pre><code>{{ myDate|myDateFilter('es') }}
  </code></pre>
  
  <p>Then your plugin's <code>myDateFilter</code> method would do something like:</p>
  
  <pre><code>public function myDateFilter(\Twig_Environment $env, $date, $locale)
  {
      $localeData = craft()-&gt;i18n-&gt;getLocaleData($locale);
      $dateFormatter = $localeData-&gt;getDateFormatter();
  
      return $dateFormatter-&gt;formatDateTime($date-&gt;getTimestamp());
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-02T12:23:07.273Z
Answers.Text: Brilliant - thanks so much.
  
  In the end I used the dateFormatter's format() function instead of formatDateTime(), but otherwise your untested code was bang on
Answers.UserDisplayName: mijewe
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-02T02:40:10.477Z
Answers.LastActivityDate: 2016-09-02T02:40:10.477Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've got a generic newsletter template. Now some of our newsletters are in Spanish. It's overkill and more complicated for the admins to bother with settings up different locales, so instead I'd like to set the locale from the entry (currently using a dropdown).</p>
  
  <p>All good, and I can use the |translate(language="") filter to achieve this using the value from the dropdown field.</p>
  
  <p>Now the problem is that when formatting a date, it remains in English because it translated using the current locale, which is English.</p>
  
  <p>I'm wondering whether I can manually override the locale in the template. <code>{% set locale = 'es' %}</code>
  or something.</p>
  
  <p>Or if I can force the date to format using a specific locale.</p>
  
  <p>Cheers.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-09-01T03:45:14.930Z
Comments.Text: Just to be clear, you're trying to avoid adding a new locale under Settings->Locales in the control panel?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-09-01T08:41:30.883Z
Comments.Text: That's right. Newsletters are already linked to a category which is intrinsically linked to a language, so having to use locales properly would be confusing and doubling up on effort for the admin.
Comments.UserDisplayName: mijewe
Tags: <localization><datetime><language>
Title: Is it possible to use set the locale manually in a template?
ThreadText: # Is it possible to use set the locale manually in a template?
  
  (Asked by: username_0 on 2016-08-31)
  
  I've got a generic newsletter template. Now some of our newsletters are in Spanish. It's overkill and more complicated for the admins to bother with settings up different locales, so instead I'd like to set the locale from the entry (currently using a dropdown).
  
  All good, and I can use the |translate(language="") filter to achieve this using the value from the dropdown field.
  
  Now the problem is that when formatting a date, it remains in English because it translated using the current locale, which is English.
  
  I'm wondering whether I can manually override the locale in the template. `{% set locale = 'es' %}`
  or something.
  
  Or if I can force the date to format using a specific locale.
  
  Cheers.
  
  **Tags:** localization, datetime, language
  
  > **Comments:**
  > **username_1**: Just to be clear, you're trying to avoid adding a new locale under Settings->Locales in the control panel?  
  > **username_0**: That's right. Newsletters are already linked to a category which is intrinsically linked to a language, so having to use locales properly would be confusing and doubling up on effort for the admin.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-09-02. Score: 3 | Accepted answer
  
  Completely, 100% untested, but I think you'd be able to pull it off with a pretty simple [plugin](https://pluginfactory.io/) that added a new [Twig filter](http://twig.sensiolabs.org/doc/filters/index.html) (check the Twig Extensions switch).
  
  From a template you'd something like:
  
  ```
  {{ myDate|myDateFilter('es') }}
  
  ```
  
  Then your plugin's `myDateFilter` method would do something like:
  
  ```
  public function myDateFilter(\Twig_Environment $env, $date, $locale)
  {
      $localeData = craft()->i18n->getLocaleData($locale);
      $dateFormatter = $localeData->getDateFormatter();
  
      return $dateFormatter->formatDateTime($date->getTimestamp());
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Brilliant - thanks so much.  In the end I used the dateFormatter's format() function instead of formatDateTime(), but otherwise your untested code was bang on  
  
  ---
  
  