From f355c393f006c596c3187a879960269f770dc547 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Thu, 18 Sep 2014 06:15:59 +1000 Subject: [PATCH 01/22] basic setup --- app/controllers/application_controller.rb | 10 ++ app/views/home/_blurb.html.haml | 5 +- config/initializers/locale.rb | 2 + config/locales/en.yml | 1 + config/locales/jp.yml | 2 + config/routes.rb | 137 +++++++++++----------- db/schema.rb | 1 + 7 files changed, 87 insertions(+), 71 deletions(-) create mode 100644 config/initializers/locale.rb create mode 100644 config/locales/jp.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0d07cb866..29f5adb35 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base include ApplicationHelper after_filter :store_location + before_filter :set_locale def store_location if (request.path != "/members/sign_in" && @@ -32,5 +33,14 @@ class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied do |exception| redirect_to request.referer || root_url, :alert => exception.message end + + def set_locale + I18n.locale = params[:locale] || I18n.default_locale + end + + def default_url_options(options={}) + logger.debug "default_url_options is passed options: #{options.inspect}\n" + { locale: I18n.locale } + end end diff --git a/app/views/home/_blurb.html.haml b/app/views/home/_blurb.html.haml index 3e742b8d4..ba3fd072f 100644 --- a/app/views/home/_blurb.html.haml +++ b/app/views/home/_blurb.html.haml @@ -5,10 +5,7 @@ .row .col-md-8.info %p - #{ENV['GROWSTUFF_SITE_NAME']} is a community of food gardeners. - We're building an open source platform to help you learn about - growing food, track what you plant and harvest, and swap - seeds and produce with other gardeners near you. + #{ENV['GROWSTUFF_SITE_NAME']} #{t 'blurb'} = render :partial => 'stats' .col-md-4.signup diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb new file mode 100644 index 000000000..ef55314c4 --- /dev/null +++ b/config/initializers/locale.rb @@ -0,0 +1,2 @@ +I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')] + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 7a30c72fe..4d47f61ab 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -13,3 +13,4 @@ en: all: "Please sign in or sign up to create a %{subject}." manage: all: "Not authorized to %{action} %{subject}." + blurb: "is a community of food gardeners. We're building an open source platform to help you learn about growing food, track what you plant and harvest, and swap seeds and produce with other gardeners near you." \ No newline at end of file diff --git a/config/locales/jp.yml b/config/locales/jp.yml new file mode 100644 index 000000000..89dcea14a --- /dev/null +++ b/config/locales/jp.yml @@ -0,0 +1,2 @@ +jp: + blurb: "はガーデナーのコミュニティーです。" diff --git a/config/routes.rb b/config/routes.rb index 360ed2477..01600b7ed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,78 +1,81 @@ Growstuff::Application.routes.draw do - resources :plant_parts - - - devise_for :members, :controllers => { :registrations => "registrations", :passwords => "passwords" } - resources :members - - resources :photos - - resources :authentications - - resources :plantings - match '/plantings/owner/:owner' => 'plantings#index', :as => 'plantings_by_owner' - - resources :gardens - match '/gardens/owner/:owner' => 'gardens#index', :as => 'gardens_by_owner' - - resources :seeds - match '/seeds/owner/:owner' => 'seeds#index', :as => 'seeds_by_owner' - - resources :harvests - match '/harvests/owner/:owner' => 'harvests#index', :as => 'harvests_by_owner' - - resources :posts - match '/posts/author/:author' => 'posts#index', :as => 'posts_by_author' - - resources :scientific_names - - match 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops' - match 'crops/hierarchy' => 'crops#hierarchy', :as => 'crops_hierarchy' - match 'crops/search' => 'crops#search', :as => 'crops_search' - resources :crops - - resources :comments - resources :roles - resources :forums - resources :notifications - - get '/places' => 'places#index' - get '/places/search' => 'places#search', :as => 'search_places' - get '/places/:place' => 'places#show', :as => 'place' - - # everything for paid accounts etc - resources :account_types - resources :accounts - resources :orders - match 'orders/:id/checkout' => 'orders#checkout', :as => 'checkout_order' - match 'orders/:id/complete' => 'orders#complete', :as => 'complete_order' - match 'orders/:id/cancel' => 'orders#cancel', :as => 'cancel_order' - - resources :order_items - resources :products - - get "home/index" + get "/:locale" => 'home#index' root :to => 'home#index' - match 'auth/:provider/callback' => 'authentications#create' + scope '/:locale' do + + resources :plant_parts + + devise_for :members, :controllers => { :registrations => "registrations", :passwords => "passwords" } + resources :members + + resources :photos + + resources :authentications + + resources :plantings + match '/plantings/owner/:owner' => 'plantings#index', :as => 'plantings_by_owner' + + resources :gardens + match '/gardens/owner/:owner' => 'gardens#index', :as => 'gardens_by_owner' + + resources :seeds + match '/seeds/owner/:owner' => 'seeds#index', :as => 'seeds_by_owner' + + resources :harvests + match '/harvests/owner/:owner' => 'harvests#index', :as => 'harvests_by_owner' + + resources :posts + match '/posts/author/:author' => 'posts#index', :as => 'posts_by_author' + + resources :scientific_names + + match 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops' + match 'crops/hierarchy' => 'crops#hierarchy', :as => 'crops_hierarchy' + match 'crops/search' => 'crops#search', :as => 'crops_search' + resources :crops + + resources :comments + resources :roles + resources :forums + resources :notifications + + get '/places' => 'places#index' + get '/places/search' => 'places#search', :as => 'search_places' + get '/places/:place' => 'places#show', :as => 'place' + + # everything for paid accounts etc + resources :account_types + resources :accounts + resources :orders + match 'orders/:id/checkout' => 'orders#checkout', :as => 'checkout_order' + match 'orders/:id/complete' => 'orders#complete', :as => 'complete_order' + match 'orders/:id/cancel' => 'orders#cancel', :as => 'cancel_order' + + resources :order_items + resources :products + + match 'auth/:provider/callback' => 'authentications#create' - match '/policy/:action' => 'policy#:action' + match '/policy/:action' => 'policy#:action' - match '/support' => 'support#index' - match '/support/:action' => 'support#:action' + match '/support' => 'support#index' + match '/support/:action' => 'support#:action' - match '/about' => 'about#index' - match '/about/:action' => 'about#:action' + match '/about' => 'about#index' + match '/about/:action' => 'about#:action' - match '/shop' => 'shop#index' - match '/shop/:action' => 'shop#:action' + match '/shop' => 'shop#index' + match '/shop/:action' => 'shop#:action' - match '/admin/orders' => 'admin/orders#index' - match '/admin/orders/:action' => 'admin/orders#:action' - match '/admin' => 'admin#index' - match '/admin/newsletter' => 'admin#newsletter', :as => :admin_newsletter - match '/admin/:action' => 'admin#:action' + match '/admin/orders' => 'admin/orders#index' + match '/admin/orders/:action' => 'admin/orders#:action' + match '/admin' => 'admin#index' + match '/admin/newsletter' => 'admin#newsletter', :as => :admin_newsletter + match '/admin/:action' => 'admin#:action' -end + end + +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 29271f5e6..af91a7a9d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -139,6 +139,7 @@ ActiveRecord::Schema.define(:version => 20140829230600) do t.text "bio" t.integer "plantings_count" t.boolean "newsletter" + t.boolean "send_planting_reminder", :default => true end add_index "members", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true From 87df8661c7c6829549ef2e4bb5dc71d4af4527d2 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Thu, 18 Sep 2014 06:24:59 +1000 Subject: [PATCH 02/22] raise exception on missing translations in test and dev environment --- config/initializers/locale.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index ef55314c4..eb4ed56e7 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -1,2 +1,8 @@ I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')] + +if Rails.env.development? || Rails.env.test? + I18n.exception_handler = lambda do |exception, locale, key, options| + raise "Missing translation: #{key}" + end +end \ No newline at end of file From f8ee9d05894100a2b4041e23b5d154110e902f67 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Thu, 18 Sep 2014 07:14:35 +1000 Subject: [PATCH 03/22] don't scope routes to locale to make url prettier because it breaks tests like whoa --- Gemfile | 1 + Gemfile.lock | 18 +++++ config/i18n-tasks.yml | 90 ++++++++++++++++++++++ config/initializers/locale.rb | 1 + config/routes.rb | 137 +++++++++++++++++----------------- spec/i18n_spec.rb | 18 +++++ 6 files changed, 195 insertions(+), 70 deletions(-) create mode 100644 config/i18n-tasks.yml create mode 100644 spec/i18n_spec.rb diff --git a/Gemfile b/Gemfile index e47403546..fd8184894 100644 --- a/Gemfile +++ b/Gemfile @@ -127,4 +127,5 @@ group :development, :test do gem 'coveralls', require: false # coverage analysis gem 'capybara' # integration tests gem 'poltergeist', '~> 1.5.1' # for headless JS testing + gem 'i18n-tasks' # adds tests for finding missing and unused translations end diff --git a/Gemfile.lock b/Gemfile.lock index 7829a34de..d8ccbfcb2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,6 +110,10 @@ GEM warden (~> 1.2.3) diff-lcs (1.1.3) docile (1.1.5) + easy_translate (0.5.0) + json + thread + thread_safe erubis (2.7.0) execjs (2.2.1) factory_girl (4.4.0) @@ -138,11 +142,21 @@ GEM haml (>= 3.1, < 4.1) railties (>= 3.1, < 4.1) hashie (3.3.1) + highline (1.6.21) hike (1.2.3) httparty (0.11.0) multi_json (~> 1.0) multi_xml (>= 0.5.2) i18n (0.6.1) + i18n-tasks (0.7.6) + activesupport + easy_translate (>= 0.5.0) + erubis + highline + i18n + slop (>= 3.5.0) + term-ansicolor + terminal-table journey (1.0.4) jquery-rails (3.1.1) railties (>= 3.0, < 5.0) @@ -257,6 +271,7 @@ GEM multi_json simplecov-html (~> 0.8.0) simplecov-html (0.8.0) + slop (3.6.0) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -266,10 +281,12 @@ GEM sprockets (>= 1.0.2) term-ansicolor (1.3.0) tins (~> 1.0) + terminal-table (1.4.5) therubyracer (0.12.1) libv8 (~> 3.16.14.0) ref thor (0.19.1) + thread (0.1.4) thread_safe (0.3.4) tilt (1.4.1) tins (1.3.2) @@ -325,6 +342,7 @@ DEPENDENCIES gravatar-ultimate haml haml-rails + i18n-tasks jquery-rails jquery-ui-rails js-routes diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml new file mode 100644 index 000000000..e1a1c35d9 --- /dev/null +++ b/config/i18n-tasks.yml @@ -0,0 +1,90 @@ +# i18n-tasks finds and manages missing and unused translations https://github.com/glebm/i18n-tasks + +base_locale: en +## i18n-tasks detects locales automatically from the existing locale files +## uncomment to set locales explicitly +# locales: [en, es, fr] + +## i18n-tasks report locale, default: en, available: en, ru +# internal_locale: ru + +# Read and write locale data +data: + ## by default, translation data are read from the file system, or you can provide a custom data adapter + # adapter: I18n::Tasks::Data::FileSystem + + # Locale files to read from + read: + - config/locales/%{locale}.yml + # - config/locales/*.%{locale}.yml + # - config/locales/**/*.%{locale}.yml + + # key => file routes, matched top to bottom + write: + ## E.g., write devise and simple form keys to their respective files + # - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml'] + # Catch-all + - config/locales/%{locale}.yml + # `i18n-tasks normalize -p` will force move the keys according to these rules + + # YAML / JSON serializer options, passed to load / dump / parse / serialize + yaml: + write: + # do not wrap lines at 80 characters + line_width: -1 + json: + write: + # pretty print JSON + indent: ' ' + space: ' ' + object_nl: "\n" + array_nl: "\n" + +# Find translate calls +search: + ## Default scanner finds t() and I18n.t() calls + # scanner: I18n::Tasks::Scanners::PatternWithScopeScanner + + ## Paths to search in, passed to File.find + paths: + - app/ + + ## Root for resolving relative keys (default) + # relative_roots: + # - app/views + + ## File.fnmatch patterns to exclude from search (default) + # exclude: ["*.jpg", "*.png", "*.gif", "*.svg", "*.ico", "*.eot", "*.ttf", "*.woff", "*.pdf"] + + ## Or, File.fnmatch patterns to include + # include: ["*.rb", "*.html.slim"] + + ## Lines starting with # or / are ignored by default + # ignore_lines: + # - "^\\s*[#/](?!\\si18n-tasks-use)" + +## Google Translate +# translation: +# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate +# api_key: "AbC-dEf5" + +## Consider these keys not missing +# ignore_missing: +# - pagination.views.* + +## Consider these keys used +# ignore_unused: +# - 'simple_form.{yes,no}' +# - 'simple_form.{placeholders,hints,labels}.*' +# - 'simple_form.{error_notification,required}.:' + +## Exclude these keys from `i18n-tasks eq-base' report +# ignore_eq_base: +# all: +# - common.ok +# fr,es: +# - common.brand + +## Exclude these keys from all of the reports +# ignore: +# - kaminari.* diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index eb4ed56e7..21c2733cb 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -1,4 +1,5 @@ I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')] +I18n.default_locale = :en if Rails.env.development? || Rails.env.test? I18n.exception_handler = lambda do |exception, locale, key, options| diff --git a/config/routes.rb b/config/routes.rb index 01600b7ed..360ed2477 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,81 +1,78 @@ Growstuff::Application.routes.draw do - get "/:locale" => 'home#index' + resources :plant_parts + + + devise_for :members, :controllers => { :registrations => "registrations", :passwords => "passwords" } + resources :members + + resources :photos + + resources :authentications + + resources :plantings + match '/plantings/owner/:owner' => 'plantings#index', :as => 'plantings_by_owner' + + resources :gardens + match '/gardens/owner/:owner' => 'gardens#index', :as => 'gardens_by_owner' + + resources :seeds + match '/seeds/owner/:owner' => 'seeds#index', :as => 'seeds_by_owner' + + resources :harvests + match '/harvests/owner/:owner' => 'harvests#index', :as => 'harvests_by_owner' + + resources :posts + match '/posts/author/:author' => 'posts#index', :as => 'posts_by_author' + + resources :scientific_names + + match 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops' + match 'crops/hierarchy' => 'crops#hierarchy', :as => 'crops_hierarchy' + match 'crops/search' => 'crops#search', :as => 'crops_search' + resources :crops + + resources :comments + resources :roles + resources :forums + resources :notifications + + get '/places' => 'places#index' + get '/places/search' => 'places#search', :as => 'search_places' + get '/places/:place' => 'places#show', :as => 'place' + + # everything for paid accounts etc + resources :account_types + resources :accounts + resources :orders + match 'orders/:id/checkout' => 'orders#checkout', :as => 'checkout_order' + match 'orders/:id/complete' => 'orders#complete', :as => 'complete_order' + match 'orders/:id/cancel' => 'orders#cancel', :as => 'cancel_order' + + resources :order_items + resources :products + + get "home/index" root :to => 'home#index' - scope '/:locale' do - - resources :plant_parts - - devise_for :members, :controllers => { :registrations => "registrations", :passwords => "passwords" } - resources :members - - resources :photos - - resources :authentications - - resources :plantings - match '/plantings/owner/:owner' => 'plantings#index', :as => 'plantings_by_owner' - - resources :gardens - match '/gardens/owner/:owner' => 'gardens#index', :as => 'gardens_by_owner' - - resources :seeds - match '/seeds/owner/:owner' => 'seeds#index', :as => 'seeds_by_owner' - - resources :harvests - match '/harvests/owner/:owner' => 'harvests#index', :as => 'harvests_by_owner' - - resources :posts - match '/posts/author/:author' => 'posts#index', :as => 'posts_by_author' - - resources :scientific_names - - match 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops' - match 'crops/hierarchy' => 'crops#hierarchy', :as => 'crops_hierarchy' - match 'crops/search' => 'crops#search', :as => 'crops_search' - resources :crops - - resources :comments - resources :roles - resources :forums - resources :notifications - - get '/places' => 'places#index' - get '/places/search' => 'places#search', :as => 'search_places' - get '/places/:place' => 'places#show', :as => 'place' - - # everything for paid accounts etc - resources :account_types - resources :accounts - resources :orders - match 'orders/:id/checkout' => 'orders#checkout', :as => 'checkout_order' - match 'orders/:id/complete' => 'orders#complete', :as => 'complete_order' - match 'orders/:id/cancel' => 'orders#cancel', :as => 'cancel_order' - - resources :order_items - resources :products - - match 'auth/:provider/callback' => 'authentications#create' + match 'auth/:provider/callback' => 'authentications#create' - match '/policy/:action' => 'policy#:action' + match '/policy/:action' => 'policy#:action' - match '/support' => 'support#index' - match '/support/:action' => 'support#:action' + match '/support' => 'support#index' + match '/support/:action' => 'support#:action' - match '/about' => 'about#index' - match '/about/:action' => 'about#:action' + match '/about' => 'about#index' + match '/about/:action' => 'about#:action' - match '/shop' => 'shop#index' - match '/shop/:action' => 'shop#:action' + match '/shop' => 'shop#index' + match '/shop/:action' => 'shop#:action' - match '/admin/orders' => 'admin/orders#index' - match '/admin/orders/:action' => 'admin/orders#:action' - match '/admin' => 'admin#index' - match '/admin/newsletter' => 'admin#newsletter', :as => :admin_newsletter - match '/admin/:action' => 'admin#:action' + match '/admin/orders' => 'admin/orders#index' + match '/admin/orders/:action' => 'admin/orders#:action' + match '/admin' => 'admin#index' + match '/admin/newsletter' => 'admin#newsletter', :as => :admin_newsletter + match '/admin/:action' => 'admin#:action' - end - -end \ No newline at end of file +end diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb new file mode 100644 index 000000000..0475c9fcc --- /dev/null +++ b/spec/i18n_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' +require 'i18n/tasks' + +describe 'I18n' do + let(:i18n) { I18n::Tasks::BaseTask.new } + let(:missing_keys) { i18n.missing_keys } + let(:unused_keys) { i18n.unused_keys } + + it 'does not have missing keys' do + expect(missing_keys).to be_empty, + "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them" + end + + it 'does not have unused keys' do + expect(i18n.unused_keys).to be_empty, + "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them" + end +end From 16f4d2f80e105f18881238fa42baa69bdd25d612 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Fri, 19 Sep 2014 07:17:08 +1000 Subject: [PATCH 04/22] fix spec to check href with newly added locale query param --- app/controllers/application_controller.rb | 2 +- config/locales/{jp.yml => ja.yml} | 2 +- spec/features/crop_wranglers_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename config/locales/{jp.yml => ja.yml} (94%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 29f5adb35..91fc81413 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -38,8 +38,8 @@ class ApplicationController < ActionController::Base I18n.locale = params[:locale] || I18n.default_locale end + # Adds locale query parameter to every path / url helper def default_url_options(options={}) - logger.debug "default_url_options is passed options: #{options.inspect}\n" { locale: I18n.locale } end diff --git a/config/locales/jp.yml b/config/locales/ja.yml similarity index 94% rename from config/locales/jp.yml rename to config/locales/ja.yml index 89dcea14a..c213277b9 100644 --- a/config/locales/jp.yml +++ b/config/locales/ja.yml @@ -1,2 +1,2 @@ -jp: +ja: blurb: "はガーデナーのコミュニティーです。" diff --git a/spec/features/crop_wranglers_spec.rb b/spec/features/crop_wranglers_spec.rb index 80475bd18..327be7e51 100644 --- a/spec/features/crop_wranglers_spec.rb +++ b/spec/features/crop_wranglers_spec.rb @@ -19,7 +19,7 @@ feature "crop wranglers" do within '.crop_wranglers' do expect(page).to have_content 'Crop Wranglers:' crop_wranglers.each do |crop_wrangler| - page.should have_link crop_wrangler.login_name, :href => member_path(crop_wrangler) + page.should have_link crop_wrangler.login_name, :href => member_path(crop_wrangler, {locale: 'en'}) end end end From 983fa8ede04a81aa25d5426dd07b49850f22674d Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Fri, 19 Sep 2014 07:29:04 +1000 Subject: [PATCH 05/22] abstract strings out of blurb partial --- app/views/home/_blurb.html.haml | 11 +++++------ config/locales/en.yml | 9 ++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/views/home/_blurb.html.haml b/app/views/home/_blurb.html.haml index ba3fd072f..fe06dad9c 100644 --- a/app/views/home/_blurb.html.haml +++ b/app/views/home/_blurb.html.haml @@ -5,15 +5,14 @@ .row .col-md-8.info %p - #{ENV['GROWSTUFF_SITE_NAME']} #{t 'blurb'} + #{ENV['GROWSTUFF_SITE_NAME']} #{t('.intro')} = render :partial => 'stats' .col-md-4.signup - %p Join now for your free garden journal, seed sharing, forums, and more. - %p= link_to 'Sign up', new_member_registration_path, :class => 'btn btn-primary btn-lg' + %p= t('.perks') + %p= link_to "#{t('.sign_up')}", new_member_registration_path, :class => 'btn btn-primary btn-lg' %p %small - Or - = link_to "sign in", new_member_session_path - if you already have an account. + = t('.already') + = link_to "#{t('.sign_in')}", new_member_session_path diff --git a/config/locales/en.yml b/config/locales/en.yml index 4d47f61ab..591ddd0e8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -13,4 +13,11 @@ en: all: "Please sign in or sign up to create a %{subject}." manage: all: "Not authorized to %{action} %{subject}." - blurb: "is a community of food gardeners. We're building an open source platform to help you learn about growing food, track what you plant and harvest, and swap seeds and produce with other gardeners near you." \ No newline at end of file + + home: + blurb: + intro: "is a community of food gardeners. We're building an open source platform to help you learn about growing food, track what you plant and harvest, and swap seeds and produce with other gardeners near you." + perks: "Join now for your free garden journal, seed sharing, forums, and more." + sign_up: "Sign up" + sign_in: "Sign in" + already: "Already have an account?" \ No newline at end of file From e3f590ede5d1cfbf2f0839a039c7f8f52931c6c1 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sat, 20 Sep 2014 21:47:18 +1000 Subject: [PATCH 06/22] abstract strings in home views into locale file --- app/views/home/_blurb.html.haml | 8 ++- app/views/home/_crops.html.haml | 8 +-- app/views/home/_discuss.html.haml | 6 +-- app/views/home/_keep_in_touch.html.haml | 13 ++--- app/views/home/_members.html.haml | 4 +- app/views/home/_open.html.haml | 40 ++++---------- app/views/home/_seeds.html.haml | 18 +++---- app/views/home/_stats.html.haml | 11 ++-- app/views/home/index.html.haml | 17 +++--- config/locales/en.yml | 72 +++++++++++++++++++++++-- 10 files changed, 114 insertions(+), 83 deletions(-) diff --git a/app/views/home/_blurb.html.haml b/app/views/home/_blurb.html.haml index fe06dad9c..3e85b4496 100644 --- a/app/views/home/_blurb.html.haml +++ b/app/views/home/_blurb.html.haml @@ -4,15 +4,13 @@ .row .col-md-8.info - %p - #{ENV['GROWSTUFF_SITE_NAME']} #{t('.intro')} + %p= t('.intro', site_name: ENV['GROWSTUFF_SITE_NAME']) = render :partial => 'stats' .col-md-4.signup %p= t('.perks') - %p= link_to "#{t('.sign_up')}", new_member_registration_path, :class => 'btn btn-primary btn-lg' + %p= link_to(t('.sign_up'), new_member_registration_path, :class => 'btn btn-primary btn-lg') %p %small - = t('.already') - = link_to "#{t('.sign_in')}", new_member_session_path + = t('.already_html', sign_in: link_to(t('.sign_in_linktext'), new_member_session_path)) diff --git a/app/views/home/_crops.html.haml b/app/views/home/_crops.html.haml index 62b6d9e4a..ce3c775ce 100644 --- a/app/views/home/_crops.html.haml +++ b/app/views/home/_crops.html.haml @@ -1,14 +1,14 @@ .row .col-md-6.hidden-xs - cache "interesting_crops", :expires_in => 1.day do - %h2 Some of our crops + %h2= t('.our_crops') - Crop.interesting.each do |c| .col-md-3{:style => 'margin:0px; padding: 3px'} = render :partial => 'crops/image_with_popover', :locals => { :crop => c } .col-md-6 - cache "interesting_plantings" do - %h2 Recently planted + %h2= t('.recently_planted') = render :partial => 'plantings/list', :locals => { :plantings => Planting.interesting.first(4) } .row @@ -16,8 +16,8 @@ - cache "recent_crops" do %p{ :style => 'margin-top: 11.25px' } %strong - Recently added crops: + #{t('.recently_added')}: != Crop.recent.limit(12).map {|c| link_to(c, c) }.join(", ") %p.text-right - =link_to "View all crops »", crops_path + =link_to "#{t('.view_all')} »", crops_path diff --git a/app/views/home/_discuss.html.haml b/app/views/home/_discuss.html.haml index 7da71a54d..22b9972b9 100644 --- a/app/views/home/_discuss.html.haml +++ b/app/views/home/_discuss.html.haml @@ -1,4 +1,4 @@ -%h2 Discussion +%h2= t('.discussion') - cache "recent_posts" do - posts = Post.limit(6) @@ -10,9 +10,9 @@ - if forums %ul.list-inline %li - %strong Forums: + %strong #{t('.forums')}: - forums.each do |f| %li= link_to f.name, f %p.text-right - = link_to "View all posts »", posts_path + = link_to "#{t('.view_all')} »", posts_path diff --git a/app/views/home/_keep_in_touch.html.haml b/app/views/home/_keep_in_touch.html.haml index 34365352b..5bc821887 100644 --- a/app/views/home/_keep_in_touch.html.haml +++ b/app/views/home/_keep_in_touch.html.haml @@ -1,17 +1,14 @@ -%h2 Keep in touch +%h2= t('.keep_in_touch') %p =image_tag("twitter_32.png", :alt => '') - Follow - =link_to '@growstufforg', 'http://twitter.com/growstufforg' - on Twitter. + = t('.twitter_html', link: link_to(t('.twitter_linktext'), 'http://twitter.com/growstufforg')) %p =image_tag("blog_32.png", :alt => '') - Subscribe to the - =link_to 'Growstuff Blog', 'http://blog.growstuff.org/' + = t('.blog_html', link: link_to(t('.blog_linktext'), 'http://blog.growstuff.org/')) %p =image_tag("email_32.png", :alt => '') - Subscribe to our - =link_to 'email newsletter', 'http://blog.growstuff.org/newsletter' + = t('.newsletter_html', link: link_to(t('.newsletter_linktext'), 'http://blog.growstuff.org/newsletter')) + diff --git a/app/views/home/_members.html.haml b/app/views/home/_members.html.haml index 6d3437302..25cb0867b 100644 --- a/app/views/home/_members.html.haml +++ b/app/views/home/_members.html.haml @@ -2,7 +2,7 @@ .hidden-xs - members = Member.interesting.first(6) - if members.present? - %h2 Some of our members + %h2= t('.title') .row - members.each do |m| @@ -10,4 +10,4 @@ = render :partial => "members/thumbnail", :locals => { :member => m } %p.text-right - = link_to "View all members »", members_path + = link_to "#{t('.view_all')} »", members_path diff --git a/app/views/home/_open.html.haml b/app/views/home/_open.html.haml index 0cc44700e..1eeb2d847 100644 --- a/app/views/home/_open.html.haml +++ b/app/views/home/_open.html.haml @@ -1,43 +1,21 @@ -%h2 Open Source +%h2= t('.open_source_title') %p - #{ENV['GROWSTUFF_SITE_NAME']} is open source software, - which means that we share this website's code for free with our - community and the world. We believe that openness, - sustainability, and social good go hand in hand. You can read more - about - =link_to "why Growstuff is open source", "http://blog.growstuff.org/2013/02/20/why-growstuff-is-open-source/" - or check out our code on - =succeed '.' do - = link_to 'Github', 'http://github.com/Growstuff/growstuff' + #{ENV['GROWSTUFF_SITE_NAME']} #{t('.open_source_body_html', why: link_to(t('.why_linktext'), "http://blog.growstuff.org/2013/02/20/why-growstuff-is-open-source/"), github: link_to(t('.github_linktext'), 'http://github.com/Growstuff/growstuff'))} -%h2 Open Data and APIs + +%h2= t('.open_data_title') %p - We're building a database - of crops, planting advice, seed sources, and other information - that anyone can use for free, under a - = succeed '.' do - = link_to 'Creative Commons license', 'http://creativecommons.org/licenses/by-sa/3.0/' - You can use this data for research, to build apps, or for any - purpose at all. Read more about our + = t('.open_data_body_html', creative_commons_link: link_to(t('.creative_commons_linktext'), 'http://creativecommons.org/licenses/by-sa/3.0/'), wiki_link: link_to(t('.wiki_linktext'), 'http://wiki.growstuff.org/index.php/Open_data'), api_docs_link: link_to(t('.api_docs_linktext'), 'http://wiki.growstuff.org/index.php/API')) - = link_to 'open data', 'http://wiki.growstuff.org/index.php/Open_data' - and - = succeed '.' do - = link_to 'API documentation', 'http://wiki.growstuff.org/index.php/API' -%h2 Get Involved + +%h2= t('.get_involved_title') %p - We believe in collaboration, and work closely with our members - and the wider food-growing community. - Our team includes volunteers from all walks of life - and all skill levels. To get involved, visit - = link_to 'Growstuff Talk', 'http://talk.growstuff.org/' - or find more information on the - = succeed "." do - = link_to 'Growstuff Wiki', 'http://wiki.growstuff.org/' + = t('.get_involved_body_html', talk_link: link_to(t('.talk_linktext'), 'http://talk.growstuff.org/'), wiki_link: link_to(t('.wiki_linktext'), 'http://wiki.growstuff.org/')) + %h2 Support Growstuff diff --git a/app/views/home/_seeds.html.haml b/app/views/home/_seeds.html.haml index ccacd0bf4..52d996373 100644 --- a/app/views/home/_seeds.html.haml +++ b/app/views/home/_seeds.html.haml @@ -1,18 +1,18 @@ - seeds = Seed.interesting.first(6) - if seeds.present? - %h2 Seeds available to trade + %h2= t('.title') - cache "interesting_seeds" do - if seeds.length > 0 %table.table.table-striped %tr - %th Owner - %th Crop - %th.hidden-xs.hidden-sm Description - %th Will trade to - %th From location + %th= t('.owner') + %th= t('.crop') + %th.hidden-xs.hidden-sm= t('.description') + %th= t('.trade_to') + %th= t('.from') %th - seeds.each do |seed| @@ -23,8 +23,8 @@ %td= seed.tradable? ? seed.tradable_to : '' %td - if seed.tradable? - = seed.owner.location.blank? ? "unspecified" : truncate(seed.owner.location, :length => 25, :separator => ', ') - %td= link_to 'Details', seed, :class => 'btn btn-default btn-xs' + = seed.owner.location.blank? ? t('.unspecified') : truncate(seed.owner.location, :length => 25, :separator => ', ') + %td= link_to t('.details'), seed, :class => 'btn btn-default btn-xs' %p.text-right - = link_to "View all seeds »", seeds_path + = link_to "#{t('.view_all')} »", seeds_path diff --git a/app/views/home/_stats.html.haml b/app/views/home/_stats.html.haml index 93c16327d..78ab2c0bc 100644 --- a/app/views/home/_stats.html.haml +++ b/app/views/home/_stats.html.haml @@ -1,10 +1,5 @@ - cache("homepage_stats") do %p.stats - So far, - = link_to "#{Member.confirmed.count.to_i} members", members_path - have planted - = link_to "#{Crop.count.to_i} crops", crops_path - = link_to "#{Planting.count.to_i} times", plantings_path - in - = succeed "." do - = link_to "#{Garden.count.to_i} gardens", gardens_path + = t('.message_html', member: link_to(t('.member_linktext', count: Member.confirmed.count.to_i), members_path), number_crops: link_to(t('.number_crops_linktext', count: Crop.count.to_i), crops_path), number_plantings: link_to(t('.number_plantings_linktext', count: Planting.count.to_i), plantings_path), number_gardens: link_to(t('.number_gardens_linktext', count: Garden.count.to_i), gardens_path)) + + diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 57fb6473f..f36a29aab 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1,19 +1,16 @@ .row .col-md-12 - if member_signed_in? - %h1 - Welcome to - = succeed "," do - = ENV['GROWSTUFF_SITE_NAME'] - = current_member + %h1= t('.welcome', site_name: ENV['GROWSTUFF_SITE_NAME'], member_name: current_member) + = render :partial => 'stats' %p .btn-group - = link_to "Plant", new_planting_path, :class => 'btn btn-default' - = link_to "Harvest", new_harvest_path, :class => 'btn btn-default' - = link_to "Add seeds", new_seed_path, :class => 'btn btn-default' - = link_to "Post", new_post_path, :class => 'btn btn-default' - = link_to "Edit profile", edit_member_registration_path, :class => 'btn btn-default' + = link_to t('.plant'), new_planting_path, :class => 'btn btn-default' + = link_to t('.harvest'), new_harvest_path, :class => 'btn btn-default' + = link_to t('.add_seeds'), new_seed_path, :class => 'btn btn-default' + = link_to t('.post'), new_post_path, :class => 'btn btn-default' + = link_to t('.edit_profile'), edit_member_registration_path, :class => 'btn btn-default' - else .hidden-xs diff --git a/config/locales/en.yml b/config/locales/en.yml index 591ddd0e8..9b650e582 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -16,8 +16,74 @@ en: home: blurb: - intro: "is a community of food gardeners. We're building an open source platform to help you learn about growing food, track what you plant and harvest, and swap seeds and produce with other gardeners near you." + intro: "%{site_name} is a community of food gardeners. We're building an open source platform to help you learn about growing food, track what you plant and harvest, and swap seeds and produce with other gardeners near you." perks: "Join now for your free garden journal, seed sharing, forums, and more." sign_up: "Sign up" - sign_in: "Sign in" - already: "Already have an account?" \ No newline at end of file + already_html: "Or %{sign_in} if you already have an account" + sign_in_linktext: "sign in" + + crops: + our_crops: "Some of our crops" + recently_planted: "Recently planted" + recently_added: "Recently added crops" + view_all: "View all crops" + + discuss: + discussion: "Discussion" + forums: "Forums" + view_all: "View all posts" + + keep_in_touch: + keep_in_touch: "Keep in touch" + twitter_html: "Follow %{link} on Twitter" + twitter_linktext: "@growstufforg" + blog_html: "Subscribe to the %{link}" + blog_linktext: "Growstuff Blog" + newsletter_html: "Subscribe to our %{link}" + newsletter_linktext: "email newsletter" + + members: + title: "Some of our members" + view_all: "View all members" + + open: + open_source_title: "Open Source" + open_source_body_html: "is open source software, which means that we share this website's code for free with our community and the world. We believe that openness, sustainability, and social good go hand in hand. You can read more about %{why} or check out our code on %{github}." + why_linktext: "why Growstuff is open source" + github_linktext: "Github" + open_data_title: "Open Data and APIs" + open_data_body_html: "We're building a database of crops, planting advice, seed sources, and other information that anyone can use for free, under a %{creative_commons_link}. You can use this data for research, to build apps, or for any purpose at all. Read more about our %{wiki_link} and %{api_docs_link}." + creative_commons_linktext: "Creative Commons license" + wiki_linktext: "open data" + api_docs_linktext: "API documentation" + get_involved_title: "Get Involved" + get_involved_body_html: "We believe in collaboration, and work closely with our members and the wider food-growing community. Our team includes volunteers from all walks of life and all skill levels. To get involved, visit %{talk_link} or find more information on the %{wiki_link}." + talk_linktext: "Growstuff Talk" + wiki_linktext: "Growstuff Wiki" + + seeds: + title: "Seeds available to trade" + owner: "Owner" + crop: "Crop" + description: "Description" + trade_to: "Will trade to" + from: "From location" + unspecified: "unspecified" + details: "Details" + view_all: "View all seeds" + + stats: + message_html: "So far, %{member} have planted %{number_crops} %{number_plantings} in %{number_gardens}." + member_linktext: "%{count} members" + number_crops_linktext: "%{count} crops" + number_plantings_linktext: "%{count} times" + number_gardens_linktext: "%{count} gardens" + + index: + welcome: "Welcome to %{site_name}, %{member_name}" + plant: "Plant" + harvest: "Harvest" + add_seeds: "Add seeds" + post: "Post" + edit_profile: "Edit profile" + From 659a68cf3971b6894f7f557d7f00921722c98a6a Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sat, 20 Sep 2014 21:49:30 +1000 Subject: [PATCH 07/22] remove missing translations spec in favor of running dedicated task --- spec/i18n_spec.rb | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 spec/i18n_spec.rb diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb deleted file mode 100644 index 0475c9fcc..000000000 --- a/spec/i18n_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'spec_helper' -require 'i18n/tasks' - -describe 'I18n' do - let(:i18n) { I18n::Tasks::BaseTask.new } - let(:missing_keys) { i18n.missing_keys } - let(:unused_keys) { i18n.unused_keys } - - it 'does not have missing keys' do - expect(missing_keys).to be_empty, - "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them" - end - - it 'does not have unused keys' do - expect(i18n.unused_keys).to be_empty, - "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them" - end -end From e3a6742574dde7b905356203a1c23ef7623f0fae Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sat, 20 Sep 2014 21:56:14 +1000 Subject: [PATCH 08/22] add sample japanese locale file to test changing languages --- config/locales/ja.yml | 74 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/config/locales/ja.yml b/config/locales/ja.yml index c213277b9..6c7d63b8f 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1,2 +1,74 @@ ja: - blurb: "はガーデナーのコミュニティーです。" + home: + blurb: + intro: "%{site_name}はガーデナーのコミュニティです。" + perks: "翻訳中" + sign_up: "翻訳中" + already_html: "翻訳中" + sign_in_linktext: "翻訳中" + + crops: + our_crops: "翻訳中" + recently_planted: "翻訳中" + recently_added: "翻訳中" + view_all: "翻訳中" + + discuss: + discussion: "翻訳中" + forums: "翻訳中" + view_all: "翻訳中" + + keep_in_touch: + keep_in_touch: "翻訳中" + twitter_html: "翻訳中" + twitter_linktext: "翻訳中" + blog_html: "翻訳中" + blog_linktext: "翻訳中" + newsletter_html: "翻訳中" + newsletter_linktext: "翻訳中" + + members: + title: "翻訳中" + view_all: "翻訳中" + + open: + open_source_title: "翻訳中" + open_source_body_html: "翻訳中" + why_linktext: "翻訳中" + github_linktext: "翻訳中" + open_data_title: "翻訳中" + open_data_body_html: "翻訳中" + creative_commons_linktext: "翻訳中" + wiki_linktext: "翻訳中" + api_docs_linktext: "翻訳中" + get_involved_title: "翻訳中" + get_involved_body_html: "翻訳中" + talk_linktext: "翻訳中" + wiki_linktext: "翻訳中" + + seeds: + title: "翻訳中" + owner: "翻訳中" + crop: "翻訳中" + description: "翻訳中" + trade_to: "翻訳中" + from: "翻訳中" + unspecified: "翻訳中" + details: "翻訳中" + view_all: "翻訳中" + + stats: + message_html: "翻訳中" + member_linktext: "翻訳中" + number_crops_linktext: "翻訳中" + number_plantings_linktext: "翻訳中" + number_gardens_linktext: "翻訳中" + + index: + welcome: "翻訳中" + plant: "翻訳中" + harvest: "翻訳中" + add_seeds: "翻訳中" + post: "翻訳中" + edit_profile: "翻訳中" + From 93cd067fff99086cfb7d4d99ce9b3f67e2fa770a Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sat, 20 Sep 2014 21:59:05 +1000 Subject: [PATCH 09/22] add two contributors --- CONTRIBUTORS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 5bd5cc601..8473e9f2a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -45,3 +45,5 @@ submit the change with your pull request. - Marlena Compton / [Marlena](https://github.com/marlena) - Elizabeth A. Kari / [catfriend](https://github.com/catfriend) - Cheri Allen / [cherimarie](https://github.com/cherimarie) +- Shiho Takagi / [oshiho3](https:://github.com/oshiho3) +- Maki Sugita / [macckii](https:://github.com/macckii) From 1acba65a8b01f74292eca50ac038e2701fa6a085 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sun, 21 Sep 2014 10:22:46 +1000 Subject: [PATCH 10/22] clean up haml a bit --- app/views/home/_open.html.haml | 11 ++++++++--- app/views/home/_stats.html.haml | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/views/home/_open.html.haml b/app/views/home/_open.html.haml index 1eeb2d847..f53c32675 100644 --- a/app/views/home/_open.html.haml +++ b/app/views/home/_open.html.haml @@ -1,20 +1,25 @@ %h2= t('.open_source_title') %p - #{ENV['GROWSTUFF_SITE_NAME']} #{t('.open_source_body_html', why: link_to(t('.why_linktext'), "http://blog.growstuff.org/2013/02/20/why-growstuff-is-open-source/"), github: link_to(t('.github_linktext'), 'http://github.com/Growstuff/growstuff'))} + = ENV['GROWSTUFF_SITE_NAME'] + = t('.open_source_body_html', why: link_to(t('.why_linktext'), 'http://blog.growstuff.org/2013/02/20/why-growstuff-is-open-source/'), + github: link_to(t('.github_linktext'), 'http://github.com/Growstuff/growstuff') ) %h2= t('.open_data_title') %p - = t('.open_data_body_html', creative_commons_link: link_to(t('.creative_commons_linktext'), 'http://creativecommons.org/licenses/by-sa/3.0/'), wiki_link: link_to(t('.wiki_linktext'), 'http://wiki.growstuff.org/index.php/Open_data'), api_docs_link: link_to(t('.api_docs_linktext'), 'http://wiki.growstuff.org/index.php/API')) + = t('.open_data_body_html', creative_commons_link: link_to(t('.creative_commons_linktext'), 'http://creativecommons.org/licenses/by-sa/3.0/'), + wiki_link: link_to(t('.wiki_linktext'), 'http://wiki.growstuff.org/index.php/Open_data'), + api_docs_link: link_to(t('.api_docs_linktext'), 'http://wiki.growstuff.org/index.php/API')) %h2= t('.get_involved_title') %p - = t('.get_involved_body_html', talk_link: link_to(t('.talk_linktext'), 'http://talk.growstuff.org/'), wiki_link: link_to(t('.wiki_linktext'), 'http://wiki.growstuff.org/')) + = t('.get_involved_body_html', talk_link: link_to(t('.talk_linktext'), 'http://talk.growstuff.org/'), + wiki_link: link_to(t('.wiki_linktext'), 'http://wiki.growstuff.org/')) %h2 Support Growstuff diff --git a/app/views/home/_stats.html.haml b/app/views/home/_stats.html.haml index 78ab2c0bc..e13f74719 100644 --- a/app/views/home/_stats.html.haml +++ b/app/views/home/_stats.html.haml @@ -1,5 +1,8 @@ - cache("homepage_stats") do %p.stats - = t('.message_html', member: link_to(t('.member_linktext', count: Member.confirmed.count.to_i), members_path), number_crops: link_to(t('.number_crops_linktext', count: Crop.count.to_i), crops_path), number_plantings: link_to(t('.number_plantings_linktext', count: Planting.count.to_i), plantings_path), number_gardens: link_to(t('.number_gardens_linktext', count: Garden.count.to_i), gardens_path)) + = t('.message_html', { member: link_to(t('.member_linktext', count: Member.confirmed.count.to_i), members_path), + number_crops: link_to(t('.number_crops_linktext', count: Crop.count.to_i), crops_path), + number_plantings: link_to(t('.number_plantings_linktext', count: Planting.count.to_i), plantings_path), + number_gardens: link_to(t('.number_gardens_linktext', count: Garden.count.to_i), gardens_path) }) From d4622540219da913ab90fd95fd78f22c3d36fc35 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sun, 21 Sep 2014 10:26:30 +1000 Subject: [PATCH 11/22] add missing translation --- app/views/home/_open.html.haml | 10 +++------- config/locales/en.yml | 4 ++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/home/_open.html.haml b/app/views/home/_open.html.haml index f53c32675..b14bfa83b 100644 --- a/app/views/home/_open.html.haml +++ b/app/views/home/_open.html.haml @@ -22,12 +22,8 @@ wiki_link: link_to(t('.wiki_linktext'), 'http://wiki.growstuff.org/')) -%h2 Support Growstuff +%h2= t('.support_title') %p - Growstuff is independent, - =succeed "," do - =link_to 'ad-free', 'http://wiki.growstuff.org/index.php/Why_no_ads%3F' - and we have no outside investment. You can support our work by - =succeed "." do - =link_to 'buying a paid account', shop_path + = t('.support_body_html', ad_free: link_to(t('.ad_free_linktext'), 'http://wiki.growstuff.org/index.php/Why_no_ads%3F'), + buy_account: link_to(t('.buy_account_linktext'), shop_path)) diff --git a/config/locales/en.yml b/config/locales/en.yml index 9b650e582..b32bd931f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -60,6 +60,10 @@ en: get_involved_body_html: "We believe in collaboration, and work closely with our members and the wider food-growing community. Our team includes volunteers from all walks of life and all skill levels. To get involved, visit %{talk_link} or find more information on the %{wiki_link}." talk_linktext: "Growstuff Talk" wiki_linktext: "Growstuff Wiki" + support_title: "Support Growstuff" + support_body_html: "Growstuff is independent, %{ad_free} and we have no outside investment. You can support our work by %{buy_account}." + ad_free_linktext: "ad-free" + buy_account_linktext: "buying a paid account" seeds: title: "Seeds available to trade" From 5e48c4392ab80040d53cf941cf7b5f7568fef2a7 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Wed, 24 Sep 2014 18:29:59 +1000 Subject: [PATCH 12/22] move site name into localization --- app/views/home/_open.html.haml | 4 ++-- config/locales/en.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/home/_open.html.haml b/app/views/home/_open.html.haml index b14bfa83b..fa7c00f57 100644 --- a/app/views/home/_open.html.haml +++ b/app/views/home/_open.html.haml @@ -1,9 +1,9 @@ %h2= t('.open_source_title') %p - = ENV['GROWSTUFF_SITE_NAME'] = t('.open_source_body_html', why: link_to(t('.why_linktext'), 'http://blog.growstuff.org/2013/02/20/why-growstuff-is-open-source/'), - github: link_to(t('.github_linktext'), 'http://github.com/Growstuff/growstuff') ) + github: link_to(t('.github_linktext'), 'http://github.com/Growstuff/growstuff'), + site_name: ENV['GROWSTUFF_SITE_NAME'] ) %h2= t('.open_data_title') diff --git a/config/locales/en.yml b/config/locales/en.yml index b32bd931f..39bb974ff 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -48,7 +48,7 @@ en: open: open_source_title: "Open Source" - open_source_body_html: "is open source software, which means that we share this website's code for free with our community and the world. We believe that openness, sustainability, and social good go hand in hand. You can read more about %{why} or check out our code on %{github}." + open_source_body_html: "%{site_name} is open source software, which means that we share this website's code for free with our community and the world. We believe that openness, sustainability, and social good go hand in hand. You can read more about %{why} or check out our code on %{github}." why_linktext: "why Growstuff is open source" github_linktext: "Github" open_data_title: "Open Data and APIs" From 984503480f074fcdb9218cd9458efec983845878 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Thu, 25 Sep 2014 07:00:11 +1000 Subject: [PATCH 13/22] remove necessity to add locale to url if current locale is English --- app/controllers/application_controller.rb | 6 +++++- spec/features/crop_wranglers_spec.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 91fc81413..8fbc8ba95 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -40,7 +40,11 @@ class ApplicationController < ActionController::Base # Adds locale query parameter to every path / url helper def default_url_options(options={}) - { locale: I18n.locale } + if I18n.locale == :en + {} + else + { locale: I18n.locale } + end end end diff --git a/spec/features/crop_wranglers_spec.rb b/spec/features/crop_wranglers_spec.rb index 327be7e51..80475bd18 100644 --- a/spec/features/crop_wranglers_spec.rb +++ b/spec/features/crop_wranglers_spec.rb @@ -19,7 +19,7 @@ feature "crop wranglers" do within '.crop_wranglers' do expect(page).to have_content 'Crop Wranglers:' crop_wranglers.each do |crop_wrangler| - page.should have_link crop_wrangler.login_name, :href => member_path(crop_wrangler, {locale: 'en'}) + page.should have_link crop_wrangler.login_name, :href => member_path(crop_wrangler) end end end From d10a62d336405c88418247ec56f960becd346764 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sun, 28 Sep 2014 21:32:15 +1000 Subject: [PATCH 14/22] set locale from subdomain --- app/controllers/application_controller.rb | 21 +++++++++++++-------- config/locales/ja.yml | 4 ++++ spec/features/signup_spec.rb | 13 +++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 spec/features/signup_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8fbc8ba95..56db2c730 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -35,16 +35,21 @@ class ApplicationController < ActionController::Base end def set_locale - I18n.locale = params[:locale] || I18n.default_locale + I18n.locale = extract_locale_tld || I18n.default_locale + end + + def extract_locale_tld + parsed_locale = request.subdomains.first + I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale : nil end # Adds locale query parameter to every path / url helper - def default_url_options(options={}) - if I18n.locale == :en - {} - else - { locale: I18n.locale } - end - end + # def default_url_options(options={}) + # if I18n.locale == :en + # {} + # else + # { locale: I18n.locale } + # end + # end end diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 6c7d63b8f..6ca6eaf88 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -45,6 +45,10 @@ ja: get_involved_body_html: "翻訳中" talk_linktext: "翻訳中" wiki_linktext: "翻訳中" + support_title: "翻訳中" + support_body_html: "翻訳中" + ad_free_linktext: "翻訳中" + buy_account_linktext: "翻訳中" seeds: title: "翻訳中" diff --git a/spec/features/signup_spec.rb b/spec/features/signup_spec.rb new file mode 100644 index 000000000..d3be7e17f --- /dev/null +++ b/spec/features/signup_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +feature "signup" do + + scenario "signup" do + visit root_path + first('.signup a').click + + expect(current_path).to eq(new_member_registration_path) + end + + +end From f9dc17c5875633594079fd6d4bea64521e65463f Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sun, 28 Sep 2014 21:34:26 +1000 Subject: [PATCH 15/22] no longer raise exception on missing g translation in dev / test envs --- config/initializers/locale.rb | 5 ----- config/locales/ja.yml | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index 21c2733cb..fb251b800 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -1,9 +1,4 @@ I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')] I18n.default_locale = :en -if Rails.env.development? || Rails.env.test? - I18n.exception_handler = lambda do |exception, locale, key, options| - raise "Missing translation: #{key}" - end -end \ No newline at end of file diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 6ca6eaf88..1f2fe3247 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -48,7 +48,7 @@ ja: support_title: "翻訳中" support_body_html: "翻訳中" ad_free_linktext: "翻訳中" - buy_account_linktext: "翻訳中" + seeds: title: "翻訳中" From a7da4b9ce41ac5e1ccec0723d456085778e8d0f5 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sun, 28 Sep 2014 21:38:28 +1000 Subject: [PATCH 16/22] no longer necessary to pass locale quuery param in every url --- app/controllers/application_controller.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 56db2c730..1b27f01fc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -43,13 +43,4 @@ class ApplicationController < ActionController::Base I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale : nil end - # Adds locale query parameter to every path / url helper - # def default_url_options(options={}) - # if I18n.locale == :en - # {} - # else - # { locale: I18n.locale } - # end - # end - end From aebd9e1d4e8a95a65c33ea0f03de5f701fddae85 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Sun, 28 Sep 2014 22:03:50 +1000 Subject: [PATCH 17/22] remove a file that accidentally found its way in from another unrelated branch --- spec/features/signup_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 spec/features/signup_spec.rb diff --git a/spec/features/signup_spec.rb b/spec/features/signup_spec.rb deleted file mode 100644 index d3be7e17f..000000000 --- a/spec/features/signup_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' - -feature "signup" do - - scenario "signup" do - visit root_path - first('.signup a').click - - expect(current_path).to eq(new_member_registration_path) - end - - -end From 6a7c935d43e8de4e818ff9435f4adb420cd1aa79 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Thu, 16 Oct 2014 06:37:02 +1100 Subject: [PATCH 18/22] try setting locale from query parameter first --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1b27f01fc..e417984fa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -35,10 +35,10 @@ class ApplicationController < ActionController::Base end def set_locale - I18n.locale = extract_locale_tld || I18n.default_locale + I18n.locale = params[:locale] || extract_locale_from_subdomain || I18n.default_locale end - def extract_locale_tld + def extract_locale_from_subdomain parsed_locale = request.subdomains.first I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale : nil end From 0f75a969447e087b0c8607cd18854551bc0264f0 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Thu, 16 Oct 2014 06:37:50 +1100 Subject: [PATCH 19/22] write spec to test that setting a different locale fundamentally works --- spec/features/locale_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 spec/features/locale_spec.rb diff --git a/spec/features/locale_spec.rb b/spec/features/locale_spec.rb new file mode 100644 index 000000000..bffedfb75 --- /dev/null +++ b/spec/features/locale_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +feature "Changing locales" do + + scenario "Locale can be set with a query param" do + visit "/" + expect(page).to have_content("Growstuff (dev) is a community of food gardeners.") + visit "/?locale=ja" + expect(page).to have_content("Growstuff (dev)はガーデナーのコミュニティです。") + end + +end \ No newline at end of file From d627d8394e2c3584a366016d30e0084beec4e117 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Thu, 16 Oct 2014 06:56:39 +1100 Subject: [PATCH 20/22] forgot which env I was in --- spec/features/locale_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/locale_spec.rb b/spec/features/locale_spec.rb index bffedfb75..8e7aad90c 100644 --- a/spec/features/locale_spec.rb +++ b/spec/features/locale_spec.rb @@ -4,9 +4,9 @@ feature "Changing locales" do scenario "Locale can be set with a query param" do visit "/" - expect(page).to have_content("Growstuff (dev) is a community of food gardeners.") + expect(page).to have_content("Growstuff (test) is a community of food gardeners.") visit "/?locale=ja" - expect(page).to have_content("Growstuff (dev)はガーデナーのコミュニティです。") + expect(page).to have_content("Growstuff (test)はガーデナーのコミュニティです。") end end \ No newline at end of file From 8994bcf28cf98728f190de6eb9f2bc46a39bf75b Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Thu, 16 Oct 2014 07:14:03 +1100 Subject: [PATCH 21/22] ok, we'll just remove all references to environment --- spec/features/locale_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/locale_spec.rb b/spec/features/locale_spec.rb index 8e7aad90c..37f1b9905 100644 --- a/spec/features/locale_spec.rb +++ b/spec/features/locale_spec.rb @@ -4,9 +4,9 @@ feature "Changing locales" do scenario "Locale can be set with a query param" do visit "/" - expect(page).to have_content("Growstuff (test) is a community of food gardeners.") + expect(page).to have_content("a community of food gardeners.") visit "/?locale=ja" - expect(page).to have_content("Growstuff (test)はガーデナーのコミュニティです。") + expect(page).to have_content("はガーデナーのコミュニティです。") end end \ No newline at end of file From 2515d34277a3420d71d25ab0553cc53b3e3c752b Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Thu, 16 Oct 2014 08:09:20 +1100 Subject: [PATCH 22/22] add teardown to reset locale to default en --- spec/features/locale_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/features/locale_spec.rb b/spec/features/locale_spec.rb index 37f1b9905..9a787f6cc 100644 --- a/spec/features/locale_spec.rb +++ b/spec/features/locale_spec.rb @@ -2,6 +2,10 @@ require 'spec_helper' feature "Changing locales" do + after do + I18n.locale = :en + end + scenario "Locale can be set with a query param" do visit "/" expect(page).to have_content("a community of food gardeners.")