mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
fix locales with webpack
This commit is contained in:
parent
b760c10414
commit
39682e24e4
10
app/frontend/packs/locale.js.erb
Normal file
10
app/frontend/packs/locale.js.erb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import 'angular-i18n/angular-locale_<%= Rails.application.secrets.angular_locale %>.js';
|
||||||
|
<% if Rails.application.secrets.moment_locale != 'en' %>
|
||||||
|
import 'moment/locale/<%= Rails.application.secrets.moment_locale %>.js';
|
||||||
|
<% end %>
|
||||||
|
<% if Rails.application.secrets.summernote_locale != 'en-US' %>
|
||||||
|
import 'summernote/lang/summernote-<%= Rails.application.secrets.summernote_locale %>.js';
|
||||||
|
<% end %>
|
||||||
|
<% if Rails.application.secrets.fullcalendar_locale != 'en' %>
|
||||||
|
import 'fullcalendar/dist/lang/<%= Rails.application.secrets.fullcalendar_locale %>.js';
|
||||||
|
<% end %>
|
@ -95,18 +95,6 @@ module ApplicationHelper
|
|||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
|
||||||
# check if the provided asset file is available
|
|
||||||
# @see https://github.com/rails/sprockets-rails/issues/298
|
|
||||||
#
|
|
||||||
def asset_available?(logical_path)
|
|
||||||
if Rails.configuration.assets.compile
|
|
||||||
Rails.application.precompiled_assets.include? logical_path
|
|
||||||
else
|
|
||||||
Rails.application.assets_manifest.assets[logical_path].present?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
## inspired by gems/actionview-4.2.5/lib/action_view/helpers/translation_helper.rb
|
## inspired by gems/actionview-4.2.5/lib/action_view/helpers/translation_helper.rb
|
||||||
|
@ -122,32 +122,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= javascript_packs_with_chunks_tag 'application' %>
|
<%= javascript_packs_with_chunks_tag 'application' %>
|
||||||
|
<%= javascript_packs_with_chunks_tag 'locale' %>
|
||||||
<!-- i18n of external libraries -->
|
|
||||||
<script type="text/javascript" src="angular-i18n/angular-locale_#{Rails.application.secrets.angular_locale}.js"></script>
|
|
||||||
<!-- if required locale does not exist, use the default "en" -->
|
|
||||||
<% if asset_available?("moment/locale/#{Rails.application.secrets.moment_locale}.js") %>
|
|
||||||
<script type="text/javascript" src="moment/locale/#{Rails.application.secrets.moment_locale}.js"></script>
|
|
||||||
<%
|
|
||||||
elsif Rails.application.secrets.moment_locale != 'en'
|
|
||||||
raise LoadError, "moment/locale/#{Rails.application.secrets.moment_locale}.js does not exists"
|
|
||||||
end
|
|
||||||
%>
|
|
||||||
<!-- if required locale does not exist, use the default "en-US" -->
|
|
||||||
<% if asset_available?("summernote/lang/summernote-#{Rails.application.secrets.summernote_locale}.js") %>
|
|
||||||
<script type="text/javascript" src="summernote/lang/summernote-#{Rails.application.secrets.summernote_locale}.js"></script>
|
|
||||||
<%
|
|
||||||
elsif Rails.application.secrets.summernote_locale != 'en-US'
|
|
||||||
raise LoadError, "summernote/lang/summernote-#{Rails.application.secrets.summernote_locale}.js does not exists"
|
|
||||||
end
|
|
||||||
%>
|
|
||||||
<!-- if required locale does not exist, use the default "en" -->
|
|
||||||
<% if asset_available?("fullcalendar/dist/lang/#{Rails.application.secrets.fullcalendar_locale}.js") %>
|
|
||||||
<script type="text/javascript" src="fullcalendar/dist/lang/#{Rails.application.secrets.fullcalendar_locale}.js"></script>
|
|
||||||
<%
|
|
||||||
elsif Rails.application.secrets.fullcalendar_locale != 'en'
|
|
||||||
raise LoadError, "fullcalendar/dist/lang/#{Rails.application.secrets.fullcalendar_locale}.js does not exists"
|
|
||||||
end
|
|
||||||
%>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module.exports = function(api) {
|
module.exports = function (api) {
|
||||||
var validEnv = ['development', 'test', 'production']
|
var validEnv = ['development', 'test', 'production'];
|
||||||
var currentEnv = api.env()
|
var currentEnv = api.env();
|
||||||
var isDevelopmentEnv = api.env('development')
|
var isDevelopmentEnv = api.env('development');
|
||||||
var isProductionEnv = api.env('production')
|
var isProductionEnv = api.env('production');
|
||||||
var isTestEnv = api.env('test')
|
var isTestEnv = api.env('test');
|
||||||
|
|
||||||
if (!validEnv.includes(currentEnv)) {
|
if (!validEnv.includes(currentEnv)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -12,7 +12,7 @@ module.exports = function(api) {
|
|||||||
'"test", and "production". Instead, received: ' +
|
'"test", and "production". Instead, received: ' +
|
||||||
JSON.stringify(currentEnv) +
|
JSON.stringify(currentEnv) +
|
||||||
'.'
|
'.'
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -66,5 +66,5 @@ module.exports = function(api) {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
].filter(Boolean)
|
].filter(Boolean)
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user