first attempt to serve correct localized js files as rails pipeline assets

This commit is contained in:
Kuba Brecka 2013-02-27 09:00:49 +01:00
parent e363950bf5
commit acc7718c67
12 changed files with 52 additions and 15 deletions

View File

@ -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 %>);

View File

@ -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

View File

@ -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 %>;

View File

@ -0,0 +1 @@
I18n.locale = window.currentLocale;

View File

@ -0,0 +1,2 @@
//= depend_on 'client.en.yml'
<%= JsLocaleHelper.output_locale(:en); %>

View File

@ -0,0 +1,2 @@
//= depend_on 'client.fr.yml'
<%= JsLocaleHelper.output_locale(:fr); %>

View File

@ -0,0 +1,2 @@
//= depend_on 'client.nl.yml'
<%= JsLocaleHelper.output_locale(:nl); %>

View File

@ -0,0 +1,2 @@
//= depend_on 'client.pseudo.yml'
<%= JsLocaleHelper.output_locale(:pseudo); %>

View File

@ -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

View File

@ -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" %>

View File

@ -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.*'

View File

@ -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