1
0
Fork 0
forked from OpenNeo/impress

i18n for items#show (including javascripts/items/show.js)

This commit is contained in:
Emi Matchu 2012-12-30 14:15:55 -05:00
parent dd4c650a43
commit 19a877d38e
9 changed files with 167 additions and 99 deletions

View file

@ -48,7 +48,7 @@ class ItemsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html do format.html do
unless fragment_exist?("items/#{@item.id} contributors") unless localized_fragment_exist?("items/#{@item.id} contributors")
@contributors_with_counts = @item.contributors_with_counts @contributors_with_counts = @item.contributors_with_counts
end end

View file

@ -137,5 +137,15 @@ module ClosetHangersHelper
hangers = @unlisted_closet_hangers_by_owned[owned] hangers = @unlisted_closet_hangers_by_owned[owned]
hangers ? hangers.size : 0 hangers ? hangers.size : 0
end end
def closet_lists_group_name(subject, owned)
ownership_key = owned ? 'owned_by' : 'wanted_by'
if subject == :you
translate "closet_lists.groups.#{ownership_key}.you"
else
translate "closet_lists.groups.#{ownership_key}.another_user",
:user_name => subject.name
end
end
end end

View file

@ -103,6 +103,11 @@ module ItemsHelper
"http://www.neopets.com/genie.phtml?type=process_genie&criteria=exact&auctiongenie=#{CGI::escape item.name}" "http://www.neopets.com/genie.phtml?type=process_genie&criteria=exact&auctiongenie=#{CGI::escape item.name}"
end end
def trading_closet_hangers_header(owned, count)
ownership_key = owned ? 'owned' : 'wanted'
translate ".trading_closet_hangers.header.#{ownership_key}", :count => count
end
def render_trading_closet_hangers(owned) def render_trading_closet_hangers(owned)
@trading_closet_hangers_by_owned[owned].map do |hanger| @trading_closet_hangers_by_owned[owned].map do |hanger|
link_to hanger.user.name, user_closet_hangers_path(hanger.user) link_to hanger.user.name, user_closet_hangers_path(hanger.user)

View file

@ -6,7 +6,7 @@ class ContributionObserver < ActiveRecord::Observer
if contribution.contributed_type == 'SwfAsset' if contribution.contributed_type == 'SwfAsset'
item = contribution.contributed.item item = contribution.contributed.item
expire_fragment("items/#{item.id} contributors") expire_fragment_in_all_locales("items/#{item.id} contributors")
end end
end end
end end

View file

@ -20,8 +20,8 @@ class ItemObserver < ActionController::Caching::Sweeper
def expire_cache_for(item) def expire_cache_for(item)
expire_fragment("items/#{item.id}#item_link_partial") expire_fragment("items/#{item.id}#item_link_partial")
expire_fragment("items/#{item.id} header") expire_fragment_in_all_locales("items/#{item.id} header")
expire_fragment("items/#{item.id} info") expire_fragment_in_all_locales("items/#{item.id} info")
end end
def expire_newest_items def expire_newest_items

View file

