1
0
Fork 0
forked from OpenNeo/impress

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 module ContributionHelper
def contributed_description(contributed, image = true) def contributed_description(contributed, show_image = true)
case contributed case contributed
when Item when Item
suffix = translate_contributed_description('item_suffix') contributed_item('item', contributed, show_image)
contributed_item(contributed, image, suffix)
when SwfAsset when SwfAsset
suffix = translate_contributed_description('swf_asset_suffix') contributed_item('swf_asset', contributed.item, show_image)
contributed_item(contributed.item, image, suffix)
when PetType when PetType
suffix = translate_contributed_description('pet_type_suffix') contributed_pet_type('pet_type', contributed, show_image)
contributed_pet_type(contributed, image, :after => suffix)
when PetState when PetState
prefix = translate_contributed_description('pet_state_prefix') contributed_pet_type('pet_state', contributed.pet_type, show_image)
contributed_pet_type(contributed.pet_type, image, :before => prefix)
end end
end end
def contributed_item(item, image, adverbial) def contributed_item(main_key, item, show_image)
if item if item
output do |html| link = link_to(item.name, item, :class => 'contributed-name')
html << 'the' description = translate('contributions.contributed_description.parents.item.present_html',
html << link_to(item.name, item, :class => 'contributed-name') :item_link => link)
html << adverbial output = translate("contributions.contributed_description.main.#{main_key}_html",
html << image_tag(item.thumbnail_url) if image :item_description => description)
end output << image_tag(item.thumbnail_url) if show_image
output
else else
"data for an item that has since been updated" translate('contributions.contributed_description.parents.item.blank')
end end
end end
PET_TYPE_IMAGE_FORMAT = 'http://pets.neopets.com/cp/%s/1/3.png' PET_TYPE_IMAGE_FORMAT = 'http://pets.neopets.com/cp/%s/1/3.png'
def contributed_pet_type(pet_type, image, options) def contributed_pet_type(main_key, pet_type, show_image)
options[:before] ||= 'the' span = content_tag(:span, pet_type.human_name, :class => 'contributed-name')
output do |html| description = translate('contributions.contributed_description.parents.pet_type_html',
html << options[:before] :pet_type_name => span)
html << content_tag(:span, pet_type.human_name, :class => 'contributed-name') output = translate("contributions.contributed_description.main.#{main_key}_html",
html << options[:after] if options[:after] :pet_type_description => description)
html << image_tag(sprintf(PET_TYPE_IMAGE_FORMAT, pet_type.image_hash)) if image output << image_tag(sprintf(PET_TYPE_IMAGE_FORMAT, pet_type.image_hash)) if show_image
end output
end end
private private
@ -46,7 +43,7 @@ module ContributionHelper
raw([].tap(&block).join(' ')) raw([].tap(&block).join(' '))
end end
def translate_contributed_description(key) def translate_contributed_suffix(key)
translate "contributions.contributed_description.#{key}" translate "contributions.contributed_description.suffix.#{key}"
end end
end end

View file

@ -67,7 +67,8 @@ class PetType < ActiveRecord::Base
# Until then, access the hash using the English color/species names. # Until then, access the hash using the English color/species names.
unless BasicHashes[species.name] && BasicHashes[species.name][color.name] 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 end
BasicHashes[species.name][color.name] BasicHashes[species.name][color.name]

View file

@ -215,10 +215,16 @@ en-MEEP:
contributions: contributions:
contributed_description: contributed_description:
item_suffix: for the first meep parents:
swf_asset_suffix: on a new body meep item:
pet_type_suffix: for the first meep present_html: the %{item_link}
pet_state_prefix: a new meep for 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: contribution:
description_html: "%{user_link} meeped us %{contributed_description}" description_html: "%{user_link} meeped us %{contributed_description}"

View file

@ -216,10 +216,16 @@ en:
contributions: contributions:
contributed_description: contributed_description:
item_suffix: for the first time parents:
swf_asset_suffix: on a new body type item:
pet_type_suffix: for the first time present_html: the %{item_link}
pet_state_prefix: a new pose for 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: contribution:
description_html: "%{user_link} showed us %{contributed_description}" description_html: "%{user_link} showed us %{contributed_description}"

View file

@ -164,10 +164,15 @@ es:
unlisted_name: No está en la lista unlisted_name: No está en la lista
contributions: contributions:
contributed_description: contributed_description:
item_suffix: por primera vez parents:
swf_asset_suffix: en un tipo de cuerpo nuevo item:
pet_type_suffix: por primera vez present_html: el %{item_link}
pet_state_prefix: una nueva pose 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: contribution:
description_html: "%{user_link} nos ha enseñado %{contributed_description}" description_html: "%{user_link} nos ha enseñado %{contributed_description}"
created_at_html: "hace %{created_at_ago}" created_at_html: "hace %{created_at_ago}"

View file

@ -164,10 +164,15 @@ pt:
unlisted_name: Não está em uma lista unlisted_name: Não está em uma lista
contributions: contributions:
contributed_description: contributed_description:
item_suffix: pela primeira vez parents:
swf_asset_suffix: em um novo tipo de corpo item:
pet_type_suffix: pela primeira vez present_html: o %{item_link}
pet_state_prefix: uma nova pose para 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: contribution:
description_html: "%{user_link} nos mostrou %{contributed_description}" description_html: "%{user_link} nos mostrou %{contributed_description}"
created_at_html: "%{created_at_ago} atrás" created_at_html: "%{created_at_ago} atrás"