ging/social_stream — Issue #199: Text in assets/ gets translated to the default language rather than client's preferred
Author: raquelgb
Created: 2012-01-20 11:24:16+00:00
State: open

@rafaelgg and I noticed this while hunting for non-translating strings in the activities front. This should have been obvious: assets may be precompiled when deploying to production, but even in development they are somehow cached, so rails I18n code should **definitely not** be used in assets. Culprits follow:

```
[arch@myhost ~]$ grep I18n `find . -name *erb | grep assets`
./documents/app/assets/javascripts/documents.js.erb: $(this).attr('id') +"\"); return false;'><%= I18n.t('comment.view_all') %> (" +
./base/app/assets/javascripts/activities.js.erb: $("#masterSubmitButton").val("<%= I18n.t('activity.sending') %>...").attr("disabled", true);
./base/app/assets/javascripts/activities.js.erb: $(this).val("<%= I18n.t('activity.sending') %>...").attr("disabled", true);
./base/app/assets/javascripts/activities.js.erb: $(".submitActivity").val("<%= I18n.t('share') %>").removeAttr("disabled");
./base/app/assets/javascripts/activities.js.erb: $("#masterSubmitButton").val("<%= I18n.t('share') %>").removeAttr("disabled");
./base/app/assets/javascripts/activities.js.erb: $(this).attr('id') +"\"); return false;'><%= I18n.t('comment.view_all') %> (" +
./presence/app/assets/javascripts/chat_interface_manager.js.erb:$("#chat_header_title").html('<%=I18n.t('chat.disconnected')%>')
./presence/app/assets/javascripts/chat_interface_manager.js.erb:$("#chat_header_title").html('<%=I18n.t('chat.connecting')%>')
./presence/app/assets/javascripts/chat_interface_manager.js.erb: var defaultTitle = '<%=I18n.t('chat.status.choose')%>'
./presence/app/assets/javascripts/chat_interface_manager.js.erb:var msg = '<%=I18n.t('chat.notify.offline')%>';
./presence/app/assets/javascripts/xmpp_client_management.js.erb:$("#chat_header_title").html('<%=I18n.t('chat.reconnecting')%>')
./presence/app/assets/javascripts/xmpp_client_management.js.erb:$("#chat_header_title").html('<%=I18n.t('chat.unableconnect')%>')
./linkser/app/assets/javascripts/linkser.js.erb: $("#link_preview").html($('

').addClass('loading').html("<%= I18n.t('link.errors.loading') %> " + url));
```

These text will appear in whatever your `I18n.default_locale` is; keep in mind that you should `rake assets:clean` and restart your app if changing the locale default.

There are really a few alternatives to work this out, at least in the activities front:

* Using [I18n-js](https://github.com/fnando/i18n-js) may be the simplest one, but it pulls yet another dependency to social_stream.
* Separating the text to translate to a view is probably the right thing to do, but they are such small strings it seems a bit overfetched.
* Hiding the translated info inside the page, then have the JS display it or copy their content over; it does not scale nice and, but then again there are not too many cases.

What do you guys think?