Fixes #4000 - Unable to upgrade to Zammad 5.1.

This commit is contained in:
Martin Gruner 2022-03-08 10:34:49 +01:00
parent b7ebd470dd
commit f254a97cc6
3 changed files with 41 additions and 5 deletions

View file

@ -95,7 +95,10 @@ module Translation::SynchronizesFromPo
return ['i18n/zammad.pot'] if locale.eql? 'en-us'
files = Dir.glob "i18n/*.#{locale}.po", base: Rails.root
raise "No translation found for locale '#{locale}'." if files.exclude?("i18n/zammad.#{locale}.po")
if files.exclude?("i18n/zammad.#{locale}.po")
Rails.logger.error "No translation found for locale '#{locale}'."
return []
end
[
files.delete("i18n/zammad.#{locale}.po"),

View file

@ -0,0 +1,21 @@
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class RenameTwLocale < ActiveRecord::Migration[6.0]
# Copied from db/migrate/20180502015927_issue_1219_zhtw_locale_typo.rb as this
# needed to be re-executed.
def change
return if !Setting.exists?(name: 'system_init_done')
if Locale.exists?(locale: 'zh-tw')
Locale.find_by(locale: 'zj-tw')&.destroy
else
Locale.find_by(locale: 'zj-tw')&.update(locale: 'zh-tw')
end
Translation.where(locale: 'zj-tw')&.update_all(locale: 'zh-tw') # rubocop:disable Rails/SkipsModelValidations
User.where('preferences LIKE ?', "%\nlocale: zj-tw\n%").each do |u|
u.preferences[:locale] = 'zh-tw'
u.save
end
end
end

View file

@ -7,8 +7,14 @@ RSpec.describe Translation do
context 'when getting the list of files for a locale' do
context 'when a locale is nonexistent' do
it 'throws' do
expect { described_class.po_files_for_locale('nonexisting-locale') }.to raise_error "No translation found for locale 'nonexisting-locale'."
it 'logs an error' do
allow(Rails.logger).to receive(:error)
described_class.po_files_for_locale('nonexisting-locale')
expect(Rails.logger).to have_received(:error).with("No translation found for locale 'nonexisting-locale'.")
end
it 'returns an empty array' do
expect(described_class.po_files_for_locale('nonexisting-locale')).to eq([])
end
end
@ -41,8 +47,14 @@ RSpec.describe Translation do
context 'when getting po strings for a locale' do
context 'when getting strings for a nonexistent locale' do
it 'throws' do
expect { described_class.strings_for_locale('nonexisting-locale') }.to raise_error "No translation found for locale 'nonexisting-locale'."
it 'logs an error' do
allow(Rails.logger).to receive(:error)
described_class.strings_for_locale('nonexisting-locale')
expect(Rails.logger).to have_received(:error).with("No translation found for locale 'nonexisting-locale'.")
end
it 'returns an empty array' do
expect(described_class.strings_for_locale('nonexisting-locale')).to eq({})
end
end