diff --git a/CHANGELOG.md b/CHANGELOG.md index 8235a8f039..778f2b3cac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/controllers/usage_controller.rb b/app/controllers/usage_controller.rb index 78e5e93264..70ccacf661 100644 --- a/app/controllers/usage_controller.rb +++ b/app/controllers/usage_controller.rb @@ -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] @@ -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] diff --git a/app/helpers/usage_helper.rb b/app/helpers/usage_helper.rb index 6748ede7ab..4f2a79f701 100644 --- a/app/helpers/usage_helper.rb +++ b/app/helpers/usage_helper.rb @@ -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 = {} @@ -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 @@ -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 diff --git a/app/models/stat_created_plan.rb b/app/models/stat_created_plan.rb index 6ba26d2271..c5bd466ee2 100644 --- a/app/models/stat_created_plan.rb +++ b/app/models/stat_created_plan.rb @@ -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 diff --git a/app/services/org/monthly_usage_service.rb b/app/services/org/monthly_usage_service.rb index 6d6b460181..953cbd1934 100644 --- a/app/services/org/monthly_usage_service.rb +++ b/app/services/org/monthly_usage_service.rb @@ -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? diff --git a/app/views/translation_io_exports/_csv_headers.erb b/app/views/translation_io_exports/_csv_headers.erb new file mode 100644 index 0000000000..d91bbf1f44 --- /dev/null +++ b/app/views/translation_io_exports/_csv_headers.erb @@ -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') +%> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index dcaf746786..bc2e3253ed 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -44,6 +44,7 @@ en: short: "%d %b" csv: "%d/%m/%Y" readable: "%d %B %Y" + month_year_abbr: "%b-%y" month_names: - - January diff --git a/config/locales/localization.en-CA.yml b/config/locales/localization.en-CA.yml index c176fa139c..1ed554d1f4 100644 --- a/config/locales/localization.en-CA.yml +++ b/config/locales/localization.en-CA.yml @@ -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 diff --git a/config/locales/localization.fr-CA.yml b/config/locales/localization.fr-CA.yml index 00513632f1..6b1f36037c 100644 --- a/config/locales/localization.fr-CA.yml +++ b/config/locales/localization.fr-CA.yml @@ -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 diff --git a/lib/csvable.rb b/lib/csvable.rb index 94cc64233b..c96d9dd463 100644 --- a/lib/csvable.rb +++ b/lib/csvable.rb @@ -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| @@ -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 diff --git a/spec/controllers/usage_controller_spec.rb b/spec/controllers/usage_controller_spec.rb index 603292410b..f9cce70b74 100644 --- a/spec/controllers/usage_controller_spec.rb +++ b/spec/controllers/usage_controller_spec.rb @@ -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) @@ -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) @@ -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 diff --git a/spec/helpers/usage_helper_spec.rb b/spec/helpers/usage_helper_spec.rb index 859a37f15d..6b1ef294f1 100644 --- a/spec/helpers/usage_helper_spec.rb +++ b/spec/helpers/usage_helper_spec.rb @@ -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) @@ -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