first attempt to serve correct localized js files as rails pipeline assets
This commit is contained in:
parent
e363950bf5
commit
acc7718c67
|
@ -1,7 +0,0 @@
|
|||
//= depend_on 'client.en.yml'
|
||||
|
||||
<% SimplesIdeias::I18n.assert_usable_configuration! %>
|
||||
<% admin = SimplesIdeias::I18n.translation_segments['app/assets/javascripts/i18n/admin.en.js']
|
||||
admin[:en][:js] = admin[:en].delete(:admin_js)
|
||||
%>
|
||||
jQuery.extend(true, I18n.translations, <%= admin.to_json %>);
|
|
@ -21,7 +21,10 @@
|
|||
// The rest of the externals
|
||||
//= require_tree ./external
|
||||
//= require i18n
|
||||
//= require discourse/translations
|
||||
|
||||
// The following needs to go right after including i18n, because other scripts
|
||||
// below require correctly set locale already
|
||||
//= require init_locale
|
||||
|
||||
//= require ./discourse/helpers/i18n_helpers
|
||||
//= require ./discourse
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
//= depend_on 'client.en.yml'
|
||||
|
||||
<% SimplesIdeias::I18n.assert_usable_configuration! %>
|
||||
var I18n = I18n || {};
|
||||
I18n.translations = <%= SimplesIdeias::I18n.translation_segments['app/assets/javascripts/i18n/en.js'].to_json %>;
|
|
@ -0,0 +1 @@
|
|||
I18n.locale = window.currentLocale;
|
|
@ -0,0 +1,2 @@
|
|||
//= depend_on 'client.en.yml'
|
||||
<%= JsLocaleHelper.output_locale(:en); %>
|
|
@ -0,0 +1,2 @@
|
|||
//= depend_on 'client.fr.yml'
|
||||
<%= JsLocaleHelper.output_locale(:fr); %>
|
|
@ -0,0 +1,2 @@
|
|||
//= depend_on 'client.nl.yml'
|
||||
<%= JsLocaleHelper.output_locale(:nl); %>
|
|
@ -0,0 +1,2 @@
|
|||
//= depend_on 'client.pseudo.yml'
|
||||
<%= JsLocaleHelper.output_locale(:pseudo); %>
|
|
@ -0,0 +1,21 @@
|
|||
module JsLocaleHelper
|
||||
|
||||
def self.output_locale(locale)
|
||||
|
||||
SimplesIdeias::I18n.assert_usable_configuration!
|
||||
|
||||
s = "var I18n = I18n || {};"
|
||||
segment = "app/assets/javascripts/i18n/#{locale}.js"
|
||||
s += "I18n.translations = " + SimplesIdeias::I18n.translation_segments[segment].to_json + ";"
|
||||
|
||||
segment = "app/assets/javascripts/i18n/admin.#{locale}.js"
|
||||
admin = SimplesIdeias::I18n.translation_segments[segment]
|
||||
admin[locale][:js] = admin[locale].delete(:admin_js)
|
||||
|
||||
s += "jQuery.extend(true, I18n.translations, " + admin.to_json + ");"
|
||||
|
||||
s
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -14,6 +14,13 @@
|
|||
})();
|
||||
</script>
|
||||
|
||||
<%# load the selected locale before any other scripts %>
|
||||
<%= javascript_include_tag "locales/#{I18n.locale}" %>
|
||||
<%# store the locale into a variable, because the scripts need it, see init_locale.js %>
|
||||
<script>
|
||||
window.currentLocale = "<%= I18n.locale %>";
|
||||
</script>
|
||||
|
||||
<%- if mini_profiler_enabled? %>
|
||||
<%- Rack::MiniProfiler.step "application" do %>
|
||||
<%= javascript_include_tag "application" %>
|
||||
|
|
|
@ -25,4 +25,14 @@ translations:
|
|||
- file: 'app/assets/javascripts/i18n/en.js'
|
||||
only: 'en.js.*'
|
||||
- file: 'app/assets/javascripts/i18n/admin.en.js'
|
||||
only: 'en.admin_js.*'
|
||||
only: 'en.admin_js.*'
|
||||
|
||||
- file: 'app/assets/javascripts/i18n/pseudo.js'
|
||||
only: 'pseudo.js.*'
|
||||
- file: 'app/assets/javascripts/i18n/admin.pseudo.js'
|
||||
only: 'pseudo.admin_js.*'
|
||||
|
||||
- file: 'app/assets/javascripts/i18n/fr.js'
|
||||
only: 'fr.js.*'
|
||||
- file: 'app/assets/javascripts/i18n/admin.fr.js'
|
||||
only: 'fr.admin_js.*'
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
// The rest of the externals
|
||||
//= require_tree ../../app/assets/javascripts/external
|
||||
//= require i18n
|
||||
//= require ../../app/assets/javascripts/discourse/translations
|
||||
|
||||
//= require ../../app/assets/javascripts/discourse/helpers/i18n_helpers
|
||||
//= require ../../app/assets/javascripts/discourse
|
||||
|
|
Loading…
Reference in New Issue