I am internationalizing my app, and after having translated the interface with the yml locale files, I now want to localize my models. I am using ActiveAdmin so the editors can update content and I would like the solution to be suitable for this.
Is there any way to define some of my model attributes as translatable, so rails generates a migration that creates an extra field for each locale / language? This, or something similar, would be my prefered solution, but I a open to other aproaches.
Check this discussion you'll find an approach for the same problem you have.
You can use globalize3 gem. It's great gem to manage model translations.
Related
I have some url templates that I use in my app - they are not localizable strings, so config/locales/en.yml does not seem like the best place for them - where do I store these? For example, "http://www.example.com/apps?id=" is one such string.
I know there are several approaches possible (a constants file in the lib folder, or using rails configuration in rails4, or some config gem like configatron), but what is the'right' way?
I don't know that there is "a right way" - the new 'x' configuration option system in Rails 4 seems to be the most "Railsy" solution out there.
I personally think it is totally okay to have a GlobalConstants module defined in an initializer or a file in the lib directory. Put all your global constants in there and be diligent about using them throughout your app where needed.
For projects where there's a mix and match of i18n strings I like having a "base" i18n file and then using the override system to create a sort of inheritance chain between the i18n files. That's not always the appropriate solution but I've had it work out quite well a few times.
Hope that helps you.
As you said there are many solutions and it dependence on usage.
You can store them in environment variables.
dotenv gem help you handle it easier:
https://github.com/bkeepers/dotenv
I'm using http://guides.rubyonrails.org/i18n.html for localization. Looks like that the only solution for updating localization is to update yml files. May be there are some solutions or gems which adds ability to update localization via application. For example we can include some gem and update localization files from our app. Is there some solutions for that?
Shameless plug for my own product here, but check out http://www.localeapp.com for a solution that works with YAML files out of the box.
Take a look at Globalize 3. It stores the translation/localization data in the database. There's also a gem to hook it up with ActiveAdmin.
Also, while you're at it, don't miss the rails-i18n gem mentioned in the guide. It translates Rails itself into many languages, so you don't have to do it yourself.
There is a great railscast to manage i18n through Redis.
I have notice that there are many files created by generators (not only scaffold, but rails generate in general) that I don't use.
So I came up with the following questions (about best practices):
Do you use generators or it is preferable to create by hand only files you need?
If you use generators, do you keep all generated files?
You can use generators specifically to help you build individual files. For instance, you could use
rails g model Video title:string link:string
to create a model file with those as attributes, but you don't need to use scaffolding to generate everything (if that's what you're referring to)
Personally I like to use a combination -- it really depends on the project. But I'd tell you not to have extra files that you aren't using, so definitely delete the ones you aren't using (or don't plan to use).
Hope this helps.
i do use the generators and just delete the files. It is probably because I am lazy but I find this easier.
Especially with models, because it includes the migration.
Honestly it all comes down to just preference. Just don't scaffold...
Since there are so many options there available for internationalization of a rails app, which gems or plugins are the best (today) for adding i18n support to a rails app.
Im using I18n bundled with rails for the application messages, button labels, and model attribue names.
But I also need to let the users to input content and the translated version of the content, but there are so many options for this right now that I don't really know which one to use.
We at Mynewsdesk (the guys behind the translate plugin) has moved on, now we're using Web Translate It to manage our locales. We've bloged about our translation workflow.
I like this one:
https://www.github.com/mynewsdesk/translate
because it has a nice webGUI for translating new/changed strings
What changes do you need to make to a Rails project to configure blueprintcss as the default stylesheet to be used when you generate scaffolding instead of scaffold.css?
I'd recommend writing your own generator, but if you want to alter the default you can:
1 - For a single app: Freeze rails and change the stylesheet the scaffold generator uses.
railsapp/vendor/rails/railties/lib/rails_generators/generators/components/scaffold/templates/style.css
2 - For all apps: Change the same style.css file in your systems rails installation.
Substitute your own scaffolding generation code. Instructions are here (with the caveat that they may be out of date).
An easier alternative may be to write a Rake action to do textual substitution in the (normally) generated source.
Look into Rails Templates.
You can write one to do much more than replace the css in a rails app. YOu can make it install gems, freeze rails, all kinds of things. Take a look at http://youvegotrails.com for an idea of what you can do.