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
tmp/**/*
config/*.yml
config/app_config.yml
config/database.yml
config/initializers/secret_token.rb
db/*.sqlite3
nbproject/
@ -16,4 +17,4 @@ doc/app/
Capfile
config/deploy.rb
config/deploy/*
.localeapp
.localeapp

View file

@ -19,7 +19,7 @@ end
gem 'jquery-rails'
gem 'select2-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 'prawn'

View file

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

View file

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

View file

@ -7,9 +7,6 @@
var modified = false // indicates if anything has been clicked on this page
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 toleranceIsCostly = true; // default tolerance behaviour
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 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) {
toleranceIsCostly = value;
}
@ -124,7 +115,7 @@ function update(item, quantity, tolerance) {
} else {
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
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();
}
function asMoney(amount) {
return String(amount.toFixed(currencyPrecision)).replace(/\./, currencySeparator) + ' ' + currencyUnit;
}
function calcUnits(unitSize, quantity, tolerance) {
var units = Math.floor(quantity / unitSize)
var remainder = quantity % unitSize
@ -158,10 +145,10 @@ function updateBalance() {
for (i in itemTotal) {
total += itemTotal[i];
}
$('#total_price').html(asMoney(total));
$('#total_price').html(I18n.l("currency", total));
var balance = groupBalance - total;
$('#new_balance').html(asMoney(balance));
$('#total_balance').val(asMoney(balance));
$('#new_balance').html(I18n.l("currency", balance));
$('#total_balance').val(I18n.l("currency", balance));
// determine bgcolor and submit button state according to balance
var bgcolor = '';
if (balance < minimumBalance) {

View file

@ -3,7 +3,6 @@
$(function() {
#{data_to_js(@ordering_data)}
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});
setToleranceBehaviour(#{FoodsoftConfig[:tolerance_is_costly]});
setStockit(#{@order.stockit?});

View file

@ -22,7 +22,9 @@
Javascripts
\==================================================
/ 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
I18n.defaultLocale = "#{I18n.default_locale}";
I18n.locale = "#{I18n.locale}";
I18n.fallbacks = true;
= yield(:javascript)

View file

@ -35,6 +35,9 @@ Foodsoft::Application.configure do
# Expands the lines which load the assets
config.assets.debug = true
# Required for i18n-js
config.assets.initialize_on_precompile = true
# Configure hostname for action mailer
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
config.action_mailer.delivery_method = :smtp
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.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
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.*']