start moving from simple_form i18n to activerecord

This commit is contained in:
wvengen 2013-10-03 16:03:13 +02:00
parent 1674dcf851
commit bbcad49831
8 changed files with 81 additions and 71 deletions

View File

@ -73,6 +73,20 @@ module ApplicationHelper
link_to(text, url_for(url_options), html_options) link_to(text, url_for(url_options), html_options)
end end
# Generates text for table heading for model attribute
# When the 'short' option is true, abbreviations will be used:
# When there is a non-empty model attribute 'foo', it looks for
# the model attribute translation 'foo_short' and use that as
# heading, with an acronym title of 'foo'.
def heading_helper(model, attribute, options = {})
s = model.human_attribute_name(attribute)
if options[:short]
sshort = model.human_attribute_name("#{attribute}_short".to_sym, default: '')
s = raw "<acronym title='#{s}'>#{sshort}</acronym>" unless sshort.empty?
end
s
end
# Generates a link to the top of the website # Generates a link to the top of the website
def link_to_top def link_to_top

View File

@ -5,8 +5,8 @@
%table.table.table-striped %table.table.table-striped
%thead %thead
%tr %tr
%th= t('simple_form.labels.article_category.name') %th= heading_helper ArticleCategory, :article_category
%th= t('simple_form.labels.article_category.description') %th= heading_helper ArticleCategory, :description
%th %th
%tbody %tbody
- @article_categories.each do |article_category| - @article_categories.each do |article_category|

View File

@ -6,16 +6,15 @@
%thead %thead
%tr %tr
%th %th
%th= sort_link_helper t('simple_form.labels.article.name'), "name" %th= sort_link_helper heading_helper(Article, :name), "name"
%th %th
%th= sort_link_helper t('simple_form.labels.article.article_category'), "category" %th= sort_link_helper heading_helper(Article, :category), "category"
%th= sort_link_helper t('simple_form.labels.article.unit'), "unit" %th= sort_link_helper heading_helper(Article, :unit), "unit"
%th= sort_link_helper t('simple_form.labels.article.note'), "note" %th= sort_link_helper heading_helper(Article, :note), "note"
%th{:style => "width: 4em;"} %th{:style => "width: 4em;"}= heading_helper Article, :unit_quantity, short: true
%acronym{:title => t('.unit_quantity_desc')}= t '.unit_quantity_short' %th{:style => "width: 5em;"}= heading_helper Article, :price
%th{:style => "width: 5em;"}= t '.price_netto' %th{:style => "width: 3.5em;"}= heading_helper Article, :tax
%th{:style => "width: 3.5em;"}= t 'simple_form.labels.defaults.tax' %th{:style => "width: 4em;"}= heading_helper Article, :deposit
%th{:style => "width: 4em;"}= t 'simple_form.labels.defaults.deposit'
%th{:style => "width: 3em;"} %th{:style => "width: 3em;"}
%tbody#listbody %tbody#listbody

View File

@ -1,20 +1,16 @@
%table.table %table.table
%thead %thead
%tr %tr
%th %th= heading_helper Article, :availability, short: true
%acronym{:title => t('.available_desc')}= t '.available_short' %th= heading_helper Article, :name
%th= t 'simple_form.labels.article.name' %th= heading_helper Article, :unit
%th= t 'simple_form.labels.article.unit' %th= heading_helper Article, :price, short: true
%th %th= heading_helper Article, :unit_quantity, short: true
%acronym{:title => t('.price_desc')}= t '.price_short' %th= heading_helper Article, :order_number, short: true
%th %th= heading_helper Article, :note
%acronym{:title => t('.unit_quantity_desc')}= t '.unit_quantity_short' %th= heading_helper Article, :article_category
%th %th= heading_helper Article, :tax
%acronym{:title => t('.order_number_desc')}= t '.order_number_short' %th= heading_helper Article, :deposit
%th= t 'simple_form.labels.article.note'
%th= t 'simple_form.labels.article.article_category'
%th= t 'simple_form.labels.defaults.tax'
%th= t 'simple_form.labels.defaults.deposit'
%tbody %tbody
- @articles.each_with_index do |article, index| - @articles.each_with_index do |article, index|
= fields_for "articles[#{article.id || index}]", article do |form| = fields_for "articles[#{article.id || index}]", article do |form|

View File

