statamic-fetch icon indicating copy to clipboard operation
statamic-fetch copied to clipboard

Localized Collections in Global

Open monstromatic opened this issue 7 years ago • 10 comments

Hello

My global contains 2 localized collections and localized text vars. When I switch the "locale", the vars are updated but the collections stay in the default locale.

When I switch from english to french {{ fetch global="footer" locale="fr" }} => text vars change as excepted but collections don't. Any idea?

monstromatic avatar Dec 19 '18 00:12 monstromatic

Hmm, I'm not 100% sure I understand what you mean with: "My global contains 2 localized collections". Do you mean you reference collections from a Global (so it's related data)?

Can you share the Global fieldset and Global data (just sample data, doesn't haven't have to be "real") so that I can try and recreate the issue on my end.

aryehraber avatar Dec 19 '18 08:12 aryehraber

Yes that's it :-)

Here is the footer global data in the default locale (site/content/globals/footer.yaml):

footer_title: 'Come see us!'
addresses_collection:
  - 31c18869-c380-41c4-8f6a-76bb69992711
page_links:
  - d30c66fb-954d-4d23-94b2-1d566dd65bf5
external_links:
  - dc2997dd-c597-43e4-bd76-789479625154
copywrite: 'All Rights Reserved.'
title: Footer
fieldset: footer_globals
id: 12d6d17e-22d9-444a-bca3-5c8f57cf2fe3

Here is the translated footer global data (site/content/globals/fr/footer.yaml): site/content/globals/fr/footer.yaml

footer_title: 'Passez nous voir !'
copywrite: 'Tous droits réservés.'
id: 12d6d17e-22d9-444a-bca3-5c8f57cf2fe3

Here is the footer_globals fieldset:

sections:
  main:
    display: Main
    fields:
      footer_title:
        type: text
        localizable: true
        display: 'Footer title'
      addresses_collection:
        collection:
          - addresses
        mode: panes
        type: collection
        display: 'Addresses Collection'
        localizable: true
      page_links:
        type: pages
        display: 'Page links'
        mode: panes
        localizable: true
      external_links:
        collection:
          - external-links
        mode: panes
        type: collection
        localizable: true
        display: 'External links'
      copywrite:
        type: text
        display: Copywrite
        localizable: true
title: 'Footer Globals'
hide: true
taxonomies: true

Thanks a lot for your help!

monstromatic avatar Dec 19 '18 09:12 monstromatic

Great, thanks for the example data!

I can't make any promises in terms of timeline, but I'll try and have a look at this when I next have some time available!

aryehraber avatar Dec 19 '18 11:12 aryehraber

Hello,

Any update about that? The bug appears not only on globals but on pages too. It is a huge issue for my project cause I'll have multiple langues and a lot of collections... Maybe in the goDeep function?

monstromatic avatar Jan 05 '19 00:01 monstromatic

Hey @monstromatic, I had a look at this today (took a while to dig up a multilingual site) but everything seems to be working as expected.

  • Created a Collection with a few localised entries (used 3 languages)
  • Then added a related Collection field to Globals and selected a few entries
  • Visited /!/Fetch/global/global?locale=nl and the correct locale was shown in the data
  • Created a test template and used {{ fetch global="global" locale="nl" }} which also showed correct locale data

Can you confirm that you're on the latest version of Fetch (v4.3.1)? And which version of Statamic are you using?

aryehraber avatar Jan 05 '19 10:01 aryehraber

Hey! Thanks for digging! Yes I use Statamic 2.11.3 et Fetch 4.3.1. I still have the issue, even with pages and pages with mounted collection.

"First level" data are localized as excepted but related datas with id (like: addresses_collection:

  • 31c18869-c380-41c4-8f6a-76bb69992711) are always bring back in default locale...

monstromatic avatar Jan 05 '19 12:01 monstromatic

Hmm, maybe I didn't nest deep enough. I'll try and add an additional level of related data to the entries and see if that shows the bug you are experiencing.

If not, perhaps you are able/willing to share your existing project (privately) to make the recreation process easier on my end?

aryehraber avatar Jan 05 '19 14:01 aryehraber

Thank you so much for trying! The project actually run locally but I could try to give you a kind of "package" for testing. Feel free to ask me for testing some code changes in Fetch.php in my project, I am working on it all day long 7/7...

monstromatic avatar Jan 05 '19 14:01 monstromatic

Hey @monstromatic, I did some further digging and there's definitely something funky going on when data is nested deeper than 1-2 levels. I'm not seeing your bug, but hitting something else atm.

Either way, this is currently out of scope of what I have time for unfortunately. I can take 1 final crack at it if you ZIP up your project (removing all sensitive data, e.g. passwords, keys, etc) and emailing me at [email protected]. I'll try and at least look at your particular issue, but can't promise anything.

aryehraber avatar Jan 05 '19 15:01 aryehraber

I ran into a very similar issue to the one described above, and I was able to resolve it with a very small change to Fetch.php.

I doubt it will be any help to OP after all this time, but below is the fix anyway:

In the relatedData($value, $key) function, change

if (Content::exists($value)) {
    return Content::find($value)->toArray();
}

to

if (Content::exists($value)) {
    if ($this->locale !== default_locale()) {
        return Content::find($value)->in($this->locale)->toArray();
    }
    return Content::find($value)->toArray();
}

adxmcollins avatar Sep 01 '21 14:09 adxmcollins