Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Introduce I18n to Hacktoberfest #675

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ gem 'faraday_middleware'

gem 'health_check'

gem "i18n", "~> 1.6"

gem 'jbuilder', '~> 2.5'

gem 'kramdown'
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ DEPENDENCIES
figaro
guard-rspec
health_check
i18n (~> 1.6)
jbuilder (~> 2.5)
kramdown
listen (>= 3.0.5, < 3.2)
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class ApplicationController < ActionController::Base
before_action :set_current_user
around_action :switch_locale
rescue_from Faraday::ClientError, with: :api_error
rescue_from Octokit::Unauthorized, with: :github_unauthorized_error
rescue_from Octokit::ServerError, with: :api_error
Expand Down Expand Up @@ -49,8 +50,17 @@ def disallow_registered_user!
redirect_to profile_path
end

def default_url_options
{ locale: I18n.locale }
end

private

def switch_locale(&action)
locale = params[:locale] || I18n.default_locale
I18n.with_locale(locale, &action)
end

def valid_token?
TokenValidatorService.new(@current_user.provider_token).valid?
end
Expand Down
92 changes: 33 additions & 59 deletions app/views/pages/homepage/closing_homepage.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<section class="home-hero">
<div class="hero-content">
<h1 class="title is-1">
<span class="highlight">Support open source</span> and pick a limited edition T-shirt or plant a tree.
<%= t('.support_for_free_tree_or_shirt_html') %>
</h1>
<%= link_to "start hacking", login_path, :class => active_path_class?(profile_path, '') + " button" %>
<%= link_to t('.start_hacking'), login_path, :class => active_path_class?(profile_path, '') + " button" %>
<div class="presented-by">
<p>Presented by</p>
<p><%= t '.presented_by' %></p>
<a href="https://www.digitalocean.com">
<img alt="DigitalOcean logo" class="header-do-logo">
</a>
Expand Down Expand Up @@ -43,59 +43,45 @@
<section class="home-event-details">
<div class="container">
<h2 class="title is-2" id="event-details">
<a href="#event-details">Event details</a>
<a href="#event-details"><%= t('.event_details') %></a>
</h2>
<p>
Hacktoberfest<span class="reg">&reg;</span> is open to everyone in our global community. Whether you’re a
developer, student learning to code, event host, or company of any size, you can help drive growth of open
source and make positive contributions to an ever-growing community. All backgrounds and skill levels are
encouraged to complete the challenge.
</p>
<p><%= t('.event_details_intro') %></p>
<ul>
<li class="bullet">
<span>Hacktoberfest is a celebration <strong>open to everyone</strong> in our global community.</span>
<span><%= t('.event_details_open_to_all_html') %></span>
</li>
<li class="bullet">
<span>
Pull requests can be made in <strong>participating GitHub-hosted repositories/projects</strong>,
classified with the Hacktoberfest topic.
<%= t('.event_details_participating_repos_html') %>
</span>
</li>
<li class="bullet">
<span>You can sign up anytime between October 1 and October 31.</span>
<span><%= t('.event_details_signup_timeline_html') %></span>
</li>
</ul>

<h2 class="title is-2" id="rules">
<a href="#rules">Rules</a>
<a href="#rules"><%= t('.rules_title') %></a>
</h2>
<p>
To earn your Hacktoberfest tee or tree reward, you must register and make four valid pull requests (PRs) between
October 1-31 (in any time zone). PRs can be made to participating public repos on GitHub, those that have the
Hacktoberfest topic. If a maintainer reports your pull request as spam or behavior not in line with the
project’s code of conduct, you will be ineligible to participate. This year, the first 70,000 participants who
successfully complete the challenge will be eligible to receive a prize.
<%= t('.rules') %>
</p>
<p>Read the <%= link_to 'participation details', details_path, :class => "participation-link" %> to learn how to
earn your Hacktoberfest tee or tree reward.</p>
<p><%= raw t('.read_participation_details', participation_details_link: "#{link_to t('.participation_details_link'), details_path, class: 'participation-link'}") %></p>
</div>
</section>

