2

Can you create an Entry with content only for a specific Locale? For instance, I have U.S. English (en_us) and German (de) locales setup for a section. I want to create entries, but only populate one locale. Is this possible?

$entry = new EntryModel();
$entry->getContent()->title = 'Testing Locale';
$entry->sectionId = '14';
$entry->typeId = '16';
$entry->locale = 'de';
$entry->localeEnabled = true;

$entry->setContentFromPost(array('plainTextField' => 'Test'));

craft()->entries->saveEntry($entry);

The resulting code above creates the entry fine, but content is present for both locales. Is this expected behaviour?

  • 1
    Check if your section has both locales enabled as default. It may work better if they're not default and your plugin specifically enables the locale - as you have above. – Mutual Feb 28 '16 at 10:38
3

This is expected behaviour though, it's better (in my opinion) than leaving everything empty.

As Andrew said in his comment, you could by default disable all locales on this section so your entry wouldn't be published in multiple locales.

You can do this by going to the settings of your section: Screenshot of disabled locales

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.