-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
i18n support DOCS with ReactOnRails using "RailsContext" #212
Comments
Might be just a doc thing where you use i18n-js to build the file and put this into your webpack bundles. |
I'd like to see this solution leverage the i18n support that's already built into rails. So the translations can all live in one place. Whatever is used on the JS side, you can imagine a translation layer that just loads the rails YAML files containing the translations, then - ahem - translates them into whatever JSON format is needed for the client/react side. I'm doing exactly this with Rails fixtures, so I can use fixture_builder to autogenerate fixtures in Rails, then have a small javascript shim/proxy module that just reads the Rails YAML fixtures directly from the filesystem, parses the into a JS object, and exposes them into whatever needs it on the JS side. |
I definitely agree with @thewoolleyman and @rstudner (on the other issue) that we should leverage the rails i18n support. |
I would rather see a pluggable interface. We use As an example My initial idea would be to put a call to a plugin ( There's also this: https://github.com/webpack/i18n-webpack-plugin which we've considered. |
+1 This is what some people are doing with |
I was going to look at implementing the same behavior with a prerender hook. On Wed, Jan 27, 2016 at 5:54 AM, Luca Canducci [email protected]
|
The prerender hook is fine for setting up the locale per each request (I guess you mean that?) but I'm wondering how to make the files required per each locale (in case of To be honest, I'd be happier to have a solution which is only driven by Rails locale files, although you will still need to get the formatting rules (e.g. numbers, dates) somewhere reliable (say Yahoo's |
We could create a default Renderer which handles Rails i18n, but my project On Wed, Jan 27, 2016 at 6:54 AM, Luca Canducci [email protected]
|
@martyphee @lucke84 @thewoolleyman The best way to evaluate this is to create a super simple example from the generated app, or maybe on the https://github.com/shakacode/react-webpack-rails-tutorial/ |
Has anyone done work on this yet? I'm in London this week talking to If not I'll see if I can do something tonight. @lucke84 https://github.com/lucke84 @thewoolleyman On Thu, Jan 28, 2016 at 5:33 AM, Justin Gordon [email protected]
|
We're working on a solution but atm it's rather custom. If it proves to be good enough, we'll try to extract a general one and happily share it with everybody. This could take a while though, so I suggest others give it a try as well 😄 |
Sure, we need this for our POC. We're currently using it to inject On Tue, Feb 16, 2016 at 3:15 PM, Luca Canducci [email protected]
|
https://gist.github.com/martyphee/2a36d9429cb084228c7b This adds before_render and after_render hooks. We're currently using Jed as our GetText implementation. On Tue, Feb 16, 2016 at 3:15 PM, Luca Canducci [email protected]
|
Has anyone had a chance to look at the gist I created? On Thu, Feb 18, 2016 at 8:14 AM, Martin Phee [email protected] wrote:
|
Hi there! We have implemented a semi-nice integration with
This workflow essentially looks up all the calls to Feel free to use the gist, but beware that it is pretty much coded to support only our use case and we've just tested it manually that it works. We have been looking at properly open-sourcing this plugin to support this workflow, but we're not sure whether others besides us have a need for such plugin. This is how the code using the translations look, very similar to Rails: // With I18n.locale = 'fi';
const reviewsText = I18n.t('some_namespace.reviews', { count: reviewsCount }) The YAML translations looked like this: ---
fi:
some_namespace:
reviews:
count:
one: "%{count} arvostelu"
other: "%{count} arvostelua" We also create separate JS builds for all locales we support. With that, we are able to replace special translation calls compile-time to translated strings. It uses a heavily configured version of // Before
const myStr = __('some_namespace.hello_world');
// After, for main-fi.js bundle
const myStr = 'Hei, maailma!';
// And for main-en.js bundle
const myStr = 'Hello, world!'; ---
fi:
some_namespace:
hello_world: Hei, maailma! ---
en:
some_namespace:
hello_world: Hello, world! Would there be interest outside to help us develop these approaches should we open-source this? It would be awesome to be able to contribute to i18n tooling, but I'm afraid that we might not have much time to support other use cases / workflows besides ours even if we'd want to. |
@valscion this is great. I had done a far more hacky version (exporting the translations.js periodically and just "using it" but his is much more elegant) Definitely should put this out publicly! :) |
Thanks @rstudner, I'll try to ping you when there's more news :) |
@valscion @rstudner @martyphee Thanks to all for your efforts here!!! 👍 |
Are we dropping this because of the railsContext thing we added? |
The railsContext solved my issue. I use it to pass in the translations and then use those to initialize Jed. |
@martyphee @jbhatab Any chance that we can get this documented? |
@justin808 isn't the railscontext documentation more than enough since how you integrate that with your react setup is custom? |
Our implementation is pretty custom. In rails we use FastGettext and customer rake tasks to pull translations from phraseapp. The rack task them builds json files which I include in the railsContext based on the current locale. |
I'm going to close this for now. The solution is to use the Yes, we'd love to get some articles and examples on how to do this! |
React on Rails is amazing, and I really appreciate all the hard work everyone has put into this. It is hands down the best way to get started with React and Node coming from a Rails background. I have been able to get incredible tooling running and have been able to build and test components in a large, existing app (1500+ rspec tests) by adapting code the react-webpack-rails-tutorial, all in a single weekend. But I cannot get railsContext to work, probably because, as @jbhatab says, the react setup is custom, and there is only one usage of railsContext in that demo, and I can't figure out how to access the data in there. If I log the location const I just get |
@martyphee, can you maybe give us a hand with some tips? |
@reconstructions I've got examples here of the railsContext, albeit not for i18n.
Having some great docs for this would be so useful for the community! Anybody game to help? |
I am game to help. I am making some progress now, although painfully so since I am new to ES6, React, and Redux, as well as how how you have structured your elegant implementation. I have the railsContext object passing through now, so thanks for the links. Since I have been coding JS and Rails for a long time, I think the fastest way for me to master your approach will be to build a new Todo component which matches the Egghead Redux tutorial functionality, only implemented using the React on Rails framework. I am on my way doing this in my own app, and then once I have test coverage I will checkout your demo and get it working there. So give me some time to go all out on this. After I have something I would really appreciate refactoring advice, and then I will write the process up as a tutorial which reflects all the gotcha wisdom that comes from being a newbie to ES6, React, Redux, and React on Rails. I (will) really appreciate any advice! |
@reconstructions the best thing for us to do is to try to implement the i18n JS functionality in the https://github.com/shakacode/react-webpack-rails-tutorial/ as an example. I'm hoping that @martyphee can provide some guidance. I can help as well. |
Sounds good, I'll do what I can. |
We're not using
|
Seems to be a lot of opinions on adding RailsContext, thought I'd share a bare no-fluff approach. client/app/bundles/Homepage/startup/HomepageClient.jsx
Then you can access it using |
@stuarthannig any chance you can throw in a doc PR? |
I can try when I get time, and more understanding. But to add to the Add config/initializers/react_on_rails.rb
client/app/bundles/Homepage/containers/Homepage.js
You'll need to add |
@Judahmeek This would be a great addition to our gitbook! |
@justin808 A lot of discussion here. By "this", are you referring to Stuart's comments here at the end? @stuarthannig Any chance you and I could connect on Slack, Skype, or another IRC-like platform so I could get a better understanding of your solution? |
@Judahmeek yes to your question directed to me. |
FYI, this PR seems like a good example of i18n: |
Eventually, we want to do something for supporting i18n.
Maybe there’s some file that gets built for the JS code.
Maybe we should integrate/support: https://github.com/fnando/i18n-js?
Here's on a SO topic on Rails integration for client side:
http://stackoverflow.com/a/10610347/1009332
CC: @callumacrae
The text was updated successfully, but these errors were encountered: