From 7b9d6da518f1bb92794fd0d0308fb792aedadb21 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 29 Jan 2024 10:08:01 +0000 Subject: [PATCH] add option for commercial license, plus translations --- app/helpers/models_helper.rb | 7 ++++++- app/views/models/show.html.erb | 4 +++- config/i18n-tasks.yml | 1 + config/locales/en.yml | 11 +++++++++++ spec/models/model_spec.rb | 6 ++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/helpers/models_helper.rb b/app/helpers/models_helper.rb index f3372575f..a0bb5cb33 100644 --- a/app/helpers/models_helper.rb +++ b/app/helpers/models_helper.rb @@ -28,13 +28,18 @@ def license_select_options(selected: nil) CC-PDDC CC0-1.0 MIT + LicenseRef-Commercial ].map { |id| [ - Spdx.licenses[id]["name"] + " (#{id})", + t_license(id), id ] }, selected: selected ) end + + def t_license(license) + t("licenses.%{id}" % {id: license.delete(".")}, default: license) + end end diff --git a/app/views/models/show.html.erb b/app/views/models/show.html.erb index 9c21fcb35..5cfd5962e 100644 --- a/app/views/models/show.html.erb +++ b/app/views/models/show.html.erb @@ -48,7 +48,9 @@ <%= icon "card-heading", "License" %> - <%= link_to @model.license, Spdx.licenses[@model.license]["reference"] %> + <%= Spdx.licenses[@model.license]&.fetch("reference") ? + link_to(t_license(@model.license), Spdx.licenses[@model.license]["reference"]) : + t_license(@model.license) %> <% end %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index 17cce66c9..677323e51 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -121,6 +121,7 @@ ignore_unused: - 'activerecord.attributes.*' - 'activerecord.models.*' - 'problems.categories.*' +- 'licenses.*' # - '{devise,kaminari,will_paginate}.*' # - 'simple_form.{yes,no}' # - 'simple_form.{placeholders,hints,labels}.*' diff --git a/config/locales/en.yml b/config/locales/en.yml index 5221621f0..0975274a0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -43,6 +43,17 @@ en: libraries: general: new: New Library + licenses: + CC-BY-40: Creative Commons Attrbution + CC-BY-NC-40: Creative Commons Attribution NonCommercial + CC-BY-NC-ND-40: Creative Commons Attribution NonCommercial NoDerivatives + CC-BY-NC-SA-40: Creative Commons Attribution NonCommercial ShareAlike + CC-BY-ND-40: Creative Commons Attribution NoDerivatives + CC-BY-SA-40: Creative Commons Attribution ShareAlike + CC-PDDC: Creative Commons Public Domain Declaration + CC0-10: Creative Commons Zero + LicenseRef-Commercial: Commercial; private use only + MIT: MIT model_files: show: duplicate_card: diff --git a/spec/models/model_spec.rb b/spec/models/model_spec.rb index d68694210..8ee2794dc 100644 --- a/spec/models/model_spec.rb +++ b/spec/models/model_spec.rb @@ -42,6 +42,12 @@ m = build(:model, license: "Made up license") expect(m).not_to be_valid end + + it "allows LicenseRef-Commercial to represent private use only" do + # See https://scancode-licensedb.aboutcode.org/commercial-license.html + m = build(:model, license: "LicenseRef-Commercial") + expect(m).to be_valid + end end it "strips leading and trailing separators from paths" do