Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Various Translations Within /usage Page #697

Open
wants to merge 4 commits into
base: integration
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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

### Added

- Bump mysql2 from 0.5.5 to 0.5.6 [#645](https://github.com/portagenetwork/roadmap/pull/645)
- Bump mysql2 from 0.5.5 to 0.5.6 [#645](https://github.com/portagenetwork/roadmap/pull/645)

- Enable Various Translations Within `/usage` Page [#697](https://github.com/portagenetwork/roadmap/pull/697)

### Fixed

- Updated Webmock's allowed request list to enable fetching of chromedriver [#670](https://github.com/portagenetwork/roadmap/pull/670)
- Updated Webmock's allowed request list to enable fetching of chromedriver [#670](https://github.com/portagenetwork/roadmap/pull/670)

## [4.0.2+portage-4.0.0] - 2024-02-01

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/usage_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def yearly_users
csv << [_('Month'), _('No. Users joined')]
total = 0
@users_per_month.each do |data|
csv << [data.date.strftime('%b-%y'), data.count]
csv << [I18n.l(data.date, format: :month_year_abbr), data.count]
total += data.count
end
csv << [_('Total'), total]
Expand All @@ -120,7 +120,7 @@ def yearly_plans
csv << [_('Month'), _('No. Created Plans')]
total = 0
@plans_per_month.each do |data|
csv << [data.date.strftime('%b-%y'), data.count]
csv << [I18n.l(data.date, format: :month_year_abbr), data.count]
total += data.count
end
csv << [_('Total'), total]
Expand Down
9 changes: 5 additions & 4 deletions app/helpers/usage_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def prep_data_for_yearly_plans_chart(data:)
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def prep_data_for_template_plans_chart(data:, subset: 'by_template')
last_month = Date.today.last_month.end_of_month.strftime('%b-%y')
last_month = I18n.localize(Date.today.last_month.end_of_month, format: :month_year_abbr)
return { labels: [last_month], datasets: [] }.to_json if data.blank? || data.empty?

datasets = {}
Expand All @@ -34,12 +34,12 @@ def prep_data_for_template_plans_chart(data:, subset: 'by_template')
# We need a placeholder for each month/year - template combo. The
# default is to assume that there are zero plans for that month/year + template
dflt = {
label: template['name'],
label: _(template['name']),
backgroundColor: random_rgb,
data: labels.map { |lbl| { x: 0, y: lbl } }
}

template_hash = datasets.fetch(template['name'], dflt)
template_hash = datasets.fetch(_(template['name']), dflt)

# Replace any of the month/year plan counts for this template IF it has
# any plans defined
Expand Down Expand Up @@ -81,7 +81,8 @@ def default_chart_prep(data:)
end

def prep_date_for_charts(date:)
date.is_a?(Date) ? date.strftime('%b-%y') : Date.parse(date).strftime('%b-%y')
date = Date.parse(date) unless date.is_a?(Date)
I18n.l(date, format: :month_year_abbr)
end

def random_rgb
Expand Down
2 changes: 1 addition & 1 deletion app/models/stat_created_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def to_csv_by_template(created_plans, sep = ',')
end.call(created_plans)

data = created_plans.map do |created_plan|
tuple = { Date: created_plan.date.strftime('%b %Y') }
tuple = { Date: I18n.l(created_plan.date, format: '%b %Y') }
template_names.each_with_object(tuple) do |name, acc|
acc[name] = 0
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/org/monthly_usage_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def build_model(month:, new_plans: 0, new_users: 0, downloads: 0, plans_shared:
end

def reducer_body(acc, rec, key_target)
month = rec.date.strftime('%b-%y')
month = I18n.l(rec.date, format: :month_year_abbr)
count = rec.count

if acc[month].present?
Expand Down
20 changes: 20 additions & 0 deletions app/views/translation_io_exports/_csv_headers.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

<%=
# /usage

# Download global usage
_('Org name')

# Download Monthly Usage
_('New plans')
_('New users')
_('Downloads')
_('Plans shared')

# No. plans during last year Download
_('No. Created Plans')


# No. plans by template Download
_('Count')
%>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ en:
short: "%d %b"
csv: "%d/%m/%Y"
readable: "%d %B %Y"
month_year_abbr: "%b-%y"
month_names:
-
- January
Expand Down
1 change: 1 addition & 0 deletions config/locales/localization.en-CA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ en-CA:
short: "%d %b"
csv: "%d/%m/%Y"
readable: "%B %d, %Y"
month_year_abbr: "%b-%y"
order:
- :day
- :month
Expand Down
1 change: 1 addition & 0 deletions config/locales/localization.fr-CA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fr-CA:
long: "%e %B %Y"
csv: "%Y-%m-%d"
readable: "%d %b %Y"
month_year_abbr: "%b-%y"
order:
- :year
- :month
Expand Down
11 changes: 4 additions & 7 deletions lib/csvable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
module Csvable
require 'csv'
class << self
# rubocop:disable Style/OptionalBooleanParameter
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:disable Style/OptionalBooleanParameter, Metrics/AbcSize
def from_array_of_hashes(data = [], humanize = true, sep = ',')
return '' unless data.first&.keys

headers = if humanize
data.first.keys
.map(&:to_s)
.map(&:humanize)
.map { |x| _(x.to_s.humanize) }
else
data.first.keys
.map(&:to_s)
.map { |x| _(x.to_s) }
end

CSV.generate({ col_sep: sep }) do |csv|
Expand All @@ -25,7 +23,6 @@ def from_array_of_hashes(data = [], humanize = true, sep = ',')
end
end
end
# rubocop:enable Style/OptionalBooleanParameter
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable Style/OptionalBooleanParameter, Metrics/AbcSize
end
end
6 changes: 3 additions & 3 deletions spec/controllers/usage_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
end
it 'assigns the correct csv data' do
expected = "Month,No. Users joined\n" \
"#{@date.strftime('%b-%y')},#{@user_stat.count}\n" \
"#{I18n.l(@date, format: :month_year_abbr)},#{@user_stat.count}\n" \
"Total,#{@user_stat.count}\n"
expect(response.content_type).to eq('text/csv')
expect(response.body).to eql(expected)
Expand All @@ -93,7 +93,7 @@
end
it 'assigns the correct csv data' do
expected = "Month,No. Created Plans\n" \
"#{@date.strftime('%b-%y')},#{@plan_stat.count}\n" \
"#{I18n.l(@date, format: :month_year_abbr)},#{@plan_stat.count}\n" \
"Total,#{@plan_stat.count}\n"
expect(response.content_type).to eq('text/csv')
expect(response.body).to eql(expected)
Expand All @@ -108,7 +108,7 @@
name = @details[:by_template].first[:name]
count = @details[:by_template].first[:count]
expected = "Date,#{name},Count\n" \
"#{@date.strftime('%b %Y')},#{count},#{@plan_stat.count}\n"
"#{I18n.l(@date, format: '%b %Y')},#{count},#{@plan_stat.count}\n"
expect(response.content_type).to eq('text/csv')
expect(response.body).to eql(expected)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/usage_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# }
it 'returns an empty hash if no data was available' do
expected = {
labels: [Date.today.last_month.end_of_month.strftime('%b-%y')],
labels: [I18n.l(Date.today.last_month.end_of_month, format: :month_year_abbr)],
datasets: []
}
expect(prep_data_for_template_plans_chart(data: nil)).to eql(expected.to_json)
Expand Down Expand Up @@ -132,7 +132,7 @@
describe '#prep_date_for_charts' do
it 'converts the date' do
rslt = prep_date_for_charts(date: Date.today.to_s)
expect(rslt).to eql(Date.today.strftime('%b-%y'))
expect(rslt).to eql(I18n.l(Date.today, format: :month_year_abbr))
end
end

Expand Down
Loading