Answers.Body: <p>I got it. I added this function to the Event_ElementType    </p>
  
  <pre><code>public function isLocalized()
  {
      return true;
  }
  </code></pre>
  
  <p>This adds a language selector to your event index.</p>
  
  <p>Then I enhanced the locale to the URL in <code>getCpEditUrl()</code> of the EventModel:</p>
  
  <pre><code>$locale = (craft()-&gt;isLocalized() &amp;&amp; $this-&gt;locale != craft()-&gt;language) ? '/' . $this-&gt;locale : '';
  return UrlHelper::getCpUrl('events/'.$calendar-&gt;handle.'/'.$this-&gt;id . $locale );
  </code></pre>
  
  <p>The additional route for the locale edit form is like this:</p>
  
  <pre><code>events/(?P&lt;calendarHandle&gt;{handle})/(?P&lt;eventId&gt;\d+)/(?P&lt;locale&gt;[-\w\.*]+)' =&gt; array('action' =&gt; 'events/editEvent')
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-14T11:41:07.143Z
Answers.Text: phaetons, I am trying to create a localized ElementType myself. I followed much of what you mentioned here, and it'll let me edit in various languages using the ElementType picker. However, the only changes that are saved localized are the `Title`. Any custom fields are always globally changed. Any pointers? Or better yet, post your modified Events plugin code to GitHub?
Answers.UserDisplayName: andrew.welch
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-11T12:34:35.910Z
Answers.LastActivityDate: 2017-06-02T03:49:33.573Z
Answers.LastEditDate: 2017-06-02T03:49:33.573Z
Answers.UserDisplayName: phaetons
Body: <p>I explored the events plugin (from <a href="https://github.com/pixelandtonic/Events" rel="nofollow noreferrer">https://github.com/pixelandtonic/Events</a>) and I understand the most of that. Now I will try to make the events localized. </p>
  
  <p>The Event itself has no localized field, just the fieldLayout fields. Do I have to save a second record in the event db or did I just have to save the element with the corresponding locale id?</p>
  
  <p>Can you give me a hint what steps are needed that I can edit them in two languages?</p>
  
  <p>So far, I load an existing event </p>
  
  <pre><code>craft()-&gt;elements-&gt;getElementById($eventId, 'Events_Event', $locale);
  </code></pre>
  
  <p>with the new locale parameter and create the edit form, putting the locale as hidden field to the form ('de' instead 'en'). The fieldLayout fields are showing the 'de'-icon above the input fields.</p>
  
  <p>When I try to save it, I pass through the locale in the $event variable to
  <code>craft()-&gt;elements-&gt;saveElement($event)</code></p>
  
  <p>I do not pass it to the <code>$eventRecord</code> because the $eventRecord itself didn't have a locale.</p>
  
  <p>The event will be saved, just not in 'de' but in 'en'.</p>
  
  <p>Do I have to tell the elementtype or the model that it can be localized to make it work?</p>
  
Tags: <plugin-development><localization><elementtype>
Title: Localize custom element types
ThreadText: # Localize custom element types
  
  (Asked by: username_0 on 2015-09-11)
  
  I explored the events plugin (from <https://github.com/pixelandtonic/Events>) and I understand the most of that. Now I will try to make the events localized.
  
  The Event itself has no localized field, just the fieldLayout fields. Do I have to save a second record in the event db or did I just have to save the element with the corresponding locale id?
  
  Can you give me a hint what steps are needed that I can edit them in two languages?
  
  So far, I load an existing event
  
  ```
  craft()->elements->getElementById($eventId, 'Events_Event', $locale);
  
  ```
  
  with the new locale parameter and create the edit form, putting the locale as hidden field to the form ('de' instead 'en'). The fieldLayout fields are showing the 'de'-icon above the input fields.
  
  When I try to save it, I pass through the locale in the $event variable to
  `craft()->elements->saveElement($event)`
  
  I do not pass it to the `$eventRecord` because the $eventRecord itself didn't have a locale.
  
  The event will be saved, just not in 'de' but in 'en'.
  
  Do I have to tell the elementtype or the model that it can be localized to make it work?
  
  **Tags:** plugin-development, localization, elementtype
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-09-11. Score: 1
  
  I got it. I added this function to the Event\_ElementType
  
  ```
  public function isLocalized()
  {
      return true;
  }
  
  ```
  
  This adds a language selector to your event index.
  
  Then I enhanced the locale to the URL in `getCpEditUrl()` of the EventModel:
  
  ```
  $locale = (craft()->isLocalized() && $this->locale != craft()->language) ? '/' . $this->locale : '';
  return UrlHelper::getCpUrl('events/'.$calendar->handle.'/'.$this->id . $locale );
  
  ```
  
  The additional route for the locale edit form is like this:
  
  ```
  events/(?P<calendarHandle>{handle})/(?P<eventId>\d+)/(?P<locale>[-\w\.*]+)' => array('action' => 'events/editEvent')
  
  ```
  
  > **Comments:**
  > **username_1**: username_0, I am trying to create a localized ElementType myself. I followed much of what you mentioned here, and it'll let me edit in various languages using the ElementType picker. However, the only changes that are saved localized are the `Title`. Any custom fields are always globally changed. Any pointers? Or better yet, post your modified Events plugin code to GitHub?  
  
  ---
  
  