Fixes #4016 - Translations are not available in API after syncing
This commit is contained in:
parent
2e02221535
commit
2d6149234d
3 changed files with 34 additions and 17 deletions
|
@ -4,9 +4,6 @@ class Translation < ApplicationModel
|
||||||
include Translation::SynchronizesFromPo
|
include Translation::SynchronizesFromPo
|
||||||
|
|
||||||
before_create :set_initial
|
before_create :set_initial
|
||||||
after_create :cache_clear
|
|
||||||
after_update :cache_clear
|
|
||||||
after_destroy :cache_clear
|
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
|
@ -44,7 +41,7 @@ get list of translations
|
||||||
|
|
||||||
# use cache if not admin page is requested
|
# use cache if not admin page is requested
|
||||||
if !admin
|
if !admin
|
||||||
data = cache_get(locale)
|
data = lang_cache_get(locale)
|
||||||
return data if data
|
return data if data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -91,7 +88,7 @@ get list of translations
|
||||||
|
|
||||||
# set cache
|
# set cache
|
||||||
if !admin
|
if !admin
|
||||||
cache_set(locale, data)
|
lang_cache_set(locale, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
data
|
data
|
||||||
|
@ -220,6 +217,23 @@ or
|
||||||
[true, nil]
|
[true, nil]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.import(locale, translations)
|
||||||
|
bulk_import translations
|
||||||
|
lang_cache_clear(locale)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.lang_cache_clear(locale)
|
||||||
|
Cache.delete lang_cache_key(locale)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.lang_cache_set(locale, data)
|
||||||
|
Cache.write lang_cache_key(locale), data
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.lang_cache_get(locale)
|
||||||
|
Cache.read lang_cache_key(locale)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_initial
|
def set_initial
|
||||||
|
@ -230,18 +244,13 @@ or
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_clear
|
def cache_delete
|
||||||
Cache.delete("TranslationMapOnlyContent::#{locale.downcase}")
|
super
|
||||||
true
|
self.class.lang_cache_clear(locale) # delete whole lang cache as well
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cache_set(locale, data)
|
def self.lang_cache_key(locale)
|
||||||
Cache.write("TranslationMapOnlyContent::#{locale.downcase}", data)
|
"TranslationMapOnlyContent::#{locale.downcase}"
|
||||||
end
|
end
|
||||||
private_class_method :cache_set
|
private_class_method :lang_cache_key
|
||||||
|
|
||||||
def self.cache_get(locale)
|
|
||||||
Cache.read("TranslationMapOnlyContent::#{locale.downcase}")
|
|
||||||
end
|
|
||||||
private_class_method :cache_get
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,7 +59,7 @@ module Translation::SynchronizesFromPo
|
||||||
updated_translation_ids.add t.id
|
updated_translation_ids.add t.id
|
||||||
end
|
end
|
||||||
|
|
||||||
Translation.import importable_translations
|
Translation.import locale, importable_translations
|
||||||
# Remove any unmodified & synchronized strings that are not present in the data any more.
|
# Remove any unmodified & synchronized strings that are not present in the data any more.
|
||||||
previous_unmodified_translations.reject { |t| updated_translation_ids.member? t.id }.each(&:destroy!)
|
previous_unmodified_translations.reject { |t| updated_translation_ids.member? t.id }.each(&:destroy!)
|
||||||
true
|
true
|
||||||
|
|
|
@ -179,6 +179,14 @@ RSpec.describe Translation do
|
||||||
expect(described_class.find_source('de-de', 'yes')).to have_attributes(source: 'yes', target_initial: 'ja', target: 'ja', is_synchronized_from_codebase: true, synchronized_from_translation_file: 'i18n/zammad.de-de.po')
|
expect(described_class.find_source('de-de', 'yes')).to have_attributes(source: 'yes', target_initial: 'ja', target: 'ja', is_synchronized_from_codebase: true, synchronized_from_translation_file: 'i18n/zammad.de-de.po')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'clear cache after sync' do
|
||||||
|
allow(Cache).to receive(:delete)
|
||||||
|
|
||||||
|
described_class.sync_locale_from_po('de-de')
|
||||||
|
|
||||||
|
expect(Cache).to have_received(:delete).with('TranslationMapOnlyContent::de-de')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when synchronizing strings for all locales' do
|
context 'when synchronizing strings for all locales' do
|
||||||
|
|
Loading…
Reference in a new issue