user2490003
user2490003

Reputation: 11890

What's the best way to scale i18n translations in an enterprise software model?

Let's say I have a really simple rails app that runs on one 1 app server and supports one language (en_US).

The i18n gem works great and provides all translations as read from my en.yml file. Woohoo.

But let's say I scale my app and it now supports the following -

I'm now supporting multiple instances of the app, each with several *.yml files that are starting to pile up. Plus, the app is getting more complex so each YML file is getting huge because there are a lot of translations.

Is there a clean way to move these YML files and i18n translations out of the core app? I'm envisioning an HTTP that functions as an "i18n service". Every time an app starts up it queries the i18n service and gets all the translations it needs for particular locale.

Is this a scalable way to approach this? Anyone have any experience in using a different design pattern?

Thanks!

Upvotes: 2

Views: 320

Answers (1)

dimakura
dimakura

Reputation: 7655

You can break one large yml file into several ones, and even distribute files in subdirectories.

For instance your localization tree might look like this:

locales/
  models/
    user_en.yml
    user_jp.yml
    product_en.yml
    product_jp.yml
  pages/
    index_en.yml
    index_jp.yml
  en.yml
  jp.yml

To include all yml files from this tree, modify you application.rb accordingly:

 config.i18n.load_path += Dir[File.join(Rails.root, 'config', 'locales', '**', '*.{rb,yml}')]

Upvotes: 2

Related Questions