Answers.Body: <p>You're pretty close... You'll need to do this in a <a href="https://craftcms.com/docs/plugins/variables" rel="nofollow noreferrer">Variable</a>, not a Service.</p>
  
  <p>If your method already exists in a Service, or if you'll need to access it via PHP as well, then you can keep it in the Service. In that case, you'll still need a Variable method, but it can simply be a wrapper for your existing Service method.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-05T05:25:50.277Z
Answers.Text: I realized after posting this that your question is focused on _locales_. In theory, it should already be grabbing the value per the user's locale... is it not doing that?
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-05T11:53:53.590Z
Answers.Text: Thanks Lindsey. Sorry, I should have been a little more detailed in my question. Yes, I've passed the function through a 'variable'. It's grabbing the locale version of the content I'm struggling with. I can't find anything that simply gets the content as per the current locale... and it's not doing it automatically.
Answers.UserDisplayName: Mark Notton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-05T05:13:35.327Z
Answers.LastActivityDate: 2017-02-05T05:13:35.327Z
Answers.UserDisplayName: Lindsey D
Body: <p>So I have a plugin with a service. Part of the service function is to grab a field (body) from an entry object that has been passed into the function. </p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  class MyPlugin_ExampleService extends BaseApplicationComponent {
  
      public function example($entry) {
          return $entry-&gt;body;
      }
  
  }
  </code></pre>
  
  <p>The function will be called via Twig.</p>
  
  <pre><code>{{ craft.myPlugin.example(entry) }}
  </code></pre>
  
  <p><strong>How do I go about getting the field data for the users current locale?</strong> </p>
  
Tags: <plugin-development><localization>
Title: How can I get field data for the current locale in a plugin?
ThreadText: # How can I get field data for the current locale in a plugin?
  
  (Asked by: username_0 on 2017-02-05)
  
  So I have a plugin with a service. Part of the service function is to grab a field (body) from an entry object that has been passed into the function.
  
  ```
  <?php
  namespace Craft;
  
  class MyPlugin_ExampleService extends BaseApplicationComponent {
  
      public function example($entry) {
          return $entry->body;
      }
  
  }
  
  ```
  
  The function will be called via Twig.
  
  ```
  {{ craft.myPlugin.example(entry) }}
  
  ```
  
  **How do I go about getting the field data for the users current locale?**
  
  **Tags:** plugin-development, localization
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-02-05. Score: 1
  
  You're pretty close... You'll need to do this in a [Variable](https://craftcms.com/docs/plugins/variables), not a Service.
  
  If your method already exists in a Service, or if you'll need to access it via PHP as well, then you can keep it in the Service. In that case, you'll still need a Variable method, but it can simply be a wrapper for your existing Service method.
  
  > **Comments:**
  > **username_1**: I realized after posting this that your question is focused on _locales_. In theory, it should already be grabbing the value per the user's locale... is it not doing that?  
  > **username_0**: Thanks username_1. Sorry, I should have been a little more detailed in my question. Yes, I've passed the function through a 'variable'. It's grabbing the locale version of the content I'm struggling with. I can't find anything that simply gets the content as per the current locale... and it's not doing it automatically.  
  
  ---
  
  