I tried to create a Sprocket directive to allow for changes in my configuration files:
in initializers/sprockets.rb
class Sprockets::DirectiveProcessor
def process_depend_on_config_directive(file)
path = File.expand_path(file, "#{Rails.root}/config/locales")
context.depend_on(path)
end
end
AT application.js
Updating the page in the corresponding js file gives me different answers, I have no way to set this behavior:
15:02:03 web.1 | 127.0.0.1 - - [17/Jul/2014 15:02:03] "GET /angular _js/services/better_translate_service-04bd3e149eb227767d3910de31fb2489.js?body=1 HTTP/1.1" 200 23560 0.0105 15:02:05 web.1 | 127.0.0.1 - - [17//2014 15:02:05] "GET /angular _js/services/better_translate_service-04bd3e149eb227767d3910de31fb2489.js?body=1 HTTP/1.1" 200 23564 0.0079 15:02:06 web.1 | 127.0.0.1 - - [17//2014 15:02:06] "GET /angular _js/services/better_translate_service-04bd3e149eb227767d3910de31fb2489.js?body=1 HTTP/1.1" 304 - 0.0061 15:02:06 web.1 | 127.0.0.1 - - [17/Jul/2014 15:02:06] "GET /angular _js/services/better_translate_service-04bd3e149eb227767d3910de31fb2489.js?body=1 HTTP/1.1" 200 23560 0.0091 15:02:07 web.1 | 127.0.0.1 - - [17//2014 15:02:07] "GET /angular _js/services/better_translate_service-04bd3e149eb227767d3910de31fb2489.js?body=1 HTTP/1.1" 200 23564 0.0076 15:02:07 web.1 | 127.0.0.1 - - [17//2014 15:02:07] "GET /angular _js/services/better_translate_service-04bd3e149eb227767d3910de31fb2489.js?body=1 HTTP/1.1" 304 - 0.0093 15:02:08 web.1 | 127.0.0.1 - - [17//2014 15:02:08] "GET /angular _js/services/better_translate_service-04bd3e149eb227767d3910de31fb2489.js?body=1 HTTP/1.1" 200 23560 0.0080 15:02:08 web.1 | 127.0.0.1 - - [17/Jul/2014 15:02:08] "GET /angular _js/services/better_translate_service-04bd3e149eb227767d3910de31fb2489.js?body=1 HTTP/1.1" 200 23564 0.0091 15:02:09 web.1 | 127.0.0.1 - - [17/Jul/2014 15:02:09] "GET /angular _js/services/better_translate_service-04bd3e149eb227767d3910de31fb2489.js?body=1 HTTP/1.1" 304 - 0.0059
: :
Edit2: :
(.erb):
<% environment.context_class.instance_eval { include ApplicationHelper } %>
<%
app.factory('Pg', ['SETTINGS', function(SETTINGS) {
var polyglot = {};
polyglot.translations = {
en: new Polyglot({ phrases: <%= I18n.with_locale(:en) { phrases_for_polyglot.to_json } %>, locale: "en" }),
fr: new Polyglot({ phrases: <%= I18n.with_locale(:fr) { phrases_for_polyglot.to_json } %>, locale: "fr" })
};
polyglot.current = 'en';
polyglot.t = _.memoize(function(key, opts) {
return polyglot.translations[polyglot.current].t(key, opts);
}, function(key, opts){
if(opts===undefined){ return polyglot.current + ''+ key; }
return polyglot.current + '' + key + polyglot.serialize(opts);
});
polyglot.serialize = function(obj) {
var str = [];
for(var p in obj){
if(obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
}
return str.join("&");
};
polyglot.selectLanguage = function(lang){
polyglot.current = lang;
};
return polyglot;
}]);
development.rb:
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.assets.debug = true
config.assets.digest = true
config.assets.configure do |env|
env.cache = ActiveSupport::Cache.lookup_store(:null_store)
end
4.1.1. - ? .
: :
application.js = > application.js.erb
<%= depend_on 'en.yml' %>
<%= depend_on 'fr.yml' %>
<% I18n.backend.send(:init_translations) unless I18n.backend.initialized? %>
console.log(<%= I18n.backend.send(:translations).to_json %>);
application.rb
config.assets.paths < Rails.root.join('config', 'locales')
.rb
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.assets.compile = true
config.serve_static_assets = true
config.assets.debug = false
config.assets.digest = true
config.root_url = 'lvh.me:5000'
config.api_host = 'http://lvh.me:3000'
: js, .
JS:
(anonymous function) MINERR_ASSET:22
(anonymous function) angular.js:3650
q angular.js:303
e angular.js:3616
$b angular.js:3556
Zb.c angular.js:1299
Zb angular.js:1314
Tc angular.js:1263
(anonymous function) angular.js:20555
a angular.js:2342
(anonymous function) angular.js:2613
q angular.js:310
Zc.c angular.js:2612
js :
console.log( ... );
;
2: . , depend_on . .js.erb, . , . , , application.js .:)