Skip to content

Commit

Permalink
Merge pull request #2304 from jhawthorn/faster_js_locale_data2
Browse files Browse the repository at this point in the history
Generate js_locale_data using JSON.dump
  • Loading branch information
jhawthorn authored Oct 19, 2017
2 parents 6b61dc8 + 2f43603 commit dfb77a7
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions backend/app/views/spree/admin/shared/_js_locale_data.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,42 @@
var Spree = {}
}
Spree.translations = <%==
I18n.t("spree").merge({
date_picker: Spree.t(:js_format,
scope: 'date_picker',
default: 'yy/mm/dd'),
abbr_day_names: I18n.t(:abbr_day_names, scope: :date),
destroy: Spree.t(:destroy, scope: :actions),
edit: Spree.t(:edit, scope: :actions),
save: Spree.t(:save, scope: :actions),
cancel: Spree.t(:cancel, scope: :actions),
first_day: Spree.t(:first_day,
scope: 'date_picker',
default: 0).to_i,
item_stock_placeholder: Spree.t(:choose_location),
month_names: I18n.t(:month_names, scope: :date).reject(&:blank?),
currency_separator: I18n.t('number.currency.format.separator'),
currency_delimiter: I18n.t('number.currency.format.delimiter'),
activerecord: I18n.t('activerecord')
}).to_json
JSON.dump(
I18n.t("spree").merge({
date_picker: Spree.t(:js_format,
scope: 'date_picker',
default: 'yy/mm/dd'),
abbr_day_names: I18n.t(:abbr_day_names, scope: :date),
destroy: Spree.t(:destroy, scope: :actions),
edit: Spree.t(:edit, scope: :actions),
save: Spree.t(:save, scope: :actions),
cancel: Spree.t(:cancel, scope: :actions),
first_day: Spree.t(:first_day,
scope: 'date_picker',
default: 0).to_i,
item_stock_placeholder: Spree.t(:choose_location),
month_names: I18n.t(:month_names, scope: :date).reject(&:blank?),
currency_separator: I18n.t('number.currency.format.separator'),
currency_delimiter: I18n.t('number.currency.format.delimiter'),
activerecord: I18n.t('activerecord')
}))
%>;

Spree.currencyInfo = <%==
Money::Currency.all.map { |c|
format =
if c.symbol == "" || c.symbol_first
"%s%v"
else
"%v %s"
end
[c.id.to_s.upcase, [
c.symbol || "¤",
c.exponent,
format
]]
}.to_h.to_json
JSON.dump(
Money::Currency.all.map { |c|
format =
if c.symbol == "" || c.symbol_first
"%s%v"
else
"%v %s"
end
[c.id.to_s.upcase, [
c.symbol || "¤",
c.exponent,
format
]]
}.to_h)
%>;
</script>
<script data-hook='admin-custom-translations'>
Expand Down

0 comments on commit dfb77a7

Please sign in to comment.