Skip to content

Commit

Permalink
WIP: i18nification
Browse files Browse the repository at this point in the history
  • Loading branch information
simkim committed May 30, 2024
1 parent 870167c commit 764ef5d
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 77 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ gem 'after_commit_action'
gem 'postgresql_cursor'
gem 'packageurl-ruby', require: 'package_url'
gem 'csv'
gem 'http_accept_language'
gem 'i18n'
gem 'i18n-tasks'
gem 'rails-i18n'

group :development do
gem "web-console"
Expand Down
24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ GEM
activesupport (>= 3.0.0)
appsignal (3.7.5)
rack
ast (2.4.2)
autoprefixer-rails (10.4.16.0)
execjs (~> 2)
base64 (0.2.0)
Expand Down Expand Up @@ -143,12 +144,24 @@ GEM
groupdate (6.4.0)
activesupport (>= 6.1)
hashdiff (1.1.0)
highline (3.0.1)
http_accept_language (2.1.1)
httparty (0.22.0)
csv
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
i18n-tasks (1.0.14)
activesupport (>= 4.0.2)
ast (>= 2.1.0)
erubi
highline (>= 2.0.0)
i18n
parser (>= 3.2.2.1)
rails-i18n
rainbow (>= 2.2.2, < 4.0)
terminal-table (>= 1.5.1)
io-console (0.7.2)
irb (1.13.1)
rdoc (>= 4.0.0)
Expand Down Expand Up @@ -209,6 +222,9 @@ GEM
bigdecimal (>= 3.0)
packageurl-ruby (0.1.0)
pagy (8.4.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
pg (1.5.6)
pg_query (5.1.0)
google-protobuf (>= 3.22.3)
Expand Down Expand Up @@ -262,6 +278,9 @@ GEM
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
rails-i18n (7.0.9)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
railties (7.1.3.3)
actionpack (= 7.1.3.3)
activesupport (= 7.1.3.3)
Expand All @@ -270,6 +289,7 @@ GEM
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rdoc (6.7.0)
psych (>= 4.0.0)
Expand Down Expand Up @@ -372,6 +392,9 @@ DEPENDENCIES
gitlab
google-protobuf
groupdate
http_accept_language
i18n
i18n-tasks
jbuilder
jquery-rails
mocha
Expand All @@ -390,6 +413,7 @@ DEPENDENCIES
rack-cors
rails (~> 7.1.3)
rails-controller-testing
rails-i18n
redis
rswag-api
rswag-ui
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
class ApplicationController < ActionController::Base
include Pagy::Backend
before_action :set_locale

skip_before_action :verify_authenticity_token

after_action lambda {
request.session_options[:skip] = true
}

def set_locale
I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales)
end
end
24 changes: 12 additions & 12 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div class="container-sm">
<div class="card mb-3">
<div class="card-header">
Statistics
<%= t('.statistics') %>
</div>
<div class="card-body">
<div class="d-flex">
Hosts: <%= number_with_delimiter @hosts.length %><br/>
Repositories: <%= number_with_delimiter @hosts.sum(&:repositories_count) %><br/>
Owners: <%= number_with_delimiter @hosts.sum(&:owners_count) %><br/>
Tags: <%= number_with_delimiter Tag.fast_total %><br/>
Manifests: <%= number_with_delimiter Manifest.fast_total %><br/>
Dependencies: <%= number_with_delimiter Dependency.fast_total %><br/>
<%= Host.model_name.human(count: 2) %>: <%= number_with_delimiter @hosts.length %><br/>
<%= Repository.model_name.human(count: 2) %>: <%= number_with_delimiter @hosts.sum(&:repositories_count) %><br/>
<%= Owner.model_name.human(count: 2) %>: <%= number_with_delimiter @hosts.sum(&:owners_count) %><br/>
<%= Tag.model_name.human(count: 2) %>: <%= number_with_delimiter Tag.fast_total %><br/>
<%= Manifest.model_name.human(count: 2) %>: <%= number_with_delimiter Manifest.fast_total %><br/>
<%= Dependency.model_name.human(count: 2) %>: <%= number_with_delimiter Dependency.fast_total %><br/>
</div>
</div>
</div>
Expand All @@ -19,25 +19,25 @@
<div class="card mb-3">
<div class="card-header">
<img src="<%= hosts.first.kind_icon_url %>" class="me-1 pull-left" height='20' width='20' onerror="this.style.display='none'">
<%= link_to kind, kind_hosts_path(kind), class: 'text-decoration-none' %>
<%= link_to t(kind), kind_hosts_path(kind), class: 'text-decoration-none' %>
<span class="text-black-50">
<%= pluralize number_with_delimiter(hosts.length), 'instance' %> -
<%= pluralize number_with_delimiter(hosts.sum(&:repositories_count)), 'repository' %>
<%= number_with_delimiter(hosts.length) %> <%= t('virtual.models.instance', count: hosts.length) %> -
<%= number_with_delimiter(hosts.sum(&:repositories_count)) %> <%= Repository.model_name.human(count: hosts.sum(&:repositories_count)) %>
</span>
</div>
<ul class="list-group list-group-flush">
<% hosts.first(20).each do |host| %>
<li class="list-group-item">
<%= link_to host.name.downcase, host %>
<span class="text-black-50">
<%= pluralize number_with_delimiter(host.repositories_count), 'repository' %>
<%= number_with_delimiter(host.repositories_count) %> <%= Repository.model_name.human(count: host.repositories_count) %>
</span>
</li>
<% end %>
</ul>
<% if hosts.length > 20 %>
<div class="card-footer">
<%= link_to "and #{hosts.length - 20} more...", kind_hosts_path(kind) %>
<%= link_to t('and_more', count: hosts.length - 20), kind_hosts_path(kind) %>
</div>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/hosts/_host.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<% if host.repositories_count.zero? %>
<i>Coming soon</i>
<% else %>
<%= number_with_delimiter host.repositories_count %> repositories<br/>
<%= number_with_delimiter host.owners_count %> owners
<%= "#{number_with_delimiter host.repositories_count} #{Repository.model_name.human(count: host.repositories_count)}" %><br/>
<%= "#{number_with_delimiter host.owners_count} #{Owner.model_name.human(count: host.owners_count)}" %>
<% end %>
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/hosts/_sort.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<li class="nav-item ms-auto">
<div class="dropdown">
<button class="btn btn-light dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Sort
<%= t('.sort') %>
</button>
<ul class="dropdown-menu">

