Skip to content

Get a list of available locales #39

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

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

Get a list of available locales #39

cbothner opened this issue May 31, 2017 · 5 comments
Labels

Comments

@cbothner
Copy link

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
Copy link
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.

@jnylen
Copy link

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
Copy link
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.

@shioyama
Copy link
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.

@shioyama
Copy link
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.

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

No branches or pull requests

3 participants