Skip to content
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

Returning a translated record from the DB #78

Open
bigardone opened this issue Nov 24, 2022 · 2 comments
Open

Returning a translated record from the DB #78

bigardone opened this issue Nov 24, 2022 · 2 comments

Comments

@bigardone
Copy link

👋🏼 Hi there, I just started using this great library (thanks for sharing it 🙌🏼 ), and I was wondering what would be the best approach to return a translated record from the DB. From what I've read in the main version, translated_as returns a translated field that Ecto can load into a struct, so I'm doing something like the following:

  def with_translated_name(query, locale) do
    from c in query,
      select_merge: %{name: translated_as(Car, c.name, locale)}
  end

Is this how it is intended to be used, or is there a better way of doing it without the select_merge?
I haven't found any examples in the tests.

Thanks in advance!

@crbelaus
Copy link
Owner

crbelaus commented Dec 10, 2022

Hi @bigardone, thanks four your interest in Trans!

At the moment this is the best way that we have. I have to think about it a bit more but maybe we can have a macro that allows you to translate multiple fields at once. This looks like a common use case that should be covered by the library.

@bigardone
Copy link
Author

Hi @crbelaus, thanks for the reply 🙌. Having something that returns a translated record would be awesome! I'll stick to the select merge in the meantime 😊

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

No branches or pull requests

2 participants