use i18n-js

This commit is contained in:
wvengen 2013-10-04 14:53:22 +02:00
parent a9dff7f1df
commit 64a597c689
10 changed files with 33 additions and 24 deletions

5
.gitignore vendored
View file

@ -1,6 +1,7 @@
log/*.log log/*.log
tmp/**/* tmp/**/*
config/*.yml config/app_config.yml
config/database.yml
config/initializers/secret_token.rb config/initializers/secret_token.rb
db/*.sqlite3 db/*.sqlite3
nbproject/ nbproject/
@ -16,4 +17,4 @@ doc/app/
Capfile Capfile
config/deploy.rb config/deploy.rb
config/deploy/* config/deploy/*
.localeapp .localeapp

View file

@ -19,7 +19,7 @@ end
gem 'jquery-rails' gem 'jquery-rails'
gem 'select2-rails' gem 'select2-rails'
gem 'bootstrap-datepicker-rails' gem 'bootstrap-datepicker-rails'
gem 'i18n-js', git: 'git://github.com/fnando/i18n-js.git' # to avoid US-ASCII js.erb error
gem 'mysql2' gem 'mysql2'
gem 'prawn' gem 'prawn'

View file

@ -4,6 +4,13 @@ GIT
specs: specs:
localize_input (0.1.0) localize_input (0.1.0)
GIT
remote: git://github.com/fnando/i18n-js.git
revision: eab4137f83777963f0ebe6960704a7f64fd8911d
specs:
i18n-js (2.1.2)
i18n
GIT GIT
remote: git://github.com/technoweenie/acts_as_versioned.git remote: git://github.com/technoweenie/acts_as_versioned.git
revision: 63b1fc8529d028fae632fe80ec0cb25df56cd76b revision: 63b1fc8529d028fae632fe80ec0cb25df56cd76b
@ -321,6 +328,7 @@ DEPENDENCIES
factory_girl_rails (~> 4.0) factory_girl_rails (~> 4.0)
faker faker
haml-rails haml-rails
i18n-js!
i18n-spec i18n-spec
inherited_resources inherited_resources
jquery-rails jquery-rails

View file

@ -9,6 +9,8 @@
//= require bootstrap-datepicker/locales/bootstrap-datepicker.nl //= require bootstrap-datepicker/locales/bootstrap-datepicker.nl
//= require jquery.observe_field //= require jquery.observe_field
//= require rails.validations //= require rails.validations
//= require i18n
//= require i18n/translations
//= require_self //= require_self
//= require ordering //= require ordering
//= require stupidtable //= require stupidtable

View file

@ -7,9 +7,6 @@
var modified = false // indicates if anything has been clicked on this page var modified = false // indicates if anything has been clicked on this page
var groupBalance = 0; // available group money var groupBalance = 0; // available group money
var currencySeparator = "."; // default decimal separator
var currencyPrecision = 2; // default digits behind comma
var currencyUnit = "€"; // default currency
var minimumBalance = 0; // minimum group balance for the order to be succesful var minimumBalance = 0; // minimum group balance for the order to be succesful
var toleranceIsCostly = true; // default tolerance behaviour var toleranceIsCostly = true; // default tolerance behaviour
var isStockit = false; // Wheter the order is from stock oder normal supplier var isStockit = false; // Wheter the order is from stock oder normal supplier
@ -23,12 +20,6 @@ var toleranceOthers = new Array();
var itemsAllocated = new Array(); // how many items the group has been allocated and should definitely get var itemsAllocated = new Array(); // how many items the group has been allocated and should definitely get
var quantityAvailable = new Array(); // stock_order. how many items are currently in stock var quantityAvailable = new Array(); // stock_order. how many items are currently in stock
function setCurrencyFormat(separator, precision, unit) {
currencySeparator = separator;
currencyPrecision = precision;
currencyUnit = unit;
}
function setToleranceBehaviour(value) { function setToleranceBehaviour(value) {
toleranceIsCostly = value; toleranceIsCostly = value;
} }
@ -124,7 +115,7 @@ function update(item, quantity, tolerance) {
} else { } else {
itemTotal[item] = price[item] * (Number(quantity)); itemTotal[item] = price[item] * (Number(quantity));
} }
$('#price_' + item + '_display').html(asMoney(itemTotal[item])); $('#price_' + item + '_display').html(I18n.l("currency", itemTotal[item]));
// update missing units // update missing units
var missing_units = unit[item] - (((quantityOthers[item] + Number(quantity)) % unit[item]) + Number(tolerance) + toleranceOthers[item]) var missing_units = unit[item] - (((quantityOthers[item] + Number(quantity)) % unit[item]) + Number(tolerance) + toleranceOthers[item])
@ -137,10 +128,6 @@ function update(item, quantity, tolerance) {
updateBalance(); updateBalance();
} }
function asMoney(amount) {
return String(amount.toFixed(currencyPrecision)).replace(/\./, currencySeparator) + ' ' + currencyUnit;
}
function calcUnits(unitSize, quantity, tolerance) { function calcUnits(unitSize, quantity, tolerance) {
var units = Math.floor(quantity / unitSize) var units = Math.floor(quantity / unitSize)
var remainder = quantity % unitSize var remainder = quantity % unitSize
@ -158,10 +145,10 @@ function updateBalance() {
for (i in itemTotal) { for (i in itemTotal) {
total += itemTotal[i]; total += itemTotal[i];
} }
$('#total_price').html(asMoney(total)); $('#total_price').html(I18n.l("currency", total));
var balance = groupBalance - total; var balance = groupBalance - total;
$('#new_balance').html(asMoney(balance)); $('#new_balance').html(I18n.l("currency", balance));
$('#total_balance').val(asMoney(balance)); $('#total_balance').val(I18n.l("currency", balance));
// determine bgcolor and submit button state according to balance // determine bgcolor and submit button state according to balance
var bgcolor = ''; var bgcolor = '';
if (balance < minimumBalance) { if (balance < minimumBalance) {

View file

@ -3,7 +3,6 @@
$(function() { $(function() {
#{data_to_js(@ordering_data)} #{data_to_js(@ordering_data)}
setGroupBalance(#{@ordering_data[:available_funds]}); setGroupBalance(#{@ordering_data[:available_funds]});
setCurrencyFormat("#{t('number.currency.format.separator')}", #{t('number.currency.format.precision')}, "#{t('number.currency.format.unit')}");
setMinimumBalance(#{FoodsoftConfig[:minimum_balance] or 0}); setMinimumBalance(#{FoodsoftConfig[:minimum_balance] or 0});
setToleranceBehaviour(#{FoodsoftConfig[:tolerance_is_costly]}); setToleranceBehaviour(#{FoodsoftConfig[:tolerance_is_costly]});
setStockit(#{@order.stockit?}); setStockit(#{@order.stockit?});

View file

@ -22,7 +22,9 @@
Javascripts Javascripts
\================================================== \==================================================
/ Placed at the end of the document so the pages load faster / Placed at the end of the document so the pages load faster
:javascript
I18n = {locale: '#{j(I18n.locale.to_s)}'}
= javascript_include_tag "application" = javascript_include_tag "application"
:javascript
I18n.defaultLocale = "#{I18n.default_locale}";
I18n.locale = "#{I18n.locale}";
I18n.fallbacks = true;
= yield(:javascript) = yield(:javascript)

View file

@ -35,6 +35,9 @@ Foodsoft::Application.configure do
# Expands the lines which load the assets # Expands the lines which load the assets
config.assets.debug = true config.assets.debug = true
# Required for i18n-js
config.assets.initialize_on_precompile = true
# Configure hostname for action mailer # Configure hostname for action mailer
config.action_mailer.default_url_options = { host: 'localhost:3000' } config.action_mailer.default_url_options = { host: 'localhost:3000' }
@ -42,4 +45,4 @@ Foodsoft::Application.configure do
# Mailcatcher can be installed by gem install mailcatcher # Mailcatcher can be installed by gem install mailcatcher
config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 } config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
end end

View file

@ -11,6 +11,9 @@ Foodsoft::Application.configure do
config.serve_static_assets = true config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600" config.static_cache_control = "public, max-age=3600"
# Required for i18n-js
config.assets.initialize_on_precompile = true
# Log error messages when you accidentally call methods on nil # Log error messages when you accidentally call methods on nil
config.whiny_nils = true config.whiny_nils = true

4
config/i18n-js.yml Normal file
View file

@ -0,0 +1,4 @@
# only serve selected strings for i18n-js to keep filesize down
translations:
- file: 'app/assets/javascripts/i18n/translations.js'
only: ['*.js.*', '*.number.*', '*.date.formats.*']