diff --git a/app/assets/javascripts/application/plugins/summernote.js b/app/assets/javascripts/application/plugins/summernote.js index eb7c0d24fd82fcb7478408e060eda145531da1c3..756bc99c539b925a21a5297dba6cb49513604784 100644 --- a/app/assets/javascripts/application/plugins/summernote.js +++ b/app/assets/javascripts/application/plugins/summernote.js @@ -111,9 +111,12 @@ $(function () { $('[data-provider="summernote"]').each(function () { var config = $(this).attr('data-summernote-config'), + locale = $('#summernote-locale').data('locale'), options = {}; config = config || 'default'; options = configs[config]; + // if locale is undefined, summernote use default (en-US) + options['lang'] = locale; $(this).summernote(options); }); diff --git a/app/controllers/application_controller/with_locale.rb b/app/controllers/application_controller/with_locale.rb index 196d8cac221cda9eb75b4c8158d161ffa273d69f..91322f474a958ef881fe0bb9ce01ac4cfcfdf07f 100644 --- a/app/controllers/application_controller/with_locale.rb +++ b/app/controllers/application_controller/with_locale.rb @@ -3,6 +3,13 @@ module ApplicationController::WithLocale included do around_action :switch_locale + + helper_method :current_language + + end + + def current_language + @current_language ||= Language.find_by(iso_code: I18n.locale.to_s) end protected diff --git a/app/controllers/server/languages_controller.rb b/app/controllers/server/languages_controller.rb index 471c53269c27a2a90cc2732ec67627319c20efcc..c1920985ee527a3979220f2ff43012a6f2e3bbd1 100644 --- a/app/controllers/server/languages_controller.rb +++ b/app/controllers/server/languages_controller.rb @@ -57,6 +57,6 @@ class Server::LanguagesController < Server::ApplicationController end def language_params - params.require(:language).permit(:name, :iso_code) + params.require(:language).permit(:name, :iso_code, :summernote_locale) end end diff --git a/app/models/language.rb b/app/models/language.rb index c9478e5b56536eaa85d0e5772e3b87318acf4e04..047a01e1ac38ade22b87e265ec4989127079d4ca 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -2,11 +2,12 @@ # # Table name: languages # -# id :uuid not null, primary key -# iso_code :string -# name :string -# created_at :datetime not null -# updated_at :datetime not null +# id :uuid not null, primary key +# iso_code :string +# name :string +# summernote_locale :string +# created_at :datetime not null +# updated_at :datetime not null # class Language < ApplicationRecord diff --git a/app/views/admin/communication/blocks/edit.html.erb b/app/views/admin/communication/blocks/edit.html.erb index 7ac4162144fff987ede45d0942a1be3c9c06f919..8dfdb9fb7292f0c243a02ca927b9efa9e289bcfc 100644 --- a/app/views/admin/communication/blocks/edit.html.erb +++ b/app/views/admin/communication/blocks/edit.html.erb @@ -104,8 +104,8 @@ }, initSummernote(element) { var config = element.getAttribute('data-summernote-config') || 'default'; - $(element).summernote({ + lang: '<%= current_language.summernote_locale unless current_language.summernote_locale.blank? %>', toolbar: window.SUMMERNOTE_CONFIGS[config].toolbar, // Dependent of app/assets/javascripts/admin/plugins/summernote.js followingToolbar: true, disableDragAndDrop: true, diff --git a/app/views/admin/layouts/themes/_appstack.html.erb b/app/views/admin/layouts/themes/_appstack.html.erb index 6191e7000989d28f1345afbef2040255b5f82057..71a38224537e494bffaf59cf0b9174d3bfe17c87 100644 --- a/app/views/admin/layouts/themes/_appstack.html.erb +++ b/app/views/admin/layouts/themes/_appstack.html.erb @@ -29,4 +29,5 @@ <%= javascript_include_tag 'admin/appstack' %> <%= render 'gdpr/cookie_consent' %> <%= render 'bugsnag' %> -</body> \ No newline at end of file + <%= render 'summernote_localization' %> +</body> diff --git a/app/views/admin/layouts/themes/_pure.html.erb b/app/views/admin/layouts/themes/_pure.html.erb index 3e28659aaae47d865a730df0ff7868c69514d7d3..c93f9af8a3b2617534ecf9d87925218603018da1 100644 --- a/app/views/admin/layouts/themes/_pure.html.erb +++ b/app/views/admin/layouts/themes/_pure.html.erb @@ -20,4 +20,5 @@ <%= javascript_include_tag 'admin/pure' %> <%= render 'gdpr/cookie_consent' %> <%= render 'bugsnag' %> -</body> \ No newline at end of file + <%= render 'summernote_localization' %> +</body> diff --git a/app/views/application/_summernote_localization.html.erb b/app/views/application/_summernote_localization.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..0fb23463ed7e4f75c81928e559158674980e1ae1 --- /dev/null +++ b/app/views/application/_summernote_localization.html.erb @@ -0,0 +1,3 @@ +<% unless current_language.summernote_locale.blank? %> + <script id="summernote-locale" data-locale="<%= current_language.summernote_locale %>" src="https://cdn.jsdelivr.net/npm/summernote@<%= SummernoteRails::Rails::VERSION.split('.').take(3).join('.') %>/dist/lang/summernote-<%= current_language.summernote_locale %>.js"></script> +<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d650055e705a1f5384d4a5ae5026cf80125cc622..d7a2782bd31e89f40eb05cc1090e87caeb0b5ed7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -19,5 +19,6 @@ <%= render 'footer' %> <%= render 'gdpr/cookie_consent' %> <%= render 'bugsnag' %> + <%= render 'summernote_localization' %> </body> </html> diff --git a/app/views/layouts/devise.html.erb b/app/views/layouts/devise.html.erb index 352fb34385d53fe8b4a9ec855fc11c5ca230c61a..6c3eb195df94f507849be3b7c6073a7cf27339bc 100644 --- a/app/views/layouts/devise.html.erb +++ b/app/views/layouts/devise.html.erb @@ -36,5 +36,6 @@ <%= render 'footer' %> <%= render 'gdpr/cookie_consent' %> <%= render 'bugsnag' %> + <%= render 'summernote_localization' %> </body> </html> diff --git a/app/views/server/languages/_form.html.erb b/app/views/server/languages/_form.html.erb index 4284d412e5255d5f79adc6c662f852a3e53a7424..9ff9353765da2a33e052cc6bc2d1314606ed1a19 100644 --- a/app/views/server/languages/_form.html.erb +++ b/app/views/server/languages/_form.html.erb @@ -3,12 +3,15 @@ <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> <div class="row"> - <div class="col-md-8"> + <div class="col-md-4"> <%= f.input :name %> </div> <div class="col-md-4"> <%= f.input :iso_code %> </div> + <div class="col-md-4"> + <%= f.input :summernote_locale %> + </div> </div> <% content_for :action_bar_right do %> diff --git a/app/views/server/languages/index.html.erb b/app/views/server/languages/index.html.erb index ccc92cb8f45fa6fe91199c2021e0ee26505ad0f5..61989513b0621f46cefaa1342299a84221ba653b 100644 --- a/app/views/server/languages/index.html.erb +++ b/app/views/server/languages/index.html.erb @@ -6,6 +6,7 @@ <tr> <th><%= Language.human_attribute_name('name') %></th> <th><%= Language.human_attribute_name('iso_code') %></th> + <th><%= Language.human_attribute_name('summernote_locale') %></th> <th></th> </tr> </thead> @@ -15,6 +16,7 @@ <tr> <td><%= link_to language, [:server, language] %></td> <td><%= language.iso_code %></td> + <td><%= language.summernote_locale %></td> <td class="text-end"> <div class="btn-group" role="group"> <%= link_to t('edit'), diff --git a/app/views/server/languages/show.html.erb b/app/views/server/languages/show.html.erb index 72b772534b1e75e877f5c3743272f60b6a26d35e..b2260d97cae65bc30c270bfb82383aa76a6bb086 100644 --- a/app/views/server/languages/show.html.erb +++ b/app/views/server/languages/show.html.erb @@ -8,7 +8,7 @@ </div> <div class="table-responsive"> <table class="<%= table_classes %>"> - <% ['iso_code'].each do |variable| %> + <% ['iso_code', 'summernote_locale'].each do |variable| %> <tr> <td><%= Language.human_attribute_name(variable) %></td> <td class="text-end"><%= @language.public_send variable %></td> diff --git a/config/locales/en.yml b/config/locales/en.yml index 7111d639871b85688a42c0efdc2659adab05647e..fc1d24889addfdb8fbb78e2dca1e71b01d7bb717 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -43,6 +43,7 @@ en: language: iso_code: Iso code name: Name + summernote_locale: Summernote localization code user: admin_theme: Admin Theme email: Email @@ -268,6 +269,7 @@ en: language: iso_code: ISO 639-1 code (cf <a href="https://fr.wikipedia.org/wiki/Liste_des_codes_ISO_639-1" target="_blank">WikiPedia</a>) name: Name in the language (= "Français", "Deutsch", ...) + summernote_locale: 'Name of summernote loca (fr-FR / en-US). Check here and ensure locale is available: <a href="https://github.com/summernote/summernote/tree/develop/src/lang" target="_blank">summernote repo</a>' user: mobile_phone: "International format (+XX). This number remains private. By filling this field, you accept to receive your two-factor authentication codes via SMS." include_blanks: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 844af3b00b1cc948cda76c971bf586426e1fc7d0..3bc15636ca146c22815e433c2e870d1f7f48405b 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -43,6 +43,7 @@ fr: language: iso_code: Code Iso name: Nom + summernote_locale: Nom de la loca Summernote user: admin_theme: Thème de l'administration email: Email @@ -268,6 +269,7 @@ fr: language: iso_code: Code ISO 639-1 (cf <a href="https://fr.wikipedia.org/wiki/Liste_des_codes_ISO_639-1" target="_blank">WikiPedia</a>) name: Nom dans la langue (= "Français", "Deutsch", ...) + summernote_locale: 'Nom de la loca de summernote (fr-FR / en-US). Vérifier ici que la locale est disponible : <a href="https://github.com/summernote/summernote/tree/develop/src/lang" target="_blank">repo summernote</a>' user: mobile_phone: "Format international (+XX). Ce numéro reste privé. En renseignant ce champ, vous acceptez de recevoir vos codes de double authentification par SMS." include_blanks: diff --git a/db/migrate/20230112151136_add_summernote_locale_in_languages.rb b/db/migrate/20230112151136_add_summernote_locale_in_languages.rb new file mode 100644 index 0000000000000000000000000000000000000000..d3c27c1fc5e073b214bdc13ad8eb3ac556306e63 --- /dev/null +++ b/db/migrate/20230112151136_add_summernote_locale_in_languages.rb @@ -0,0 +1,5 @@ +class AddSummernoteLocaleInLanguages < ActiveRecord::Migration[7.0] + def change + add_column :languages, :summernote_locale, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 8fdf9f50664b0bc9d856e2c8c04450c9e9e7de9c..40bb669c26123d6f3aeb573a47ea10460556949b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_11_083139) do +ActiveRecord::Schema[7.0].define(version: 2023_01_12_151136) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -562,6 +562,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_11_083139) do t.string "iso_code" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "summernote_locale" end create_table "research_journal_papers", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| diff --git a/test/fixtures/languages.yml b/test/fixtures/languages.yml index 314cf445ef3fed313d995e12253df4be80947e82..7927df719648b1e74869ee705ee9228d8451a56c 100644 --- a/test/fixtures/languages.yml +++ b/test/fixtures/languages.yml @@ -2,11 +2,12 @@ # # Table name: languages # -# id :uuid not null, primary key -# iso_code :string -# name :string -# created_at :datetime not null -# updated_at :datetime not null +# id :uuid not null, primary key +# iso_code :string +# name :string +# summernote_locale :string +# created_at :datetime not null +# updated_at :datetime not null # en: name: English