New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get a list of available locales #39

Closed
cbothner opened this Issue May 31, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@cbothner

cbothner commented May 31, 2017

Is there a way to get a list of the locales in which a certain attribute has a value? I'm using the postgres jsonb backend, and I know I could just do @model.read_attribute(:title).keys, but that seems brittle and like there ought to be a way that doesn't require me to know about the json blob structure.

@shioyama shioyama added the feature label May 31, 2017

@shioyama

This comment has been minimized.

Show comment
Hide comment
@shioyama

shioyama May 31, 2017

Owner

There isn't a way to do it currently, but you're right that it would be good to have something that any backend could use in the same way.

There are a few things like this that I've left out so far to focus on making sure the core of the gem works without issues, which it seems to do now, so I'm open to taking these kinds of feature requests. I'll keep note of this and in the next phase of work (probably in the next few weeks) think about how to implement them in a backend-independent way.

Owner

shioyama commented May 31, 2017

There isn't a way to do it currently, but you're right that it would be good to have something that any backend could use in the same way.

There are a few things like this that I've left out so far to focus on making sure the core of the gem works without issues, which it seems to do now, so I'm open to taking these kinds of feature requests. I'll keep note of this and in the next phase of work (probably in the next few weeks) think about how to implement them in a backend-independent way.

@jnylen

This comment has been minimized.

Show comment
Hide comment
@jnylen

jnylen Jul 27, 2017

@shioyama Any ETA?
I'm using jsonb.

Is it possible to like grab the jsonb data instead of only returning the language specific translation?

jnylen commented Jul 27, 2017

@shioyama Any ETA?
I'm using jsonb.

Is it possible to like grab the jsonb data instead of only returning the language specific translation?

@shioyama

This comment has been minimized.

Show comment
Hide comment
@shioyama

shioyama Jul 28, 2017

Owner

You can always get the jsonb hash with @model.read_attribute(:title) if title is the attribute. As @cbothner noted, you can also get the locales with @model.read_attribute(:title).keys.

Of course this is jsonb-specific, other backends would have to be handled differently, and that's what I'm thinking about. Probably something like @model.title_backend.locales. I'm aiming to have that in for 0.2.0, which I'm working on. But if you need this now, just use @model.read_attribute(:title).keys, it should work fine as long as you don't switch backends.

Owner

shioyama commented Jul 28, 2017

You can always get the jsonb hash with @model.read_attribute(:title) if title is the attribute. As @cbothner noted, you can also get the locales with @model.read_attribute(:title).keys.

Of course this is jsonb-specific, other backends would have to be handled differently, and that's what I'm thinking about. Probably something like @model.title_backend.locales. I'm aiming to have that in for 0.2.0, which I'm working on. But if you need this now, just use @model.read_attribute(:title).keys, it should work fine as long as you don't switch backends.

@shioyama

This comment has been minimized.

Show comment
Hide comment
@shioyama

shioyama Aug 12, 2017

Owner

This has been merged into the master branch. Just call post.title_backend.locales to get the locales for the title attribute.

I'll be releasing 0.2.0 with a bunch of changes in the next day or so.

Owner

shioyama commented Aug 12, 2017

This has been merged into the master branch. Just call post.title_backend.locales to get the locales for the title attribute.

I'll be releasing 0.2.0 with a bunch of changes in the next day or so.

@shioyama

This comment has been minimized.

Show comment
Hide comment
@shioyama

shioyama Aug 13, 2017

Owner

@cbothner @jnylen 0.2.0 has been released, see the changelog and this summary of changes. You can now get available locales with post.title_backend.locales, etc.

Owner

shioyama commented Aug 13, 2017

@cbothner @jnylen 0.2.0 has been released, see the changelog and this summary of changes. You can now get available locales with post.title_backend.locales, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment