Skip to content

Commit

Permalink
Merge pull request #549 from codegouvfr/i18n
Browse files Browse the repository at this point in the history
i18nification
  • Loading branch information
andrew authored Jun 12, 2024
2 parents f1af055 + 4bd9a73 commit 9f81263
Show file tree
Hide file tree
Showing 25 changed files with 302 additions and 104 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@

libraries-1.6.0-2020-01-12*

data/
data/

.irb_history
.irbrc
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ gem 'postgresql_cursor'
gem 'packageurl-ruby', require: 'package_url'
gem 'csv'

# Translation
gem 'http_accept_language'
gem 'i18n'
gem 'i18n-tasks'
gem 'rails-i18n'
gem 'enum_help'

group :development do
gem "web-console"
end
Expand Down
27 changes: 27 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 All @@ -106,6 +107,8 @@ GEM
csv (3.3.0)
date (3.3.4)
drb (2.2.1)
enum_help (0.0.19)
activesupport (>= 3.0.0)
erubi (1.12.0)
execjs (2.9.1)
faraday (2.9.1)
Expand Down Expand Up @@ -147,12 +150,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 @@ -212,6 +227,9 @@ GEM
bigdecimal (>= 3.0)
packageurl-ruby (0.1.0)
pagy (8.4.4)
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 @@ -265,6 +283,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.4)
actionpack (= 7.1.3.4)
activesupport (= 7.1.3.4)
Expand All @@ -273,6 +294,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 @@ -368,13 +390,17 @@ DEPENDENCIES
chartkick
counter_culture
csv
enum_help
faraday
faraday-follow_redirects
faraday-gzip
faraday-retry
gitlab
google-protobuf
groupdate
http_accept_language
i18n
i18n-tasks
jbuilder
jquery-rails
mocha
Expand All @@ -393,6 +419,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
2 changes: 1 addition & 1 deletion app/models/hosts/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def crawl_repositories
end

def load_owner_repos_names(owner)
if owner.kind == 'user'
if owner.user?
api_client.user_projects(owner.login, per_page: 100, archived: false, simple: true).map{|repo| repo["path_with_namespace"] }
else
api_client.group_projects(owner.login, per_page: 100, archived: false, simple: true).map{|repo| repo["path_with_namespace"] }
Expand Down
1 change: 1 addition & 0 deletions app/models/owner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Owner < ApplicationRecord
scope :updated_after, ->(date) { where('updated_at > ?', date) }

scope :kind, ->(kind) { where(kind: kind) }
enum kind: { user: 'user', organization: 'organization' }

scope :has_sponsors_listing, -> { where("metadata->>'has_sponsors_listing' = 'true'") }

Expand Down
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
6 changes: 3 additions & 3 deletions app/views/hosts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
<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>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<%= topics_host_path(@host) %>">
Topics
<%= t('virtual.models.topic.other') %>
</a>
</li>
<%= render 'sort' %>
Expand Down
12 changes: 6 additions & 6 deletions app/views/hosts/topics.html.erb
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<% @meta_title = "#{@host} Topics" %>
<% @meta_title = "#{@host} #{t('virtual.models.topic.other')}" %>

<div class="container-sm">
<h1 class='mb-4'>
<%= link_to @host, @host.url, target: :_blank %>
Topics
<%= t 'virtual.models.topic.other' %>
</h1>

<ul class="nav nav-tabs my-3">
<li class="nav-item">
<a class="nav-link" href="<%= host_path(@host) %>">
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>
</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page">
Topics
<%= t 'virtual.models.topic.other' %>
</a>
</li>
</ul>
Expand All @@ -40,7 +40,7 @@
<%= link_to topic, topic_path(topic) %>
</h5>
<p class="card-text">
<%= number_with_delimiter count %> packages
<%= number_with_delimiter count %> <%= Repository.model_name.human(count: count) %>
</p>
</div>
</div>
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
4 changes: 2 additions & 2 deletions app/views/owners/_owner.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<div class="flex-grow-1 ms-3 text-break">
<h5 class='card-title'>
<%= link_to owner.login, host_owner_path(@host, owner.login) %>
<i><small class="text-muted"><%= owner.kind %></small></i>
<i><small class="text-muted"><%= owner.kind_i18n %></small></i>
</h5>

<p class="card-subtitle mb-2 text-muted">
<%= pluralize number_with_delimiter(owner.repositories_count), 'repository' %>
<%= number_with_delimiter(owner.repositories_count) %> <%= Repository.model_name.human(count: owner.repositories_count) %>
</p>
</div>
<div class="flex-shrink-0">
Expand Down
6 changes: 3 additions & 3 deletions app/views/owners/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
<ul class="nav nav-tabs my-3">
<li class="nav-item">
<a class="nav-link" href="<%= host_path(@host) %>">
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 active" aria-current="page">
Owners
<%= Owner.model_name.human(count: @host.owners_count) %>
<span class="badge bg-secondary rounded-pill">
<%= number_with_delimiter @host.owners_count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<%= topics_host_path(@host) %>">
Topics
<%= t('virtual.models.topic.other') %>
</a>
</li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions app/views/owners/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%= link_to @host, host_path(@host) %> / <%= link_to @owner, "#{@host.url}/#{@owner}", target: :_blank %>
<% if @owner_record %>
<small class='text-muted'>
<%= pluralize number_with_delimiter(@owner_record.repositories_count), 'repository' %>
<%= number_with_delimiter(@owner_record.repositories_count) %> <%= Repository.model_name.human(count: @owner_record.repositories_count) %>
</small>
<% end %>
</h1>
Expand All @@ -19,15 +19,15 @@
<% if @owner_record.funding_links.any? %>
<p><small class='text-muted'>
Funding links: <% @owner_record.funding_links.each_with_index do |url,i| %><%= ', ' if i > 0 %><%= link_to(url, sanitize_user_url(url), target: :_blank) %><% end %>
<%= t '.funding_links' %> <% @owner_record.funding_links.each_with_index do |url,i| %><%= ', ' if i > 0 %><%= link_to(url, sanitize_user_url(url), target: :_blank) %><% end %>
</small></p>
<% end %>
<% end %>

<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: @owner_record.repositories_count) %>
<% if @owner_record %>
<span class="badge bg-secondary rounded-pill">
<%= number_with_delimiter @owner_record.repositories_count %>
Expand Down
Loading

0 comments on commit 9f81263

Please sign in to comment.