Translating entries in the database rails - ruby-on-rails

In our application users can create a set of categories. Those categories each contain products. On the website customers can then see the categories - currently only in one language.
We would like to add translations so that the customers can view the data in different languages. This would mean that the the user has to be able to add translations to the actual data.
Based on this question: Rails I18n via database column I should add a couple of database columns for each locale.
Has anyone solved a similar problem?

I have used globalize3 numerous times and always liked it. Maybe it can help you too.

I had something similar kind of requirement where this episode helped me . I was not changing the language but i wanted to externalize some of the currency parameters as the currency per country changes. Here is my sample application code

Related

Rails I18n overlay for user

We're using Rails with I18n for a web application running for users in multiple countries. To handle different languages we're setting the locale based on the TLD. Now, we have an important customer in one country that requires custom translations. To handle this, we would like to overlay a few translations for that specific customer.
Right now we're loading the locales as usual, but also add a folder to the I18n.load_path if the session belongs to the specific customer and then run I18n.backend.reload!. This works well, and we only have to add the keys that needs custom translations for the customer in question. What's less great is that this changes the translations for everybody using the same language.
What's the recommended way to do this in Rails?
I sorted this out by adding a custom locale for which I added a fallback to the language in question. Works well.

Data model and storage for Rails app

At the moment ’m building a web app using Ruby on Rails. I try to get my head around the data model and database part. To make it easy to understand I’ll use IFTTT as an analogy:
In the app, the user can add different recipes, for example:
Facebook — Twitter
Weather — Send email
You name it...
Of course every recipe has its own fields and options. So the user can choose multiple recipes from the library and set options to every recipe. The library of recipes is defined in code.
I have a few questions regarding this setup and would be happy if I could get some directions:
Is it smart to serialize the options of a recipe into a single database field? Every recipe has different fields and I don‘t want a database table for every recipe type.
Or is it better to create a ‘key-value’ table with all the options of all the recipes?
How to handle validation? Can Virtus come in handy?
Is a NoSQL database a good fit for these kinds of applications?
Are there best practices for these kinds of applications/data models? Any help is welcome.
Thanks!
Rens
Not sure if SO is the best place for really general questions like this but I'll take a swing
1 && 2) Personally I'd give the recipe table an action_taken field, probably as a string, and fields for all the available, resulting actions as booleans. Then the only thing you really need to be careful of is making sure the action_taken field remains uniform
3) ActiveRecord has a pretty fleshed out validation suite built in. You can validate based on presence, uniqueness, inclusion in a set of elements, etc. You can also extra validations on the database if you feel like being extra safe
4) I would use PostgreSQL, seems to be the community standard so probably the easiest to get support with if you need it
Hope this helps

Rails: database-handling for an international ecommerce app

Edited
The question in short:
Is there a way (a gem?) in Rails to bind two databases of same schemes to an app, where Rails decides which db to use on top level domain?
For example: if user entered example.de the data on site loads from a db called de_example_production and if it's example.com then the data is loaded from us_example_production.
Details (old question):
I have an ecommerce Rails app that has been developed for some particular country. Now I am trying to extend it to another country.
The main requirement is that it should be the same app running on the same server (so that code updates apply to all countries), but since the countries have different data - cities, stores, products - I want to them to be on separate databases. What's the best way to achieve this?
As an alternative, I thought of continuing with the current database by adding a country model on top of the hierarchy of models that I already have, but it seems to me this approach will add a lot of complexity and redundancy to the system.
Can you please help me out?
As Thomas pointed out, the paradigm I was looking for is called multitenancy. I decided to proceed with the Apartment gem as it perfectly suited my requirements.
These pro railscasts helped me in my implementation:
Multitenancy with Scopes
and Multitenancy with PostgreSQL.

How to localize existing content in Rails 3?

I have set up a simple Rails app based on Post, Comment example from the default documentation. -> http://edgeguides.rubyonrails.org/getting_started.html
What would be the appropriate way of localizing existing content from these Posts ?
If I assume that Post has a :title and "content, and I would like this content to be entered not only in English, but also in German and Dutch, then how would I achieve this if I want the end result to look similar to this :
http://0.0.0.0:3000/en/posts.json to get all posts in English and respectively,
http://0.0.0.0:3000/de/posts.json for German?
I havent found a gem yet, that would support such multilangual content.
I have seen doe, many existing ways to do so, mostly in applications like Wordpress or Drupal, which are not rails based.
I guess the preferred way would be either storing EN and DE posts in seperate tables (but then how to add new languages?), or to place all translations within the same database table, but seperate translations in a different way, but how to get them easily out in json in the right language?
I am really confused and puzzled why such a "common" problem, is not solved in Rails by default, or maybe I am simply looking in the wrong place.
Globalize3 will do what you want to do. It stores all translations for a particular model in a separate table, with a locale column identifying what the language of a particular translation is. This makes it possible to add new languages without having to migrate the database, so the approach is very scalable.
There are other gems for translating content as well, e.g. Traco is one that I know of, but this one stores the translations in the same table as the model, so when you add new languages you have to migrate each model table. I personally prefer the Globalize3 approach, although it makes the gem itself more complicated internally.

Is it possible to handle text translations for data stored in database tables?

I am using Ruby on Rails 3.1.0 and I would like to know if it is possible to handle text translations for data stored in database tables. Is it possible? If so, how?
For example, if I have a database table column named Title and in that I have a record with the Title value set\stored to "car", I would like to show
the text "automobile" for italian people;
the text "auto" for german people;
and so on...
For user generated content it's best to store the language with the content.
You can then have your users create "copies" of this data with a different language reference.
Depending on how much data you need to change per table a different gems might be suitable for your needs. I18n gem is NOT a good choice here, as it's meant for static content. See: https://www.ruby-toolbox.com/categories/i18n
Ruby can help you translate the words from one language to another, but only by providing hashes and structures or code algorithms that allow you to do lookups. By itself it knows nothing of the meaning of words, and cannot translate words.
For your purpose, you should build a table of translations, with the primary language words in a primary field, and their translations in secondary fields, one field for each language. Then you can quickly look up all the words for a form in German, or Italian, and substitute them into the form.
You can setup your rails application for internationalization using Rails Internationalization (i18n) API. You would need to pass and set the locale. The locale files would reside in config/locales. As mentioned by the tin Man, the locale file is a key:value file. Here you can override custom rails defaults.
Locale can be set from params and also from domain name. The Rails guide is actually the best place to start with in my opinion.
http://guides.rubyonrails.org/i18n.html
As already mentioned in the other answers, you'll want to use the rails i18n functionality to get this to work.
There are however alternative ways of storing your translations. This railscast describes how to set up a redis-based translation backend, as well as links to a whole bunch of different backends.
If you just want to store your translations in a database using ActiveRecord, I'd suggest you have a look at i18n-active_record.
With these plugins you can easily store your translations in the database, and have your application look them up for you using I18n.t('some_translation_key').

Resources