<% [['pushed_at', 'desc', 'Recently Pushed'],['stargazers_count','desc','Stars'],['forks_count','desc','Forks']].each do |sort, order, name| %>
<% [['pushed_at', 'desc', t('.recently_pushed')],['stargazers_count','desc',t('.stars')],['forks_count','desc',t('.forks')]].each do |sort, order, name| %>
<li><a class="dropdown-item <%= 'active' if params[:sort] == sort %>" href="<%= url_for(sort: sort, order: order) %>"><%= name %></a></li>
<% end %>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hosts/kind.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="container-sm">
<h2><%= @kind %> hosts</h2>
<h2><%= t('.title', kind: @kind) %></h2>

<%= render @hosts %>
<%== pagy_bootstrap_nav(@pagy) if @pagy.pages > 1 %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/hosts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<ul class="nav nav-tabs my-3">
<li class="nav-item">
<a class="nav-link active" aria-current="page">
Repositories
<%= Repository.model_name.human(count: @host.repositories_count) %>
<span class="badge bg-secondary rounded-pill">
<%= number_with_delimiter @host.repositories_count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<%= host_owners_path(@host) %>">
Owners
<%= Owner.model_name.human(count: @host.owners_count) %>
<span class="badge bg-secondary rounded-pill">
<%= number_with_delimiter @host.owners_count %>
</span>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</h1>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4">
An open API service providing repository metadata for many open source software ecosystems.
<%= t '.intro' %>
</p>
</div>
</div>
Expand All @@ -33,7 +33,7 @@
</div>