@ -1,31 +1,32 @@
- title @item.name - title @item.name
- canonical_path @item - canonical_path @item
- cache "items/#{@item.id} header" do - localized_cache "items/#{@item.id} header" do
%header#item-header %header#item-header
= image_tag @item.thumbnail_url, :id => 'item-thumbnail' = image_tag @item.thumbnail_url, :id => 'item-thumbnail'
%div %div
%h2#item-name= @item.name %h2#item-name= @item.name
= nc_icon_for(@item) = nc_icon_for(@item)
- unless @item.rarity.blank? - unless @item.rarity.blank?
== Rarity: #{@item.rarity_index} (#{@item.rarity}) == #{t '.rarity'}: #{@item.rarity_index} (#{@item.rarity})
= link_to 'JN Items', jn_items_url_for(@item) = link_to t('.jn_items'), jn_items_url_for(@item)
- unless @item.nc? - unless @item.nc?
= link_to 'Shop Wizard', shop_wizard_url_for(@item) = link_to t('.shop_wizard'), shop_wizard_url_for(@item)
= link_to 'Super Wizard', super_shop_wizard_url_for(@item) = link_to t('.super_shop_wizard'), super_shop_wizard_url_for(@item)
= link_to 'Trades', trading_post_url_for(@item) = link_to t('.trading_post'), trading_post_url_for(@item)
= link_to 'Auctions', auction_genie_url_for(@item) = link_to t('.auction_genie'), auction_genie_url_for(@item)
- if user_signed_in? - if user_signed_in?
#closet-hangers #closet-hangers
%h3 %h3
Track this in = t '.hangers_header_html',
= link_to 'Your Items', user_closet_hangers_path(current_user) :user_items_link => link_to(t('your_items'),
user_closet_hangers_path(current_user))
= form_tag update_quantities_user_item_closet_hangers_path(:user_id => current_user, :item_id => @item), :method => :put do = form_tag update_quantities_user_item_closet_hangers_path(:user_id => current_user, :item_id => @item), :method => :put do
#closet-hangers-ownership-groups #closet-hangers-ownership-groups
- @current_user_lists.each do |owned, lists| - @current_user_lists.each do |owned, lists|
%div %div
%h4 Items you #{closet_list_verb(owned)} %h4= closet_lists_group_name(:you, owned)
%ul %ul
- lists.each do |list| - lists.each do |list|
%li %li
@ -38,81 +39,69 @@
@current_user_quantities[owned], :min => 0 @current_user_quantities[owned], :min => 0
- unless lists.empty? - unless lists.empty?
= label_tag "quantity[#{owned}]", :class => 'unlisted' do = label_tag "quantity[#{owned}]",
Not in a list t('closet_lists.unlisted_name'),
:class => 'unlisted'
- else - else
= label_tag "quantity[#{owned}]" do = label_tag "quantity[#{owned}]", t('.quantity_label')
How many? = submit_tag t('.submit_hangers')
= submit_tag 'Save to Your Items'
- cache "items/#{@item.id} info" do - localized_cache "items/#{@item.id} info" do
%p= @item.description %p= @item.description
#item-zones #item-zones
%p %p
%strong Occupies: %strong #{t '.occupied_zones_header'}:
= list_zones @item.occupied_zones, :uncertain_label = list_zones @item.occupied_zones, :uncertain_label
%p %p
%strong Restricts: %strong #{t '.restricted_zones_header'}:
- if @item.restricted_zones.empty? - if @item.restricted_zones.empty?
None = t '.no_restricted_zones'
- else - else
= list_zones @item.restricted_zones = list_zones @item.restricted_zones
#trade-hangers #trade-hangers
- [true, false].each do |owned| - [true, false].each do |owned|
%p %p
- unless @trading_closet_hangers_by_owned[owned].empty? %strong
%strong = trading_closet_hangers_header(owned, @trading_closet_hangers_by_owned[owned].size)
= pluralize @trading_closet_hangers_by_owned[owned].size, 'user' = render_trading_closet_hangers(owned)
- if owned
- if @trading_closet_hangers_by_owned[owned].size == 1
has
- else
have
this item up for trade:
- else
- if @trading_closet_hangers_by_owned[owned].size == 1
wants
- else
want
this item:
= render_trading_closet_hangers(owned)
- else
%strong
We don't know anyone who
- if owned
has this item up for trade.
- else
wants this item.
%span.toggle %span.toggle
%span.more more %span.more= t '.trading_closet_hangers.show_more'
%span.less less %span.less= t '.trading_closet_hangers.show_less'
- cache 'items#show preview_header' do - localized_cache 'items#show preview_header' do
#item-preview-header #item-preview-header
%h3 Preview %h3= t '.preview_header'
%a#customize-more.button{:href => '/'} Customize more = link_to t('.customize_more'), root_path, :id => 'customize-more',
:class => 'button'
#item-preview #item-preview
#item-preview-species= standard_species_images_for(@item) #item-preview-species= standard_species_images_for(@item)
#item-preview-error #item-preview-error
#item-preview-swf #item-preview-swf= t '.preview_requirements_not_met'
Javascript and Flash are required to preview wearables. Sorry!
- cache "items/#{@item.id} contributors" do - localized_cache "items/#{@item.id} contributors" do
- unless @contributors_with_counts.empty? - unless @contributors_with_counts.empty?
#item-contributors #item-contributors
%header Brought to you by: %header #{t '.contributors_header'}:
%ul %ul
- @contributors_with_counts.each do |contributor, count| - @contributors_with_counts.each do |contributor, count|
%li= link_to(contributor.name, user_contributions_path(contributor)) + format_contribution_count(count) %li= link_to(contributor.name, user_contributions_path(contributor)) + format_contribution_count(count)
%footer Thanks! %footer= t '.contributors_footer'
:javascript :javascript
var CURRENT_ITEM_ZONES_RESTRICT = #{@item.zones_restrict.inspect}, var CURRENT_ITEM_ZONES_RESTRICT = #{@item.zones_restrict.inspect},
IMPRESS_HOST = #{RemoteImpressHost.inspect}; IMPRESS_HOST = #{RemoteImpressHost.inspect};
= include_javascript_libraries :jquery, :swfobject %script#swf-assets-not-found-template{:type => 'text/x-jquery-tmpl'}
= javascript_include_tag 'items/show' = t '.swf_assets_not_found_html', :item_name => h(@item.name),
:species_name => '${species_name}',
:color_name => '${color_name}',
:modeling_link => link_to(t('.swf_assets_not_found_modeling_link_content'),
root_path)
- content_for :javascripts do
= include_javascript_libraries :jquery, :swfobject, :jquery_tmpl
= javascript_include_tag 'items/show'

