Add translation into i18n locales of Rails - ruby-on-rails

I want to create a simple form that adds translations dynamically into config/locales/en.rb. There's a way to do this? I'll need something like a parser to solve this?

With using Globalize3 gem given here on stack-overflow answer Add translation to I18N dynamically
Rails cast link:
http://railscasts.com/episodes/338-globalize3?view=asciicast

Related

Can I access SASS variables from Rails classes?

In my Rails 4 application I have a number of SASS variables like this one:
$primary_color: #ec4158;
Is it possible to access that variable from a Rails class somehow?
Thanks for any help.
I think you have to make it the other way around.
define constants in an initializer or somewhere else (like this)
generate your sass using erb (yourstyle.sass.erb)
use the same constants in your prawn generation

Faker generate english sentences in ruby on rails

While using Faker with rails, it generates sentences in some other language. I want them to be generated in English. What kind of settings do I need to change to do it?
Docs say
Just set Faker::Config.locale to the locale you want, and Faker will take care of the rest.
https://github.com/stympy/faker/blob/master/README.md
https://github.com/stympy/faker/tree/master/lib/locales
Faker::Config.locale = :en

Rails i18n in one table (CakePHP-like)?

Is there a Gem that stores translations in one table like CakePHP does?
The polymorphic CakePHP i18n-table has the following structure:
id
locale
model
foreign_key
field
content
Globalize3 i.e. uses a new table for each model translation which I find too redundant.
You can add various backends to the i18n gem which generally provides internationalization for ruby. Globalize3 is one option. A more lightweight alternative could be i18n-active_record which uses a single table similar to your CakePHP example.

What gem should I use in order to have all the translations in the DB?

I've played a bit with globalize and rails 3, but from what I'm able to tell, globalize only works for ActiveRecord instances. I'd also like to be able to have the translations for other static pages in the database ( say for example header,footer, company details etc. ). Is this possible to do with globalize? If not, please recommend a gem that I should use.
I managed to do this using i18n-active_record
If you want to translate static page parts - you may create a new model (with globalize translations) and use it for storing static content (or just put your translations into config/locales folder)

HTML Purifier equivalent for Ruby on Rails?

Has anyone encountered an equivalent to HTMLPurifier for Rails apps? Essentially I need to clean up often terribly formed HTML generated by users before saving to the DB.
http://htmlpurifier.org/
You can use the sanitize method.
sanitize(html)
There is also a Sanitize gem.
Sanitize.clean(html)
I tend to prefer the Sanitize gem because it can be used as a before_save filter in your models instead of having to use the sanitize method in each of your views.

Resources