<footer class="py-5 container-sm text-muted text-center">
<%= link_to 'About', 'https://ecosyste.ms', class: 'link-dark', target: :_blank %>
<%= link_to t('.about'), 'https://ecosyste.ms', class: 'link-dark', target: :_blank %>
<%= link_to 'Blog', "https://blog.ecosyste.ms", class: 'link-dark', target: :_blank %>
<%= link_to 'API', rswag_ui_path, class: 'link-dark', target: :_blank %>
<%= link_to 'Open Data', exports_path, class: 'link-dark' %>
Expand Down
16 changes: 7 additions & 9 deletions app/views/repositories/_repository.html.erb
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@
<div class="card mb-3 repository d-flex" id="repository_<%= repository.id %>">
<div class="card-body pb-1">
<div class="d-flex">

<div class="flex-grow-1 ms-3 text-break">
<h5 class='card-title'>
<%= link_to repository, host_repository_path(repository.host, repository) %>
<% if repository.fork && repository.source_name %>
<small class='text-muted'><i>
Fork of <%= link_to repository.source_name, host_repository_path(host_id: repository.host, id: repository.source_name) %>
<%= t('repositories.fork_of') %> <%= link_to repository.source_name, host_repository_path(host_id: repository.host, id: repository.source_name) %>
</i></small>
<% end %>
<% if repository.archived %>
<span title='Archived'>📦</span>
<% end %>
</h5>

<p class="card-subtitle mb-2 text-muted">
<%= repository.description %>
</p>
<p class="card-subtitle mb-2 text-muted"><i><small>
<% if repository.language %>
Language: <%= repository.language %>
<span class='text-capitalize'><%= Repository.human_attribute_name(:language) %></span>: <%= repository.language %>
<% end %>
<% if repository.language && repository.size %>
-
<% end %>
<% if repository.size %>
Size: <%= number_to_human_size repository.size*1000 %>
<span class='text-capitalize'><%= Repository.human_attribute_name(:size) %></span>: <%= number_to_human_size repository.size*1000 %>
<% end %>
<% if repository.size && repository.last_synced_at %>
-
<% end %>
<% if repository.last_synced_at %>
Last synced: <%= distance_of_time_in_words_to_now repository.last_synced_at %> ago
<span class='text-capitalize'><%= Repository.human_attribute_name(:last_synced_at) %></span>: <%= t('time_ago', time: time_ago_in_words(repository.last_synced_at)) %>
<% end %>
<% if repository.pushed_at && repository.last_synced_at %>
-
<% end %>
<% if repository.pushed_at %>
Pushed: <%= distance_of_time_in_words_to_now repository.pushed_at %> ago
<span class='text-capitalize'><%= Repository.human_attribute_name(:pushed_at) %></span>: <%= t('time_ago', time: time_ago_in_words(repository.pushed_at)) %>
<% end %>
<% if repository.stargazers_count || repository.forks_count %>
-
<% end %>
<% if repository.stargazers_count %>
Stars: <%= number_with_delimiter repository.stargazers_count %>
<span class='text-capitalize'><%= Repository.human_attribute_name(:stargazers_count) %></span>: <%= number_with_delimiter repository.stargazers_count %>
<% end %>
<% if repository.stargazers_count && repository.forks_count %>
-
<% end %>
<% if repository.forks_count %>
Forks: <%= number_with_delimiter repository.forks_count %>
<span class='text-capitalize'><%= Repository.human_attribute_name(:forks_count) %></span>: <%= number_with_delimiter repository.forks_count %>
<% end %>
</small></i></p>
</div>
Expand Down
27 changes: 13 additions & 14 deletions app/views/repositories/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<%= link_to group, subgroup_host_owner_path(@host, @repository.owner, subgroups) %> /
<%end %>
<% end %>
<%= link_to @repository.project_slug, @repository.html_url, target: :_blank %>
</h1>