View file

@ -48,6 +48,16 @@ en-meep:
converted_at_html: Conveeped %{converted_at_ago} ago converted_at_html: Conveeped %{converted_at_ago} ago
reported_at_html: Repeeped %{reported_at_ago} ago reported_at_html: Repeeped %{reported_at_ago} ago
closet_lists:
unlisted_name: Not in a meep
groups:
owned_by:
you: Meeps you own
another_user: Meeps %{user_name} owns
wanted_by:
you: Meeps you want
another_user: Meeps %{user_name} wants
contributions: contributions:
contributed_description: contributed_description:
item_suffix: for the first meep item_suffix: for the first meep
@ -97,6 +107,43 @@ en-meep:
newest_items_header: New Meeps newest_items_header: New Meeps
species_search_header: Can't decide? Meep by species species_search_header: Can't decide? Meep by species
show:
rarity: Meepity
jn_items: JN Meepits
shop_wizard: Meep Wizard
super_shop_wizard: Meeper Wizard
trading_post: Treeps
auction_genie: Aucteeps
hangers_header_html: Meep this in %{user_items_link}
quantity_label: How meepy?
submit_hangers: Save to Your Meeps
occupied_zones_header: Occupeeps
restricted_zones_header: Restreeps
no_restricted_zones: Meepless
trading_closet_hangers:
header:
owned:
zero: We don't know anymeep who has this item meep for trade.
one: "1 user has this item meep for trade:"
other: "%{count} users have this item meep for trade:"
wanted:
zero: "We don't know anymeep who meeps this item."
one: "1 user meeps this item:"
other: "%{count} users meep this item:"
show_more: meep more
show_less: meep less
preview_header: Meepview
customize_more: Customize meep
preview_requirements_not_met:
Javascript and Flash are required to preview meepits. Meep!
contributors_header: Meeped to you by
contributors_footer: Meep!
swf_assets_not_found_html:
We've never meeped the %{item_name} on the %{color_name}
%{species_name} before. Have you? If so, please %{modeling_link} and
we'll meep our datameep instantly. Meep!
swf_assets_not_found_modeling_link_content: meep it for us
outfits: outfits:
new: new:
tagline: Meeps made meepy! tagline: Meeps made meepy!

View file

@ -49,6 +49,17 @@ en:
converted_at_html: Converted %{converted_at_ago} ago converted_at_html: Converted %{converted_at_ago} ago
reported_at_html: Reported %{reported_at_ago} ago reported_at_html: Reported %{reported_at_ago} ago
closet_lists:
unlisted_name: Not in a list
groups:
owned_by:
you: Items you own
another_user: Items %{user_name} owns
wanted_by:
you: Items you want
another_user: Items %{user_name} wants
contributions: contributions:
contributed_description: contributed_description:
item_suffix: for the first time item_suffix: for the first time
@ -98,6 +109,43 @@ en:
newest_items_header: Newest items newest_items_header: Newest items
species_search_header: Can't decide? Search by species species_search_header: Can't decide? Search by species
show:
rarity: Rarity
jn_items: JN Items
shop_wizard: Shop Wizard
super_shop_wizard: Super Wizard
trading_post: Trades
auction_genie: Auctions
hangers_header_html: Track this in %{user_items_link}
quantity_label: How many?
submit_hangers: Save to Your Items
occupied_zones_header: Occupies
restricted_zones_header: Restricts
no_restricted_zones: None
trading_closet_hangers:
header:
owned:
zero: We don't know anyone who has this item up for trade.
one: "1 user has this item up for trade:"
other: "%{count} users have this item up for trade:"
wanted:
zero: "We don't know anyone who wants this item."
one: "1 user wants this item:"
other: "%{count} users want this item:"
show_more: more
show_less: less
preview_header: Preview
customize_more: Customize more
preview_requirements_not_met:
Javascript and Flash are required to preview wearables. Sorry!
contributors_header: Brought to you by
contributors_footer: Thanks!
swf_assets_not_found_html:
We've never seen the %{item_name} on the %{color_name}
%{species_name} before. Have you? If so, please %{modeling_link} and
we'll update our database instantly. Thanks!
swf_assets_not_found_modeling_link_content: model it for us
outfits: outfits:
new: new:
tagline: Neopets wearables made easy! tagline: Neopets wearables made easy!

