From 989363f74346b69d8fb9ba797ba488fdc750d402 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 12 Feb 2013 11:45:54 -0600 Subject: [PATCH] better i18n for contributed description --- app/helpers/contribution_helper.rb | 51 ++++++++++++++---------------- app/models/pet_type.rb | 3 +- config/locales/en-MEEP.yml | 14 +++++--- config/locales/en.yml | 14 +++++--- config/locales/es.yml | 13 +++++--- config/locales/pt.yml | 13 +++++--- 6 files changed, 64 insertions(+), 44 deletions(-) diff --git a/app/helpers/contribution_helper.rb b/app/helpers/contribution_helper.rb index a59afd06..d4baa595 100644 --- a/app/helpers/contribution_helper.rb +++ b/app/helpers/contribution_helper.rb @@ -1,43 +1,40 @@ module ContributionHelper - def contributed_description(contributed, image = true) + def contributed_description(contributed, show_image = true) case contributed when Item - suffix = translate_contributed_description('item_suffix') - contributed_item(contributed, image, suffix) + contributed_item('item', contributed, show_image) when SwfAsset - suffix = translate_contributed_description('swf_asset_suffix') - contributed_item(contributed.item, image, suffix) + contributed_item('swf_asset', contributed.item, show_image) when PetType - suffix = translate_contributed_description('pet_type_suffix') - contributed_pet_type(contributed, image, :after => suffix) + contributed_pet_type('pet_type', contributed, show_image) when PetState - prefix = translate_contributed_description('pet_state_prefix') - contributed_pet_type(contributed.pet_type, image, :before => prefix) + contributed_pet_type('pet_state', contributed.pet_type, show_image) end end - def contributed_item(item, image, adverbial) + def contributed_item(main_key, item, show_image) if item - output do |html| - html << 'the' - html << link_to(item.name, item, :class => 'contributed-name') - html << adverbial - html << image_tag(item.thumbnail_url) if image - end + link = link_to(item.name, item, :class => 'contributed-name') + description = translate('contributions.contributed_description.parents.item.present_html', + :item_link => link) + output = translate("contributions.contributed_description.main.#{main_key}_html", + :item_description => description) + output << image_tag(item.thumbnail_url) if show_image + output else - "data for an item that has since been updated" + translate('contributions.contributed_description.parents.item.blank') end end PET_TYPE_IMAGE_FORMAT = 'http://pets.neopets.com/cp/%s/1/3.png' - def contributed_pet_type(pet_type, image, options) - options[:before] ||= 'the' - output do |html| - html << options[:before] - html << content_tag(:span, pet_type.human_name, :class => 'contributed-name') - html << options[:after] if options[:after] - html << image_tag(sprintf(PET_TYPE_IMAGE_FORMAT, pet_type.image_hash)) if image - end + def contributed_pet_type(main_key, pet_type, show_image) + span = content_tag(:span, pet_type.human_name, :class => 'contributed-name') + description = translate('contributions.contributed_description.parents.pet_type_html', + :pet_type_name => span) + output = translate("contributions.contributed_description.main.#{main_key}_html", + :pet_type_description => description) + output << image_tag(sprintf(PET_TYPE_IMAGE_FORMAT, pet_type.image_hash)) if show_image + output end private @@ -46,7 +43,7 @@ module ContributionHelper raw([].tap(&block).join(' ')) end - def translate_contributed_description(key) - translate "contributions.contributed_description.#{key}" + def translate_contributed_suffix(key) + translate "contributions.contributed_description.suffix.#{key}" end end diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 93156c4e..01c29c00 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -67,7 +67,8 @@ class PetType < ActiveRecord::Base # Until then, access the hash using the English color/species names. unless BasicHashes[species.name] && BasicHashes[species.name][color.name] - raise "basic image hash for #{species.name}, #{color.name} not found" + # TODO: use rainbow pool? some external service? + return 'deadbeef' end BasicHashes[species.name][color.name] diff --git a/config/locales/en-MEEP.yml b/config/locales/en-MEEP.yml index 4eca87cd..aa30af33 100644 --- a/config/locales/en-MEEP.yml +++ b/config/locales/en-MEEP.yml @@ -215,10 +215,16 @@ en-MEEP: contributions: contributed_description: - item_suffix: for the first meep - swf_asset_suffix: on a new body meep - pet_type_suffix: for the first meep - pet_state_prefix: a new meep for + parents: + item: + present_html: the %{item_link} + blank: data for an item that has since been meeped + pet_type_html: the %{pet_type_name} + main: + item_html: "%{item_description} for the first meep" + swf_asset_html: "%{item_description} on a new body meep" + pet_type_html: "%{pet_type_description} for the first meep" + pet_state_html: "a new meep for %{pet_type_description}" contribution: description_html: "%{user_link} meeped us %{contributed_description}" diff --git a/config/locales/en.yml b/config/locales/en.yml index 39518b4a..662f7e68 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -216,10 +216,16 @@ en: contributions: contributed_description: - item_suffix: for the first time - swf_asset_suffix: on a new body type - pet_type_suffix: for the first time - pet_state_prefix: a new pose for + parents: + item: + present_html: the %{item_link} + blank: data for an item that has since been updated + pet_type_html: the %{pet_type_name} + main: + item_html: "%{item_description} for the first time" + swf_asset_html: "%{item_description} on a new body type" + pet_type_html: "%{pet_type_description} for the first time" + pet_state_html: "a new pose for %{pet_type_description}" contribution: description_html: "%{user_link} showed us %{contributed_description}" diff --git a/config/locales/es.yml b/config/locales/es.yml index 2789c46b..dc18ad48 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -164,10 +164,15 @@ es: unlisted_name: No está en la lista contributions: contributed_description: - item_suffix: por primera vez - swf_asset_suffix: en un tipo de cuerpo nuevo - pet_type_suffix: por primera vez - pet_state_prefix: una nueva pose + parents: + item: + present_html: el %{item_link} + pet_type_html: el %{pet_type_name} + main: + item_html: "%{item_description} por primera vez" + swf_asset_html: "%{item_description} en un tipo de cuerpo nuevo" + pet_type_html: "%{pet_type_description} por primera vez" + pet_state_html: "una nueva pose para %{pet_type_description}" contribution: description_html: "%{user_link} nos ha enseñado %{contributed_description}" created_at_html: "hace %{created_at_ago}" diff --git a/config/locales/pt.yml b/config/locales/pt.yml index cbbbea10..43268c13 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -164,10 +164,15 @@ pt: unlisted_name: Não está em uma lista contributions: contributed_description: - item_suffix: pela primeira vez - swf_asset_suffix: em um novo tipo de corpo - pet_type_suffix: pela primeira vez - pet_state_prefix: uma nova pose para + parents: + item: + present_html: o %{item_link} + pet_type_html: o %{pet_type_name} + main: + item_html: "%{item_description} pela primeira vez" + swf_asset_html: "%{item_description} em um novo tipo de corpo" + pet_type_html: "%{pet_type_description} pela primeira vez" + pet_state_html: "uma nova pose para %{pet_type_description}" contribution: description_html: "%{user_link} nos mostrou %{contributed_description}" created_at_html: "%{created_at_ago} atrás"