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

Enhance internationalization #143

Closed
brunvez opened this issue Apr 9, 2020 · 8 comments · Fixed by #145
Closed

Enhance internationalization #143

brunvez opened this issue Apr 9, 2020 · 8 comments · Fixed by #145

Comments

@brunvez
Copy link
Contributor

brunvez commented Apr 9, 2020

Hey, I came by a use case where I needed to translate my torch interface to Spanish. Doing that in the view I have in my projects is straightforward since I can call the gettext macros on the strings. The issue is that neither the filters nor the pagination allowed me to override the translations.

I came by these two questions in the Elixir forum that give some insight on how to internationalize those strings and cooked my own solution here. It's a bit of a WIP but it worked for me and with some polish maybe we can merge it in if you think it'd be useful.

Forum questions:

@cpjolicoeur
Copy link
Member

Hey @brunvez, I think we are all for adding better/proper I18N support into Torch. Either just by adding the es Spanish gettext files directly, or with a "larger" implementation like you have executed.

Is the issue, that Torch currently just doesn't provide a Spanish translation file (we currently only have English and Russian) or that even if we did have a Spanish file, you couldn't get what you needed?

@brunvez
Copy link
Contributor Author

brunvez commented Apr 9, 2020

Thanks for answering, adding the es translation directly would solve things form me. I just wanted to push for a more comprehensive solution since this may arise again in the future.

Though I have to admit I don't really like the current way of solving it with gettext, or at least the one I could find 😅

@cpjolicoeur
Copy link
Member

I'd love to add as many translation files as possible, but I'm not a native speaker of all these languages, so we've been adding them to the system as users request them and can provide correct translations.

Using a sort of hybrid approach might not be a bad solution though as it would allow us to add the translation files as the community provides them, while also allowing users to dynamically use their own local translation while not "official" translation file exists.

@brunvez
Copy link
Contributor Author

brunvez commented Apr 9, 2020

Yeah, I think this provides kind of the best of both worlds. It maintains current functionality and allows to extend it to any language. For some context, this is the needed code for developers to config their custom texts:

config :torch,
  otp_app: :my_app,
  messages_backend: MyApp.Torch.MessagesBackend,
  template_format: "eex"
defmodule MyApp.Torch.MessagesBackend do
  import MyAppWeb.Gettext, only: [dgettext: 2]

  def message("Contains"), do: dgettext("torch", "Contains")
  def message("Equals"), do: dgettext("torch", "Equals")
  def message("Choose one"), do: dgettext("torch", "Choose one")
  # ...
end

I'd also be glad to add translations for Spanish of course.

@cpjolicoeur
Copy link
Member

Would you be open to submit a Pull Request here with the MessagesBackend features. It could include the Spanish translations as well, or you could submit those as a second pull request if you want.

@brunvez
Copy link
Contributor Author

brunvez commented Apr 9, 2020

Sure thing, I'll make some tweaks and open a PR

@cpjolicoeur
Copy link
Member

@brunvez Version 3.1.0 should now be on hex.pm. Thanks again.

@brunvez
Copy link
Contributor Author

brunvez commented Apr 14, 2020

Thank you @cpjolicoeur!

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