1

I'm dealing with tag localization on an English/Spanish site and have figured out that if I create a new tag, both En and Es elements are created by default, which would be O.K. if I never had to filter tags for locale.

I discovered that if I manually delete the duplicate element from the other locale, they do only show in their respective locales, which is ideal for this. Is there a way to do this via the admin UI?

I have made the tags field on my entries non-translatable, but what would stop Craft from creating duplicate elements for the other locale?

EDIT: Also, if I update a tag, the other locale version that I deleted is recreated automatically :/

1

OK, so this isn't quite how i expected it to work, but it does so far. I won't post code, because you just need the right process:

Assuming you're creating tags for a dual locale site of English (en) and Spanish (es)

  1. Create a TagModel for first locale (en)
  2. Set attributes and content for first en version
  3. Save it
  4. Load a new instance of a TagModel by loading the tag you just saved by id, but specify the other locale.

    $tag_es = craft()->tags->getTagById($tag_en->id, "es")
    
  5. Assign the es title, content and attributes (regenerate the slug, too!)

  6. Save the es tag with

    tags->saveTag($tag_es)
    

Now, Tag Manager should keep them separated by locale, and you can query them by locale, too.

The bottom line is, you have to create alternate locale versions by essentially cloning the original Tag Model while specifying the new locale string, then reassign the content and just save it. Again, not what I expected.

EDIT: Check your results in the database. Don't believe the Tag Manager — it only shows data from one locale for some reason.

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.