<section class="home-projects">
<div class="container">
<h2 class="title is-2" id="projects">
<a href="#projects">Hacktoberfest projects</a>
<a href="#projects"><%= t('.hacktoberfest_projects') %></a>
</h2>
<p>
You can contribute to participating projects on GitHub. Here are a few looking for some help:
</p>
<p><%= t('.participating_projects_list') %></p>
<% if @projects.empty? %>
<br/>
<p>
<i>
Sorry, we couldn't load any projects to highlight at this time.
<br/>
Click the button below to browse for projects directly on GitHub.
<i><%= t('.cannot_load_projects') %>
<br />
<%= t('.click_to_browse_projects') %>
</i>
</p>
<br/>
Expand All @@ -106,31 +92,29 @@
<div class="field">
<div class="control">
<div class="select">
<%= collection_select(:language, :id, Language.all.sort_by(&:name), :id, :name, prompt: "Select language", html_options: {class: 'language-dropdown'}) %>
<%= collection_select(:language, :id, Language.all.sort_by(&:name), :id, :name, prompt: t('.select_language'), html_options: {class: 'language-dropdown'}) %>
</div>
</div>
</div>
<button type="button" class="button button-small" id="reset-filter">Remove filter</button>
<button type="button" class="button button-small" id="reset-filter"><%= t('.remove_filter') %></button>
</div>
</div>
<div class="grid" id="project-list">
<%= render partial: 'languages/all_projects', locals: {projects: @projects} %>
</div>
<% end %>
<a href="https://github.com/topics/hacktoberfest" class="button">
Browse <%= @projects.empty? ? 'projects' : 'more' %> on GitHub
<%= t('.browse_github', count: @projects.count) %>
</a>
</div>
</section>

<section class="home-special-projects">
<div class="container">
<h2 class="title is-2 featured" id="featured">
<a href="#featured">Projects focused on climate change & COVID-19 relief</a>
<a href="#featured"><%= t('.featured_projects_title') %></a>
</h2>
<p>
Featured projects focused on tackling climate change and supporting the fight against COVID-19.
</p>
<p><%= t('.featured_projects_description')%></p>
<div class="grid">
<% @featured_projects.map do |repository| %>
<a href="<%= repository['Repo URL'] %>">
Expand All @@ -145,7 +129,7 @@
<% end %>
</div>
<a href="https://github.com/topics/climate-change" class="button">
Browse more on GitHub
<%= t('.browse_github') %>
</a>
</div>
</section>
Expand All @@ -154,13 +138,9 @@
<div class="container">
<div class="events">
<h2 class="title is-2" id="events">
<a href="#events">Global events</a>
<a href="#events"><%= t('.global_events') %></a>
</h2>
<p>
Celebrate and support open source technology by
<a href="https://hacktoberfest.digitalocean.com/eventkit">organizing</a> or
<a href="https://hacktoberfest.digitalocean.com/events">attending</a> a virtual event in October.
</p>
<p><%= t('.organize_or_paricipate_in_event_html')%></p>
<div class="event-union">
<% @events.map do |e| %>
<a class="box grow-shadow" href="<%= e.url %>">
Expand All @@ -183,7 +163,7 @@
<% end %>
</div>
<div id="eventmap" style="max-width: 1170px; height: 470px;"></div>
<%= link_to 'See more events', events_path, :class => 'button' %>
<%= link_to t('.see_more_events'), events_path, :class => 'button' %>
</div>
</div>
</section>
Expand All @@ -193,35 +173,29 @@
<div class="grid sponsor-quotes">
<div class="box">
<h6 class="title is-6">
From DigitalOcean
<%= t('.sponsor_digital_ocean_from') %>
</h6>
<a href="https://www.digitalocean.com/"><img alt="DigitalOcean logo" class="sponsors-digitalocean"/></a>
<p>
Now in its 7th year, Hacktoberfest has become an integral thread in our company fabric. We wouldn’t be here
without the passionate community and helpful partners that make this program such a spectacular event. A big
thank you to all that are joining for the first time and those that keep coming back year after year.
<%= t('.sponsor_digital_ocean_message') %>
</p>
</div>
<div class="box">
<h6 class="title is-6">
From Intel
<%= raw t('.sponsor_intel_from') %>
</h6>
<a href="/intel.pdf"><img alt="Intel logo" class="sponsors-intel"/></a>
<p>
Did you know that Intel is among the top ten contributors to open-source software? <br/> <br/>
We’re honored to join the Hacktoberfest celebration this year to build on this foundation along with
hundreds of thousands of software engineers around the world.
<%= raw t('.sponsor_intel_message') %>
</p>
</div>
<div class="box">
<h6 class="title is-6">
From Dev
<%= t('.sponsor_dev_from') %>
</h6>
<a href="https://github.com/forem/forem"><img alt="DEV logo" class="sponsors-dev"/></a>
<p>
DEV/Forem is proud to support Hacktoberfest, a truly wonderful celebration of open-source. Whether you're an
individual contributor or a project maintainer, please join us on DEV to share your Hacktoberfest journey.
We can't wait to see you there.
<%= raw t('.sponsor_dev_message') %>
</p>
</div>
</div>
Expand Down Expand Up @@ -284,7 +258,7 @@
<section class="social">
<%= image_tag("HF-full-logo.svg", :alt => "Hacktoberfest Logo") %>
<div class="social-wrapper">
<p>Spread the word</p>
<p><%= t('.spread_the_word') %></p>
<div class="social-share-icons">
<a class="social-circle" href="https://ctt.ac/Vu1a7">
<img alt="twitter" class="social-share-twitter"/>
Expand All @@ -301,7 +275,7 @@
<div class="social-CTA">
<a class="button" href="https://discord.gg/hacktoberfest">
<%= image_tag("footer-social-discord.svg", :alt => "Discord Logo") %>
Join the conversation
<%= t('.join_discord') %>
</a>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

