Skip to content

Inconsistency between space/environments locales and default locale #204

@HQ063

Description

@HQ063

There is some inconsistency regarding locales and default locale on space and environment. The locales are defined in a specific environment, but the default locale is defined in the space. This leads to weird situations.
For example, the space object has a #default_locale method, but it has no #locales and the environment has a #locales but not a #default_locale, and when I query the defaul_locale
for an space I get a code that is not part of the allowed locales for the master environments.

[103] pry(main)> space = contentful_management.spaces.find('vyk520m9px5z')
[104] pry(main)> space.locales
NoMethodError: undefined method `locales' for #<Contentful::Management::Space:0x00007fdb22b87838>
[105] pry(main)> space.default_locale
=> "en-US"
[108] pry(main)> environment = space.environments.find('master')
[109] pry(main)> environment.default_locale
NoMethodError: undefined method `found_locale' for #<Contentful::Management::Environment:0x00007fdb251fefe8>
[112] pry(main)> environment.locales.all.collect(&:code)
=> ["en-CA", "fr-CA"]

So default_locale is en-US for an space that doesn't has en-US as available locale in any of the environments.

This should not be a big problem, except that when I retrieve a content_type from that environment, the default_locale for that content_type is also wrong.

[115] pry(main)> product = environment.content_types.find('product')
[116] pry(main)> product.default_locale
=> "en-US"

And that problem causes a lot of other bugs, for example: #201, #202, #203

I've read #73 and I know I can use product.client.configuration[:default_locale] = 'en-CA', but that changes the default_locale for the whole contentful management client, and I need to keep it independently for each space.

As a workaround I'm avoiding this problem with this:
product.define_singleton_method(:default_locale) { 'en-CA' } but doesn't feel like a real solution, it's more a temporal patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions