Follow-up 64a87b1c67 - Perform initial text module import locally and improve language matching.

This commit is contained in:
Martin Gruner 2021-12-14 11:17:47 +01:00
parent 7b2a80a162
commit 54e994e064
6 changed files with 277 additions and 77 deletions

View file

@ -21,97 +21,47 @@ class TextModule < ApplicationModel
=begin =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 =end
def self.load(locale, overwrite_existing_item = false) def self.load(locale)
raise __('Got no locale') if locale.blank? 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 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( # First check the full locale, e.g. 'de-de'.
url, 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'.
json: true, locale = locale.split('-').first
verify_ssl: true, filename = Rails.root.join("i18n/text_modules/#{locale}.yml")
} end
)
raise "Can't load text modules from #{url}" if !result if !File.exist?(filename)
raise "Can't load text modules from #{url}: #{result.error}" if !result.success? # 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 ActiveRecord::Base.transaction do
result.data.each do |text_module| result.each do |text_module|
exists = TextModule.find_by(foreign_id: text_module['foreign_id']) text_module[:updated_by_id] = 1
if exists text_module[:created_by_id] = 1
next if !overwrite_existing_item TextModule.create(text_module.symbolize_keys!)
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
end end
end end
true true
end 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 private
def validate_content def validate_content

View file

@ -385,7 +385,6 @@ class CreateTicket < ActiveRecord::Migration[4.2]
t.column :content, :text, limit: 10.megabytes + 1, null: false t.column :content, :text, limit: 10.megabytes + 1, null: false
t.column :note, :string, limit: 250, null: true t.column :note, :string, limit: 250, null: true
t.column :active, :boolean, null: false, default: 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 :updated_by_id, :integer, null: false
t.column :created_by_id, :integer, null: false t.column :created_by_id, :integer, null: false
t.timestamps limit: 3, null: false t.timestamps limit: 3, null: false

View file

@ -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

View file

@ -1,7 +1,15 @@
# Zammad Translations # Zammad Translations - `i18n/*.po`
Zammad translations are managed exclusively via [translations.zammad.org](https://translations.zammad.org/). 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. 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. 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.

117
i18n/text_modules/de.yml Normal file
View file

@ -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:
'<p>Vielen Dank für Ihre Anfrage.</p><p>Wir werden Ihr Anliegen sichten
und uns schnellstmöglich mit Ihnen in Verbindung setzen.</p>'
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: ''

115
i18n/text_modules/en.yml Normal file
View file

@ -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:
'<p>Thank you for your request.</p><p>We will analyse the issue and get back
to you as soon as possible.</p>'
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: ''