config.active_record.verbose_query_logs = true

config.action_view.raise_on_missing_translations = true

config.assets.debug = true

config.assets.quiet = true
Expand Down
87 changes: 55 additions & 32 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# The following keys must be escaped otherwise they will not be retrieved by
# the default I18n backend:
#
# true, false, on, off, yes, no
#
# Instead, surround them with single quotes.
#
# en:
# 'true': 'foo'
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
pages:
homepage:
closing_homepage:
browse_github:
zero: "Browse more on GitHub"
other: "Browse projects on GitHub"
cannot_load_projects: "Sorry, we couldn't load any projects to highlight at this time."
click_to_browse_projects: "Click the button below to browse for projects directly on GitHub."
event_details: "Event details"
event_details_intro: 'Hacktoberfest® is open to everyone in our global community. Whether you’re a
developer, student learning to code, event host, or company of any size, you can help drive growth of open
source and make positive contributions to an ever-growing community. All backgrounds and skill levels are
encouraged to complete the challenge.'
event_details_open_to_all_html: 'Hacktoberfest is a celebration <strong>open to everyone</strong> in our global community.'
event_details_participating_repos_html: 'Pull requests can be made in <strong>participating GitHub-hosted repositories/projects</strong>,
classified with the Hacktoberfest topic.'
event_details_signup_timeline_html: 'You can sign up anytime between October 1 and October 31.'
featured_projects_title: 'Projects focused on climate change & COVID-19 relief'
featured_projects_description: "Featured projects focused on tackling climate change and supporting the fight against COVID-19."
global_events: 'Global events'
hacktoberfest: "Hacktoberfest"
hacktoberfest_projects: "Hacktoberfest projects"
join_discord: "Join the conversation"
organize_or_paricipate_in_event_html: 'Celebrate and support open source technology by
<a href="https://hacktoberfest.digitalocean.com/eventkit">organizing</a> or
<a href="https://hacktoberfest.digitalocean.com/events">attending</a> a virtual event in October.'
participating_projects_list: "You can contribute to participating projects on GitHub. Here are a few looking for some help:"
participation_details_link: "participation details"
presented_by: "Presented by"
read_participation_details: "Read the %{participation_details_link} to learn how to
earn your Hacktoberfest tee or tree reward."
remove_filter: 'Remove filter'
rules: 'To earn your Hacktoberfest tee or tree reward, you must register and make four valid pull requests (PRs) between
October 1-31 (in any time zone). PRs can be made to participating public repos on GitHub, those that have the
Hacktoberfest topic. If a maintainer reports your pull request as spam or behavior not in line with the
project’s code of conduct, you will be ineligible to participate. This year, the first 70,000 participants who
successfully complete the challenge will be eligible to receive a prize.'
rules_title: 'Rules'
see_more_events: 'See more events'
select_language: "Select language"
spread_the_word: "Spread the word"
sponsor_dev_from: "From Dev"
sponsor_dev_message: "DEV/Forem is proud to support Hacktoberfest, a truly wonderful celebration of open-source. Whether you're an
individual contributor or a project maintainer, please join us on DEV to share your Hacktoberfest journey.
We can't wait to see you there."
sponsor_digital_ocean_from: "From Digital Ocean"
sponsor_digital_ocean_message: "Now in its 7th year, Hacktoberfest has become an integral thread in our company fabric. We wouldn’t be here
without the passionate community and helpful partners that make this program such a spectacular event. A big
thank you to all that are joining for the first time and those that keep coming back year after year."
sponsor_intel_from: "From Intel"
sponsor_intel_message: "Did you know that Intel is among the top ten contributors to open-source software? <br/> <br/>
We’re honored to join the Hacktoberfest celebration this year to build on this foundation along with
hundreds of thousands of software engineers around the world."
start_hacking: "start hacking"
support_for_free_tree_or_shirt_html: "<span class='highlight'>Support open source</span> and pick a limited edition T-shirt or plant a tree."
4 changes: 2 additions & 2 deletions spec/requests/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
context 'user not logged in' do
it 'redirects the user to login', vcr: { record: :new_episodes } do
get profile_path
expect(response).to redirect_to(login_path)
expect(response).to redirect_to(login_path(locale: 'en'))
end

it 'saves user destination in session', vcr: { record: :new_episodes } do
Expand Down Expand Up @@ -72,7 +72,7 @@
end

it 'redirects to the root_path' do
expect(response).to redirect_to(root_path)
expect(response).to redirect_to(root_path(locale: 'en'))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
context 'hacktoberfest is active' do
it 'redirects to the register_path' do
get profile_path
expect(response).to redirect_to(register_path)
expect(response).to redirect_to(register_path(locale: 'en'))
end
end

Expand Down