@ -5,13 +5,13 @@
%table.table.table-striped %table.table.table-striped
%thead %thead
%tr %tr
%th= t 'simple_form.labels.article.name' %th= heading_helper Article, :name
%th= t 'simple_form.labels.article.origin' %th= heading_helper Article, :origin
%th= t 'simple_form.labels.article.manufacturer' %th= heading_helper Article, :manufacturer
%th= t 'simple_form.labels.article.note' %th= heading_helper Article, :note
%th{:style => "width:4em"}= t 'simple_form.labels.defaults.price' %th{:style => "width:4em"}= heading_helper Article, :price
%th= t 'simple_form.labels.article.unit' %th= heading_helper Article, :unit
%th= t 'simple_form.labels.defaults.unit_quantity' %th= heading_helper Article, :unit_quantity, short: true
%th %th
%tbody %tbody
- for article in @articles - for article in @articles

View File

@ -24,16 +24,16 @@
%table.table %table.table
%thead %thead
%tr %tr
%th= t 'simple_form.labels.article.name' %th= heading_helper Article, :name
%th= t 'simple_form.labels.article.note' %th= heading_helper Article, :note
%th= t 'simple_form.labels.article.manufacturer' %th= heading_helper Article, :manufacturer
%th= t 'simple_form.labels.article.origin' %th= heading_helper Article, :origin
%th= t 'simple_form.labels.article.unit' %th= heading_helper Article, :unit
%th= t '.unit_quantity_short' %th= heading_helper Article, :unit_quantity, short: true
%th= t '.price_short' %th= heading_helper Article, :price
%th= t 'simple_form.labels.defaults.tax' %th= heading_helper Article, :tax
%th= t 'simple_form.labels.defaults.deposit' %th= heading_helper Article, :deposit
%th= t 'simple_form.labels.article.article_category' %th= heading_helper Article, :article_category
%tbody %tbody
- @updated_articles.each do |updated_article, attrs| - @updated_articles.each do |updated_article, attrs|
- article = Article.find(updated_article.id) - article = Article.find(updated_article.id)

View File

@ -2,19 +2,19 @@
= t('.body').html_safe = t('.body').html_safe
%pre %pre
= [t('.fields.status'), = [t('.fields.status'),
t('simple_form.labels.defaults.order_number'), Article.human_attribute_name(:order_number),
t('simple_form.labels.article.name'), Article.human_attribute_name(:name),
t('simple_form.labels.article.note'), Article.human_attribute_name(:note),
t('simple_form.labels.article.manufacturer'), Article.human_attribute_name(:manufacturer),
t('simple_form.labels.article.origin'), Article.human_attribute_name(:origin),
t('simple_form.labels.article.unit'), Article.human_attribute_name(:unit),
t('simple_form.labels.defaults.price'), Article.human_attribute_name(:price),
t('simple_form.labels.defaults.tax'), Article.human_attribute_name(:tax),
t('simple_form.labels.defaults.deposit'), Article.human_attribute_name(:deposit),
t('simple_form.labels.defaults.unit_quantity'), Article.human_attribute_name(:unit_quantity),
t('.fields.season_amount'), t('.fields.season_amount'),
t('.fields.season_price'), t('.fields.season_price'),
t('simple_form.labels.article.article_category')].join(" | ") Article.human_attribute_name(:article_category)].join(" | ")
= form_for :articles, :url => parse_upload_supplier_articles_path(@supplier), = form_for :articles, :url => parse_upload_supplier_articles_path(@supplier),
:html => { :multipart => true } do |f| :html => { :multipart => true } do |f|

View File

@ -36,16 +36,27 @@ en:
activerecord: activerecord:
attributes: attributes:
article: article:
article_category: article category article_category: Category
availability: Is article available? availability: Is article available?
deposit: deposit availability_short: avail.
fc_price: FC price deposit: Deposit
fc_share: FC share fc_price: FoodCoop price
gross_price: gross price fc_price_short: FC price
price: price fc_share: FoodCoop margin
fc_share_short: FC margin
gross_price: Gross price
manufacturer: Manufacturer
name: Name
note: Note
origin: Origin
price: Price
tax: VAT tax: VAT
unit: unit unit: Unit
unit_quantity: unit quantity unit_quantity: Unit quantity
unit_quantity_short: U.Q.
article_category:
description: Description
name: Name
financial_transaction: financial_transaction:
amount: amount amount: amount
note: note note: note
@ -1559,16 +1570,6 @@ en:
required_users: How many users will be needed in total? required_users: How many users will be needed in total?
tax: In percentage, standard is 7,0 tax: In percentage, standard is 7,0
labels: labels:
article:
article_category: Category
manufacturer: Manufacturer
name: Name
note: Note
origin: Origin
unit: Unit
article_category:
description: Description
name: Name
defaults: defaults:
amount: Amount amount: Amount
date: Date date: Date