Why locales are not in assets?

Why in a standard rails application locales are in config directory
and not in assets?

How are these files assets? They’re not served to the end user, but are rather used by the backend to display information in different languages to the end-user, thereby making them configuration.

This sounds like it could be more of a feature request than a complaint.

Compiling yaml files for translation (Or whatever store) down to maybe json for use might lend towards the more pro client-side views crowd. I haven’t even thought out the implications of such a thing, but it might be really cool to do that.


That’s quite an interesting twist on it. I never thought of doing it that way, but now it would make sense to be able to have these made available to client-side applications which can then use them to translate… but what are the translation libraries like on the client-side these days?

This library does exactly what you’re talking about here: https://github.com/fnando/i18n-js

It’s a small library to provide the I18n translations on the Javascript. It comes with Rails support.

It is for sure worth to take a look.

Maybe this was a stupid question and i do not understand what assets exactly are. For me assets were things which are not Ruby code or user data, but on which the developer spends a lot of time.

Assets are things that are embedded in a web page and get downloaded by the browser. This includes images (JPGs, PNGs), javascript files, CSS files, flash movies, mp3s, etc. Since locales are used only by the server and not downloaded by the browser, they are server configuration, not assets.

Josh, thanks for the explanation. However, i may argue that one can keep SCSS or CoffeeScript in assets, and those are not downloaded, only generated CSS and JavaScript are. YAML files of localizations are not downloaded, but the localized strings for the current page are.

You’re right that they’re not downloadable. They’re still used in the process of generating assets that are downloadable. The ones that are downloadable live in public/assets anyway.

I give up about calling them assets, but maybe locales can be at least in app/ directory?

You can put it inside the app directory too. Both are loaded.

You can put them anywhere you want. If you want to put them in assets, just add

config.i18n.load_path += Dir[Rails.root.join(‘assets’, ‘locales’, ‘*.{rb,yml}’).to_s]

to your config/application.rb file.

I would advise against doing this though. As a developer, I expect to find locales in config/locales. If things aren’t in their correct places, I tend to mildly freak out.