Expand All @@ -25,36 +24,36 @@
<div class="col-md-4">
<p><small class='text-muted'>
<% if @repository.fork && @repository.source_name %>
Fork of <%= link_to @repository.source_name, host_repository_path(@host, @repository.source_name) %><br/>
<%= t('repositories.fork_of') %> <%= link_to @repository.source_name, host_repository_path(@host, @repository.source_name) %><br/>
<% end %>
Stars: <%= number_with_delimiter @repository.stargazers_count %><br/>
Forks: <%= number_with_delimiter @repository.forks_count %><br/>
Open Issues: <%= number_with_delimiter @repository.open_issues_count %><br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:stargazers_count) %></span>: <%= number_with_delimiter @repository.stargazers_count %><br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:forks_count) %></span>: <%= number_with_delimiter @repository.forks_count %><br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:open_issues_count) %></span>: <%= number_with_delimiter @repository.open_issues_count %><br/>
</small></p>
</div>
<div class="col-md-4">
<p><small class='text-muted'>
License: <%= @repository.license || 'None' %><br/>
Language: <%= @repository.language %><br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:license) %></span>: <%= @repository.license || 'None' %><br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:language) %></span>: <%= @repository.language %><br/>
<% if @repository.size %>
Repo Size: <%= number_to_human_size @repository.size*1000 %><br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:size) %></span>: <%= number_to_human_size @repository.size*1000 %><br/>
<% end %>
Dependencies: <% if @repository.dependencies_parsed_at && @manifests %>
<span class='text-capitalize'><%= Repository.human_attribute_name(:dependencies_parsed_at) %>: <% if @repository.dependencies_parsed_at && @manifests %>
<%= number_with_delimiter @manifests.sum{|m| m.dependencies.length } %>
<% else %>
pending
<%= t('repositories.dependencies.pending') %>
<% end %>
</small></p>
</div>
<div class="col-md-4">
<p><small class='text-muted'>
Created: <%= distance_of_time_in_words_to_now @repository.created_at %> ago<br/>
Updated: <%= distance_of_time_in_words_to_now @repository.updated_at %> ago<br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:created_at) %></span>: <%= t('time_ago', time: distance_of_time_in_words_to_now(@repository.created_at)) %><br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:updated_at) %></span>: <%= t('time_ago', time: distance_of_time_in_words_to_now(@repository.updated_at)) %><br/>
<% if @repository.pushed_at %>
Last pushed: <%= distance_of_time_in_words_to_now @repository.pushed_at %> ago<br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:pushed_at) %></span>: <%= t('time_ago', time: distance_of_time_in_words_to_now(@repository.pushed_at)) %><br/>
<% end %>
<% if @repository.last_synced_at %>
Last synced: <%= distance_of_time_in_words_to_now @repository.last_synced_at %> ago<br/>
<span class='text-capitalize'><%= Repository.human_attribute_name(:last_synced_at) %></span>: <%= t('time_ago', time: distance_of_time_in_words_to_now(@repository.last_synced_at)) %><br/>
<% end %>
</small></p>
</div>
Expand Down
1 change: 0 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

config.exceptions_app = routes
end
end
1 change: 1 addition & 0 deletions config/initializers/i18n.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I18n.available_locales = %i[en fr]
1 change: 1 addition & 0 deletions config/initializers/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/bootstrap'
require 'pagy/extras/array'
require 'pagy/extras/overflow'
require 'pagy/extras/i18n'

Pagy::DEFAULT[:items] = 100
Pagy::DEFAULT[:items_param] = :per_page
Expand Down
Loading

0 comments on commit 764ef5d

Please sign in to comment.