Answers.Body: <p>Figured out something that works, though I can't explain why:</p>
  
  <pre><code>{{ object.section.name|t(language=object.locale) }}
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Here's how to do it for Craft 3:</p>
  
  <pre><code>{{ object.section.name|t('site', language=object.site.language) }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-14T17:30:03.050Z
Answers.Text: I think the issue with the short syntax is that you can only use the variable directly at the beginning, so `{locale}` works and `{'foo' ~ locale}` does not. If I understood correctly, short syntax parsing got improved for Craft 3, although I still prefer regular Twig.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-02T19:49:35.960Z
Answers.LastActivityDate: 2018-03-14T12:59:32.370Z
Answers.LastEditDate: 2018-03-14T12:59:32.370Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>For a Single section's entry type that has the title field hidden, I'd like to translate the generated title, as per the entry's locale.</p>
  
  <p>I've currently got the following in the entry type's "Title Format" field:</p>
  
  <pre><code>{section.name|t(language=locale)}
  </code></pre>
  
  <p>However, this doesn't translate the <code>section.name</code> as per the entry's locale, it appears to use the current CP locale instead (i.e., if the CP is currently rendered in English, it'll use the English translation for entries in all locales). However, if I use something like</p>
  
  <pre><code>{section.name|t(language=locale)} ({locale})
  </code></pre>
  
  <p>the latter <code>locale</code> value (inside the parenthesis) does reflect the entry's locale (it'll print something like <code>Section Name (no)</code> for the Norwegian version. So that's a bit odd.</p>
  
  <p>Also, I've tested with a hard coded string for the <code>t</code> filter's <code>language</code> parameter (i.e. <code>{section.name|t(language="no")}</code>), which works as expected.</p>
  
  <p>Not sure what's going on – though I'm guessing that the <code>locale</code> variable passed to the translation filter is somehow <code>null</code> (in which case Craft will use the current locale). How can I translate an entry type's Title Format based on the entry's locale?</p>
  
Tags: <localization><singles><titles>
Title: Translating a section's title field on save
ThreadText: # Translating a section's title field on save
  
  (Asked by: username_0 on 2017-01-02)
  
  For a Single section's entry type that has the title field hidden, I'd like to translate the generated title, as per the entry's locale.
  
  I've currently got the following in the entry type's "Title Format" field:
  
  ```
  {section.name|t(language=locale)}
  
  ```
  
  However, this doesn't translate the `section.name` as per the entry's locale, it appears to use the current CP locale instead (i.e., if the CP is currently rendered in English, it'll use the English translation for entries in all locales). However, if I use something like
  
  ```
  {section.name|t(language=locale)} ({locale})
  
  ```
  
  the latter `locale` value (inside the parenthesis) does reflect the entry's locale (it'll print something like `Section Name (no)` for the Norwegian version. So that's a bit odd.
  
  Also, I've tested with a hard coded string for the `t` filter's `language` parameter (i.e. `{section.name|t(language="no")}`), which works as expected.
  
  Not sure what's going on – though I'm guessing that the `locale` variable passed to the translation filter is somehow `null` (in which case Craft will use the current locale). How can I translate an entry type's Title Format based on the entry's locale?
  
  **Tags:** localization, singles, titles
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-01-02. Score: 3 | Accepted answer
  
  Figured out something that works, though I can't explain why:
  
  ```
  {{ object.section.name|t(language=object.locale) }}
  
  ```
  
  **Update**
  
  Here's how to do it for Craft 3:
  
  ```
  {{ object.section.name|t('site', language=object.site.language) }}
  
  ```
  
  > **Comments:**
  > **username_1**: I think the issue with the short syntax is that you can only use the variable directly at the beginning, so `{locale}` works and `{'foo' ~ locale}` does not. If I understood correctly, short syntax parsing got improved for Craft 3, although I still prefer regular Twig.  
  
  ---
  
  