From c5e92ec53cb73f7b207784ebe87a2484b8212173 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 1 Jan 2013 23:40:37 -0500 Subject: [PATCH] i18n for neopets_pages#create (flashes - holy snap, that was nasty) --- app/controllers/neopets_pages_controller.rb | 52 ++++++++++++--------- config/locales/en-meep.yml | 37 +++++++++++++++ config/locales/en.yml | 37 +++++++++++++++ 3 files changed, 103 insertions(+), 23 deletions(-) diff --git a/app/controllers/neopets_pages_controller.rb b/app/controllers/neopets_pages_controller.rb index a930789d..5bf908d0 100644 --- a/app/controllers/neopets_pages_controller.rb +++ b/app/controllers/neopets_pages_controller.rb @@ -10,40 +10,48 @@ class NeopetsPagesController < ApplicationController @neopets_page.index = @page_params[:index] @neopets_page.source = @page_params[:source] - saved_counts = @neopets_page.save_hangers! + messages = [t('neopets_pages.create.success', + :index => @neopets_page.index)] + saved_counts = @neopets_page.save_hangers! any_created = saved_counts[:created] > 0 any_updated = saved_counts[:updated] > 0 - if any_created || any_updated - message = "Page #{@neopets_page.index} saved! We " - message << "added " + pluralize(saved_counts[:created], 'item') + " to the items you own" if any_created - message << " and " if any_created && any_updated - message << "updated the count on " + pluralize(saved_counts[:updated], 'item') if any_updated - message << ". " - elsif @neopets_page.hangers.size > 1 - message = "Success! We checked that page, and we already had all this data recorded. " - else - message = "Success! We checked that page, and there were no wearables to add. " + if any_created && any_updated + created_msg = t('neopets_pages.create.created_and_updated_hangers.created_msg', + :count => saved_counts[:created]) + updated_msg = t('neopets_pages.create.created_and_updated_hangers.updated_msg', + :count => saved_counts[:updated]) + messages << t('neopets_pages.create.created_and_updated_hangers.text', + :created_msg => created_msg, + :updated_msg => updated_msg) + elsif any_created + messages << t('neopets_pages.create.created_hangers', + :count => saved_counts[:created]) + elsif any_updated + messages << t('neopets_pages.create.updated_hangers', + :count => saved_counts[:updated]) + elsif @neopets_page.hangers.size > 1 # saw items, but at same quantities + messages << t('neopets_pages.create.no_changes') + else # no items recognized + messages << t('neopets_pages.create.no_data') end unless @neopets_page.unknown_item_names.empty? - message << "We also found " + - pluralize(@neopets_page.unknown_item_names.size, 'item') + - " we didn't recognize: " + - @neopets_page.unknown_item_names.to_sentence + - ". Please put each item on your pet and type its name in on the " + - "home page so we can have a record of it. Thanks! " + messages << t('neopets_pages.create.unknown_items', + :item_names => @neopets_page.unknown_item_names.to_sentence, + :count => @neopets_page.unknown_item_names.size) end if @neopets_page.last? - message << "That was the last page of your Neopets #{@neopets_page.name}." + messages << t('neopets_pages.create.done', :name => @neopets_page.name) destination = user_closet_hangers_path(current_user) else - message << "Now the frame should contain page #{@neopets_page.index + 1}. Paste that source code over, too." + messages << t('neopets_pages.create.next_page', + :next_index => (@neopets_page.index + 1)) destination = {:action => :new, :index => (@neopets_page.index + 1)} end - flash[:success] = message + flash[:success] = messages.join(' ') redirect_to destination else redirect_to :action => :new @@ -70,9 +78,7 @@ class NeopetsPagesController < ApplicationController def on_parse_error(e) Rails.logger.info "Neopets page parse error: #{e.message}" - flash[:alert] = "We had trouble reading your source code. Is it a valid " + - "HTML document? Make sure you pasted the computery-looking result of " + - "clicking View Frame Source, and not the pretty page itself. " + flash[:alert] = t('neopets_pages.create.parse_error') render :action => :new end end diff --git a/config/locales/en-meep.yml b/config/locales/en-meep.yml index cfd6ac30..78bee665 100644 --- a/config/locales/en-meep.yml +++ b/config/locales/en-meep.yml @@ -277,6 +277,43 @@ en-meep: swf_assets_not_found_modeling_link_content: meep it for us neopets_pages: + create: + success: Page %{index} meeped! + created_and_updated_hangers: + text: "%{created_msg} meep %{updated_msg}." + created_msg: + one: We added 1 meepit + other: We added %{count} meepit + updated_msg: + one: updated the meepity for 1 more + other: updated the meepity for %{count} more + created_hangers: + one: We added 1 new meepit to the list of meepits you own. + other: We added %{count} new meepits to the list of meepits you own. + updated_hangers: + one: We updated the quantity for 1 of your meepits. + other: We updated the quantity for %{count} of your meepits. + no_changes: + We already had this data meeped to your account, + so we didn't meep any changes. + no_data: We didn't meep any wearables, so we didn't meep any changes. + unknown_items: + one: + "We also meeped an item we didn't recognize: %{item_names}. Please + meep it for us and we'll update our database instantly. Thanks!" + other: + "We also meeped %{count} items we didn't recognize: %{item_names}. + Please meep them for us and we'll update our database instantly. + Thanks!" + next_page: + Now the frame should contain page %{next_index}. + Meep that source code over, too. + done: That was the last meepit of your Neopets %{name}. + parse_error: + We had trouble meeping your source code. Is it a valid HTML document? + Make sure you meeped the computery-looking result of clicking View + Frame Source, and not the pretty-looking page itself. + names: closet: meepit safety_deposit: safety demeepit diff --git a/config/locales/en.yml b/config/locales/en.yml index 1a2d443c..2c36da51 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -278,9 +278,46 @@ en: swf_assets_not_found_modeling_link_content: model it for us neopets_pages: + create: + success: Page %{index} saved! + created_and_updated_hangers: + text: "%{created_msg} and %{updated_msg}." + created_msg: + one: We added 1 item + other: We added %{count} items + updated_msg: + one: updated the quantity for 1 more + other: updated the quantity for %{count} more + created_hangers: + one: We added 1 new item to the list of items you own. + other: We added %{count} new items to the list of items you own. + updated_hangers: + one: We updated the quantity for 1 of your items. + other: We updated the quantity for %{count} of your items. + no_changes: + We already had this data recorded to your account, so we didn't make any changes. + no_data: We didn't see any wearables, so we didn't make any changes. + unknown_items: + one: + "We also found an item we didn't recognize: %{item_names}. Please + model it for us and we'll update our database instantly. Thanks!" + other: + "We also found %{count} items we didn't recognize: %{item_names}. + Please model them for us and we'll update our database instantly. + Thanks!" + next_page: + Now the frame should contain page %{next_index}. + Paste that source code over, too. + done: That was the last page of your Neopets %{name}. + parse_error: + We had trouble reading your source code. Is it a valid HTML document? + Make sure you pasted the computery-looking result of clicking View + Frame Source, and not the pretty-looking page itself. + names: closet: closet safety_deposit: safety deposit + new: title: Import from %{name}, Page %{index} your_items_link: Back to Your Items