Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

localize_entry fails #124

Closed
fkamras opened this issue May 23, 2017 · 4 comments
Closed

localize_entry fails #124

fkamras opened this issue May 23, 2017 · 4 comments
Assignees
Labels

Comments

@fkamras
Copy link

fkamras commented May 23, 2017

I noticed some new fields in the synced data that contains the content type id and created and updated dates.
It seems like the localize_entry function is failing becuase of this, as it's trying to get the en-US field that does not exist there.
Seems like this is the problem as it's working once I remove the meta key before the localize_entry function but it would be better if I don't have to go through my whole code to add this.

I'm using the dl/upgrade-to-v4 branch

@fkamras
Copy link
Author

fkamras commented May 24, 2017

I'm not sure if it's the same issue, but since yesterday all the data that I accessed with camel case is now only available with underscores....

@dlitvakb
Copy link
Contributor

Hey @fkamras,

Regarding the first issue, I'll look into it ASAP, it looks like a bug.

Regarding the second issue, it's a documented change with version 2.0.0 -> https://github.com/contentful/contentful_middleman/blob/master/CHANGELOG.md#changed

Cheers

@dlitvakb dlitvakb added the bug label May 24, 2017
@dlitvakb dlitvakb self-assigned this May 24, 2017
@brtdwchtr
Copy link
Contributor

brtdwchtr commented Jul 11, 2017

Bumping this... Any updates, @dlitvakb ?

If it might help, the problem code can be found on line 32 of helpers.rb

return value.fetch(locale) if value.key? locale
return value.fetch(fallback_locale)

It will throw an error when trying to localize for example the _meta property of a datafile

 :_meta:
    :content_type_id: sometype
    :updated_at: '2017-07-10T21:14:03+00:00'
    :created_at: '2017-07-06T11:24:38+00:00'
    :id: xYz123XyZ321zYX123

I was thinking the solution might be to rewrite localize_value like this:

def localize_value(value, locale, fallback_locale='en-US')
    if value.respond_to? :fetch
       return value.fetch(locale) if value.key? locale
       return value.fetch(fallback_locale) if value.key? fallback_locale
    end
    value
end

Unless just returning the original hash, if no language or fallback has been found, could present another problem?

EDIT: went ahead and created a PR for this

@dlitvakb
Copy link
Contributor

Fixed by #128

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants