From bbcad49831f9ec7872cc15981261b58e47fc6b37 Mon Sep 17 00:00:00 2001 From: wvengen Date: Thu, 3 Oct 2013 16:03:13 +0200 Subject: [PATCH] start moving from simple_form i18n to activerecord --- app/helpers/application_helper.rb | 14 +++++++ app/views/article_categories/index.html.haml | 4 +- app/views/articles/_articles.html.haml | 17 ++++----- app/views/articles/_edit_all_table.html.haml | 24 +++++------- .../articles/_import_search_results.haml | 14 +++---- app/views/articles/sync.html.haml | 20 +++++----- app/views/articles/upload.html.haml | 22 +++++------ config/locales/en.yml | 37 ++++++++++--------- 8 files changed, 81 insertions(+), 71 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 167a558d..c9caff30 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -73,6 +73,20 @@ module ApplicationHelper link_to(text, url_for(url_options), html_options) 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 "#{sshort}" unless sshort.empty? + end + s + end # Generates a link to the top of the website def link_to_top diff --git a/app/views/article_categories/index.html.haml b/app/views/article_categories/index.html.haml index dc18f042..0ec33119 100644 --- a/app/views/article_categories/index.html.haml +++ b/app/views/article_categories/index.html.haml @@ -5,8 +5,8 @@ %table.table.table-striped %thead %tr - %th= t('simple_form.labels.article_category.name') - %th= t('simple_form.labels.article_category.description') + %th= heading_helper ArticleCategory, :article_category + %th= heading_helper ArticleCategory, :description %th %tbody - @article_categories.each do |article_category| diff --git a/app/views/articles/_articles.html.haml b/app/views/articles/_articles.html.haml index fd00f23d..e8a1c7b1 100644 --- a/app/views/articles/_articles.html.haml +++ b/app/views/articles/_articles.html.haml @@ -6,16 +6,15 @@ %thead %tr %th - %th= sort_link_helper t('simple_form.labels.article.name'), "name" + %th= sort_link_helper heading_helper(Article, :name), "name" %th - %th= sort_link_helper t('simple_form.labels.article.article_category'), "category" - %th= sort_link_helper t('simple_form.labels.article.unit'), "unit" - %th= sort_link_helper t('simple_form.labels.article.note'), "note" - %th{:style => "width: 4em;"} - %acronym{:title => t('.unit_quantity_desc')}= t '.unit_quantity_short' - %th{:style => "width: 5em;"}= t '.price_netto' - %th{:style => "width: 3.5em;"}= t 'simple_form.labels.defaults.tax' - %th{:style => "width: 4em;"}= t 'simple_form.labels.defaults.deposit' + %th= sort_link_helper heading_helper(Article, :category), "category" + %th= sort_link_helper heading_helper(Article, :unit), "unit" + %th= sort_link_helper heading_helper(Article, :note), "note" + %th{:style => "width: 4em;"}= heading_helper Article, :unit_quantity, short: true + %th{:style => "width: 5em;"}= heading_helper Article, :price + %th{:style => "width: 3.5em;"}= heading_helper Article, :tax + %th{:style => "width: 4em;"}= heading_helper Article, :deposit %th{:style => "width: 3em;"} %tbody#listbody diff --git a/app/views/articles/_edit_all_table.html.haml b/app/views/articles/_edit_all_table.html.haml index bd9441f7..e7752792 100644 --- a/app/views/articles/_edit_all_table.html.haml +++ b/app/views/articles/_edit_all_table.html.haml @@ -1,20 +1,16 @@ %table.table %thead %tr - %th - %acronym{:title => t('.available_desc')}= t '.available_short' - %th= t 'simple_form.labels.article.name' - %th= t 'simple_form.labels.article.unit' - %th - %acronym{:title => t('.price_desc')}= t '.price_short' - %th - %acronym{:title => t('.unit_quantity_desc')}= t '.unit_quantity_short' - %th - %acronym{:title => t('.order_number_desc')}= t '.order_number_short' - %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' + %th= heading_helper Article, :availability, short: true + %th= heading_helper Article, :name + %th= heading_helper Article, :unit + %th= heading_helper Article, :price, short: true + %th= heading_helper Article, :unit_quantity, short: true + %th= heading_helper Article, :order_number, short: true + %th= heading_helper Article, :note + %th= heading_helper Article, :article_category + %th= heading_helper Article, :tax + %th= heading_helper Article, :deposit %tbody - @articles.each_with_index do |article, index| = fields_for "articles[#{article.id || index}]", article do |form| diff --git a/app/views/articles/_import_search_results.haml b/app/views/articles/_import_search_results.haml index 6d4c6720..254abca8 100644 --- a/app/views/articles/_import_search_results.haml +++ b/app/views/articles/_import_search_results.haml @@ -5,13 +5,13 @@ %table.table.table-striped %thead %tr - %th= t 'simple_form.labels.article.name' - %th= t 'simple_form.labels.article.origin' - %th= t 'simple_form.labels.article.manufacturer' - %th= t 'simple_form.labels.article.note' - %th{:style => "width:4em"}= t 'simple_form.labels.defaults.price' - %th= t 'simple_form.labels.article.unit' - %th= t 'simple_form.labels.defaults.unit_quantity' + %th= heading_helper Article, :name + %th= heading_helper Article, :origin + %th= heading_helper Article, :manufacturer + %th= heading_helper Article, :note + %th{:style => "width:4em"}= heading_helper Article, :price + %th= heading_helper Article, :unit + %th= heading_helper Article, :unit_quantity, short: true %th %tbody - for article in @articles diff --git a/app/views/articles/sync.html.haml b/app/views/articles/sync.html.haml index 1039aee4..4fe32a3c 100644 --- a/app/views/articles/sync.html.haml +++ b/app/views/articles/sync.html.haml @@ -24,16 +24,16 @@ %table.table %thead %tr - %th= t 'simple_form.labels.article.name' - %th= t 'simple_form.labels.article.note' - %th= t 'simple_form.labels.article.manufacturer' - %th= t 'simple_form.labels.article.origin' - %th= t 'simple_form.labels.article.unit' - %th= t '.unit_quantity_short' - %th= t '.price_short' - %th= t 'simple_form.labels.defaults.tax' - %th= t 'simple_form.labels.defaults.deposit' - %th= t 'simple_form.labels.article.article_category' + %th= heading_helper Article, :name + %th= heading_helper Article, :note + %th= heading_helper Article, :manufacturer + %th= heading_helper Article, :origin + %th= heading_helper Article, :unit + %th= heading_helper Article, :unit_quantity, short: true + %th= heading_helper Article, :price + %th= heading_helper Article, :tax + %th= heading_helper Article, :deposit + %th= heading_helper Article, :article_category %tbody - @updated_articles.each do |updated_article, attrs| - article = Article.find(updated_article.id) diff --git a/app/views/articles/upload.html.haml b/app/views/articles/upload.html.haml index 7cb5f4fb..6a8b4d50 100644 --- a/app/views/articles/upload.html.haml +++ b/app/views/articles/upload.html.haml @@ -2,19 +2,19 @@ = t('.body').html_safe %pre = [t('.fields.status'), - t('simple_form.labels.defaults.order_number'), - t('simple_form.labels.article.name'), - t('simple_form.labels.article.note'), - t('simple_form.labels.article.manufacturer'), - t('simple_form.labels.article.origin'), - t('simple_form.labels.article.unit'), - t('simple_form.labels.defaults.price'), - t('simple_form.labels.defaults.tax'), - t('simple_form.labels.defaults.deposit'), - t('simple_form.labels.defaults.unit_quantity'), + Article.human_attribute_name(:order_number), + Article.human_attribute_name(:name), + Article.human_attribute_name(:note), + Article.human_attribute_name(:manufacturer), + Article.human_attribute_name(:origin), + Article.human_attribute_name(:unit), + Article.human_attribute_name(:price), + Article.human_attribute_name(:tax), + Article.human_attribute_name(:deposit), + Article.human_attribute_name(:unit_quantity), t('.fields.season_amount'), 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), :html => { :multipart => true } do |f| diff --git a/config/locales/en.yml b/config/locales/en.yml index 915f4341..790df83e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -36,16 +36,27 @@ en: activerecord: attributes: article: - article_category: article category + article_category: Category availability: Is article available? - deposit: deposit - fc_price: FC price - fc_share: FC share - gross_price: gross price - price: price + availability_short: avail. + deposit: Deposit + fc_price: FoodCoop price + fc_price_short: FC 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 - unit: unit - unit_quantity: unit quantity + unit: Unit + unit_quantity: Unit quantity + unit_quantity_short: U.Q. + article_category: + description: Description + name: Name financial_transaction: amount: amount note: note @@ -1559,16 +1570,6 @@ en: required_users: How many users will be needed in total? tax: In percentage, standard is 7,0 labels: - article: - article_category: Category - manufacturer: Manufacturer - name: Name - note: Note - origin: Origin - unit: Unit - article_category: - description: Description - name: Name defaults: amount: Amount date: Date