All threads / [I18n] How do I translate database content ?

Ask A Question


You’re not receiving notifications from this thread.

[I18n] How do I translate database content ?

Nino asked in Databases
I have translated my static content with I18n, but I need to translate some strings/texts stored in my database.

For a more practical approach I have this scheme and I want to serve a localized `description`
create_table "locations", force: :cascade do |t|
    t.string "name"
    t.string "address"
    t.text "description"

How do I do this ? I don't find (or understand) solutions with I18n's documentation.

You could go and try to JSONB for this. `t.text :description \ t.jsonb :description_translations, null: false, default: '{}'` 

On top of my head not sure about much data it can hold, but this is the approach I took the localise names for locations once.

Not sure, let's say the description attr is "blah blah blah" stored in a DB and you could do in your views:
<%= t @location.description.split.first %>
blah: "anything"
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.