From 54e994e064d641e04c2554b088e5686aeba8d81e Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Tue, 14 Dec 2021 11:17:47 +0100 Subject: [PATCH] Follow-up 64a87b1c67c2dad7e9311491115f73606b14acc6 - Perform initial text module import locally and improve language matching. --- app/models/text_module.rb | 100 ++++----------- db/migrate/20120101000010_create_ticket.rb | 1 - ...11213105441_drop_text_module_foreign_id.rb | 11 ++ i18n/README.md | 10 +- i18n/text_modules/de.yml | 117 ++++++++++++++++++ i18n/text_modules/en.yml | 115 +++++++++++++++++ 6 files changed, 277 insertions(+), 77 deletions(-) create mode 100644 db/migrate/20211213105441_drop_text_module_foreign_id.rb create mode 100644 i18n/text_modules/de.yml create mode 100644 i18n/text_modules/en.yml diff --git a/app/models/text_module.rb b/app/models/text_module.rb index dfcd76c09..d08dbb71d 100644 --- a/app/models/text_module.rb +++ b/app/models/text_module.rb @@ -21,97 +21,47 @@ class TextModule < ApplicationModel =begin -load text modules from online +import text modules from i18n/text_modules/*.yml if no text modules exist yet. - TextModule.load('de-de', overwrite_existing_item) # e. g. 'en-us' or 'de-de' + TextModule.load('de-de') # e. g. 'en-us' or 'de-de' =end - def self.load(locale, overwrite_existing_item = false) + def self.load(locale) raise __('Got no locale') if locale.blank? + return if !TextModule.count.zero? + locale = locale.split(',').first.downcase # in case of accept_language header is given - url = "https://i18n.zammad.com/api/v1/text_modules/#{locale}" - result = UserAgent.get( - url, - {}, - { - json: true, - verify_ssl: true, - } - ) + # First check the full locale, e.g. 'de-de'. + filename = Rails.root.join("i18n/text_modules/#{locale}.yml") + if !File.exist?(filename) + # Fall back to the more generic language if needed, e.g. 'de'. + locale = locale.split('-').first + filename = Rails.root.join("i18n/text_modules/#{locale}.yml") + end - raise "Can't load text modules from #{url}" if !result - raise "Can't load text modules from #{url}: #{result.error}" if !result.success? + if !File.exist?(filename) + # No text modules available for current locale data. + return + end + + file_content = File.read(filename) + result = Psych.load(file_content) + + raise "Can't load text modules from #{filename}" if result.length.zero? ActiveRecord::Base.transaction do - result.data.each do |text_module| - exists = TextModule.find_by(foreign_id: text_module['foreign_id']) - if exists - next if !overwrite_existing_item - - exists.update!(text_module.symbolize_keys!) - else - text_module[:updated_by_id] = 1 - text_module[:created_by_id] = 1 - TextModule.create(text_module.symbolize_keys!) - end + result.each do |text_module| + text_module[:updated_by_id] = 1 + text_module[:created_by_id] = 1 + TextModule.create(text_module.symbolize_keys!) end end true end -=begin - -push text_modules to online - - TextModule.push(locale) - -=end - - def self.push(locale) - - # only push changed text_modules - text_modules = TextModule.all # where(locale: locale) - text_modules_to_push = [] - text_modules.each do |text_module| - next if !text_module.active - - text_modules_to_push.push text_module - end - - return true if text_modules_to_push.blank? - - url = 'https://i18n.zammad.com/api/v1/text_modules/thanks_for_your_support' - - translator_key = Setting.get('translator_key') - - result = UserAgent.post( - url, - { - locale: locale, - text_modules: text_modules_to_push, - fqdn: Setting.get('fqdn'), - translator_key: translator_key, - }, - { - json: true, - open_timeout: 6, - read_timeout: 16, - verify_ssl: true, - } - ) - raise "Can't push text_modules to #{url}: #{result.error}" if !result.success? - - # set new translator_key if given - if result.data['translator_key'] - Setting.set('translator_key', result.data['translator_key']) - end - - true - end - private def validate_content diff --git a/db/migrate/20120101000010_create_ticket.rb b/db/migrate/20120101000010_create_ticket.rb index 5d5d5666f..795544d52 100644 --- a/db/migrate/20120101000010_create_ticket.rb +++ b/db/migrate/20120101000010_create_ticket.rb @@ -385,7 +385,6 @@ class CreateTicket < ActiveRecord::Migration[4.2] t.column :content, :text, limit: 10.megabytes + 1, null: false t.column :note, :string, limit: 250, null: true t.column :active, :boolean, null: false, default: true - t.column :foreign_id, :integer, null: true t.column :updated_by_id, :integer, null: false t.column :created_by_id, :integer, null: false t.timestamps limit: 3, null: false diff --git a/db/migrate/20211213105441_drop_text_module_foreign_id.rb b/db/migrate/20211213105441_drop_text_module_foreign_id.rb new file mode 100644 index 000000000..ba2c10299 --- /dev/null +++ b/db/migrate/20211213105441_drop_text_module_foreign_id.rb @@ -0,0 +1,11 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +class DropTextModuleForeignId < ActiveRecord::Migration[6.0] + def change + # return if it's a new setup + return if !Setting.exists?(name: 'system_init_done') + + remove_column :text_modules, :foreign_id, :integer + TextModule.reset_column_information + end +end diff --git a/i18n/README.md b/i18n/README.md index 020364d8b..d4563f03b 100644 --- a/i18n/README.md +++ b/i18n/README.md @@ -1,7 +1,15 @@ -# Zammad Translations +# Zammad Translations - `i18n/*.po` Zammad translations are managed exclusively via [translations.zammad.org](https://translations.zammad.org/). You are welcome to contribute. Please get a free account there if you want to do so. Any pull requests modifying translation files directly will be rejected. + +# Zammad Text Modules - `i18n/text_modules/*.yml` + +Zammad text modules are automatically imported when the first admin user is created, according to this user's language. +This is just meant to provide for a smooth start with some existing helpful text modules. They can be modified later on; +no subsequent import from the example files will be performed. + +Feel free to send pull requests to add more helpful examples to existing files or even files for new languages. diff --git a/i18n/text_modules/de.yml b/i18n/text_modules/de.yml new file mode 100644 index 000000000..11dc0abb7 --- /dev/null +++ b/i18n/text_modules/de.yml @@ -0,0 +1,117 @@ +--- +- name: bur - Bitte um Rückruf + keywords: '' + content: + ich konnte Sie telefonisch nicht erreichen. Können Sie mir bitte eine kurze E-Mail + schicken wenn Sie wieder verfügbar sind? + note: '' +- name: ff - Für Fragen stehe ich... + keywords: '' + content: Für Fragen stehe ich gerne zur Verfügung! + note: '' +- name: fwf - Für weitere Fragen stehe ich... + keywords: '' + content: Für weitere Fragen stehe ich gerne zur Verfügung! + note: '' +- name: glg - Ganz liebe Grüße, + keywords: '' + content: Ganz liebe Grüße, + note: '' +- name: vg - Viele Grüße, + keywords: '' + content: Viele Grüße, + note: '' +- name: lg - Liebe Grüße, + keywords: '' + content: Liebe Grüße, + note: '' +- name: 'hallo - Hallo #{ticket.customer.firstname},' + keywords: '' + content: 'Hallo #{ticket.customer.firstname},' + note: '' +- name: 'hf - Hallo Frau #{ticket.customer.lastname},' + keywords: '' + content: 'Hallo Frau #{ticket.customer.lastname},' + note: '' +- name: 'hh - Hallo Herr #{ticket.customer.lastname},' + keywords: '' + content: 'Hallo Herr #{ticket.customer.lastname},' + note: '' +- name: ifm - Ich freue mich! + keywords: '' + content: Ich freue mich! + note: '' +- name: 'sgf - Sehr geehrte Frau #{ticket.customer.lastname},' + keywords: '' + content: 'Sehr geehrte Frau #{ticket.customer.lastname},' + note: '' +- name: 'sgh - Sehr geehrter Herr #{ticket.customer.lastname},' + keywords: '' + content: 'Sehr geehrter Herr #{ticket.customer.lastname},' + note: '' +- name: vdfdra - Vielen Dank für die rasche Antwort! + keywords: '' + content: Vielen Dank für die rasche Antwort! + note: '' +- name: vdff - Vielen Dank für das Feedback! + keywords: '' + content: Vielen Dank für das Feedback! + note: '' +- name: vdfia - Vielen Dank für Ihre Anfrage + keywords: '' + content: Vielen Dank für Ihre Anfrage + note: '' +- name: üff - Über Feedback würde ich mich freuen! + keywords: '' + content: Über Feedback würde ich mich freuen! + note: '' +- name: üfwf - Über Feedback zum weiteren Vorgehen würde ich mich freuen! + keywords: '' + content: Über Feedback zum weiteren Vorgehen würde ich mich freuen! + note: '' +- name: mfg - Mit freundlichen Grüßen, + keywords: '' + content: Mit freundlichen Grüßen, + note: '' +- name: sg - Sonnige Grüße, + keywords: '' + content: Sonnige Grüße, + note: '' +- name: sog - Sommerliche Grüße, + keywords: '' + content: Sommerliche Grüße, + note: '' +- name: wg - Winterliche Grüße, + keywords: '' + content: Winterliche Grüße, + note: '' +- name: ivbd - Ich verbleibe bis dahin, + keywords: '' + content: Ich verbleibe bis dahin, + note: '' +- name: bg - Beste Grüße, + keywords: '' + content: Beste Grüße, + note: '' +- name: vdbg - Vielen Dank und beste Grüße, + keywords: '' + content: Vielen Dank und beste Grüße. + note: '' +- name: fwft - Für weitere Fragen + keywords: '' + content: Für weitere Fragen stehe ich gerne auch telefonisch zur Verfügung! + note: '' +- name: ass - Anliegen sichten + keywords: '' + content: + '

Vielen Dank für Ihre Anfrage.

Wir werden Ihr Anliegen sichten + und uns schnellstmöglich mit Ihnen in Verbindung setzen.

' + note: '' +- name: vdv - vielen Dank im Voraus + keywords: '' + content: Freundliche Grüße und vielen Dank im Voraus, + note: '' +- name: hn - ich wollte höflich nachfragen + keywords: '' + content: ich wollte höflich nachfragen, + note: '' diff --git a/i18n/text_modules/en.yml b/i18n/text_modules/en.yml new file mode 100644 index 000000000..e0ef86866 --- /dev/null +++ b/i18n/text_modules/en.yml @@ -0,0 +1,115 @@ +--- +- name: cnr - I could not reach you... + keywords: '' + content: + I could not reach you by phone. Could you please send me a short email and + let me know when you will be available again? + note: '' +- name: iq - If you have any questions... + keywords: '' + content: If you have any questions, do not hesitate to contact me + note: '' +- name: ifq - in case of further questions... + keywords: '' + content: In case of further questions do not hesitate to contact me + note: '' +- name: kr - Kind regards, + keywords: '' + content: Kind regards, + note: '' +- name: 'Hello - Hello #{ticket.customer.firstname},' + keywords: '' + content: 'Hello #{ticket.customer.firstname},' + note: '' +- name: 'hello - Hello Ms. #{ticket.customer.firstname},' + keywords: '' + content: 'Hello Ms. #{ticket.customer.firstname},' + note: '' +- name: ilf - I look forward to hearing from you + keywords: '' + content: I look forward to hearing from you + note: '' +- name: 'dms- Dear Ms. #{ticket.customer.lastname},' + keywords: '' + content: 'Dear Ms. #{ticket.customer.lastname},' + note: '' +- name: 'dmr - Dear Mr. #{ticket.customer.lastname},' + keywords: '' + content: 'Dear Mr. #{ticket.customer.lastname},' + note: '' +- name: tfqr - Thank you for your quick reply. + keywords: '' + content: Thank you for your quick reply. + note: '' +- name: tff - Thank you for the feedback + keywords: '' + content: Thank you for the feedback. + note: '' +- name: tfyr - Thank you for your request. + keywords: '' + content: Thank you for your request. + note: '' +- name: ilff - I look forward to your feedback + keywords: '' + content: I look forward to your feedback. + note: '' +- name: fs - I look forward to your feedback regarding further steps + keywords: '' + content: I look forward to your feedback regarding further steps. + note: '' +- name: br - Best regards, + keywords: '' + content: Best regards, + note: '' +- name: sg - Sunny greetings, + keywords: '' + content: With sunny greetings, + note: '' +- name: sug - Summer greetings, + keywords: '' + content: ' With summer greetings,' + note: '' +- name: wg - Winter greetings, + keywords: '' + content: With winter greetings, + note: '' +- name: tybr - Thank you and best regards, + keywords: '' + content: Thank you and best regards, + note: '' +- name: ifqp - In case of further questions...phone + keywords: '' + content: If you have any questions, do not hesitate to contact me by phone. + note: '' +- name: ai - Analyse issue + keywords: '' + content: + '

Thank you for your request.

We will analyse the issue and get back + to you as soon as possible.

' + note: '' +- name: tya - Thank you in advance + keywords: '' + content: Kind regards and thank you in advance, + note: '' +- name: iwlk - I would like to know + keywords: '' + content: I would like to know, + note: '' +- name: wrt - With reference to + keywords: '' + content: With reference to + note: '' +- name: mdi - more detailed information + keywords: '' + content: + We would appreciate it if you could send us more detailed information about + ... + note: '' +- name: fa - further assistance + keywords: '' + content: If you need any additional assistance, please contact me + note: '' +- name: reg - Regards + keywords: '' + content: Regards + note: ''