better i18n for contributed description

This commit is contained in:
Emi Matchu 2013-02-12 11:45:54 -06:00
parent 15b939f946
commit 989363f743
6 changed files with 64 additions and 44 deletions

View file

@ -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

View file

@ -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]

View file

@ -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}"

View file

@ -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}"

View file

@ -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}"

View file

@ -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"