View file

@ -16,56 +16,29 @@ String.prototype.capitalize = function () {
return this.charAt(0).toUpperCase() + this.substr(1); return this.charAt(0).toUpperCase() + this.substr(1);
} }
String.prototype.article = function () {
return 'aeiou'.indexOf(this.charAt(0).toLowerCase()) == -1 ? 'a' : 'an'
}
function impressUrl(path) { function impressUrl(path) {
return 'http://' + IMPRESS_HOST + path; return 'http://' + IMPRESS_HOST + path;
} }
function LoadError(base_msg) {
this.render = function (args) {
var msg = base_msg, token, article_token;
for(var i in args) {
token = "$" + i;
article_token = token + "_article";
if(msg.indexOf(article_token) != -1) {
msg = msg.replace(article_token, args[i].article());
}
msg = msg.replace(token, args[i]);
}
return "Whoops - we've never seen " + msg + " before! If you have, please " +
"<a href='http://" + IMPRESS_HOST + "'>submit that pet's name</a> as soon as you " +
"get the chance! Thanks!";
}
}
function PetType() { function PetType() {
var pet_type = this, loaded_data = false, loaded_assets = false; var pet_type = this, loaded_data = false, loaded_assets = false;
this.activated = true; this.activated = true;
this.assets = []; this.assets = [];
this.deactivate = function (error, args) { this.deactivate = function () {
var msg; var msg;
this.activated = false; this.activated = false;
if(typeof args == 'undefined') args = {}; this.deactivation_msg = $('#swf-assets-not-found-template').tmpl({
args.color = this.color_name.capitalize(); color_name: this.color_name.capitalize(),
args.species = this.species_name.capitalize(); species_name: this.species_name.capitalize()
this.deactivation_msg = error.render(args); });
if(this == PetType.current) showDeactivationMsg(); if(this == PetType.current) showDeactivationMsg();
var img = this.link.children('img').get(0); var img = this.link.children('img').get(0);
this.link.addClass('deactivated'); this.link.addClass('deactivated');
img.src = img.src.replace('/1/', '/2/'); img.src = img.src.replace('/1/', '/2/');
} }
this.deactivateWithItem = function (item) {
pet_type.deactivate(Item.LOAD_ERROR, {
item: item.name
});
}
this.load = function () { this.load = function () {
Item.current.load(this); Item.current.load(this);
loadAssets(); loadAssets();
@ -108,8 +81,6 @@ function PetType() {
} }
PetType.all = {}; PetType.all = {};
PetType.LOAD_ERROR = new LoadError("$color_article $color $species");
PetType.DASH_REGEX = /-/g; PetType.DASH_REGEX = /-/g;
PetType.createFromLink = function (link) { PetType.createFromLink = function (link) {
@ -148,7 +119,7 @@ function Item(id) {
}); });
$.each(PetType.all, function () { $.each(PetType.all, function () {
if(item.getAssetsForPetType(this).length == 0) { if(item.getAssetsForPetType(this).length == 0) {
this.deactivateWithItem(item); this.deactivate();
} }
}); });
}); });
@ -167,13 +138,11 @@ function Item(id) {
this.assets_by_body_id[pet_type.body_id] = assets; this.assets_by_body_id[pet_type.body_id] = assets;
pet_type.onUpdate(); pet_type.onUpdate();
} else { } else {
pet_type.deactivateWithItem(this); pet_type.deactivate();
} }
} }
} }
Item.LOAD_ERROR = new LoadError("$species_article $species wear a $item");
Item.createFromLocation = function () { Item.createFromLocation = function () {
var item = new Item(parseInt(document.location.pathname.substr(7), 10)), var item = new Item(parseInt(document.location.pathname.substr(7), 10)),
z = CURRENT_ITEM_ZONES_RESTRICT, zl = z.length; z = CURRENT_ITEM_ZONES_RESTRICT, zl = z.length;
@ -197,7 +166,7 @@ Preview = new function Preview() {
this.update = function (assets) { this.update = function (assets) {
var assets; var assets;
if(swf) { if(swf && typeof swf.setAssets == 'function') {
log('now doing update'); log('now doing update');
assets = PetType.current.assets.concat( assets = PetType.current.assets.concat(
Item.current.getAssetsForPetType(PetType.current) Item.current.getAssetsForPetType(PetType.current)
@ -228,9 +197,9 @@ Preview = new function Preview() {
); );
} }
this.disable = function (msg) { this.disable = function (errorMessage) {
$('#' + swf_id).hide(); $('#' + swf_id).hide();
$('#item-preview-error').html(msg).show(); $('#item-preview-error').empty().append(errorMessage).show();
} }
this.enable = function () { this.enable = function () {