Improved support for different version of translation cache files.
This commit is contained in:
parent
4d2e578edf
commit
9b8298de28
3 changed files with 17 additions and 10 deletions
|
@ -70,7 +70,8 @@ all:
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.load_from_file
|
def self.load_from_file
|
||||||
file = Rails.root.join('config/locales.yml')
|
version = Version.get
|
||||||
|
file = Rails.root.join("config/locales-#{version}.yml")
|
||||||
return false if !File.exist?(file)
|
return false if !File.exist?(file)
|
||||||
data = YAML.load_file(file)
|
data = YAML.load_file(file)
|
||||||
to_database(data)
|
to_database(data)
|
||||||
|
@ -88,12 +89,13 @@ all:
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.fetch
|
def self.fetch
|
||||||
|
version = Version.get
|
||||||
url = 'https://i18n.zammad.com/api/v1/locales'
|
url = 'https://i18n.zammad.com/api/v1/locales'
|
||||||
|
|
||||||
result = UserAgent.get(
|
result = UserAgent.get(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
version: Version.get,
|
version: version,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
json: true,
|
json: true,
|
||||||
|
@ -103,7 +105,7 @@ all:
|
||||||
raise "Can't load locales from #{url}" if !result
|
raise "Can't load locales from #{url}" if !result
|
||||||
raise "Can't load locales from #{url}: #{result.error}" if !result.success?
|
raise "Can't load locales from #{url}: #{result.error}" if !result.success?
|
||||||
|
|
||||||
file = Rails.root.join('config/locales.yml')
|
file = Rails.root.join("config/locales-#{version}.yml")
|
||||||
File.open(file, 'w') do |out|
|
File.open(file, 'w') do |out|
|
||||||
YAML.dump(result.data, out)
|
YAML.dump(result.data, out)
|
||||||
end
|
end
|
||||||
|
|
|
@ -225,9 +225,10 @@ all:
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.load_from_file(dedicated_locale = nil)
|
def self.load_from_file(dedicated_locale = nil)
|
||||||
|
version = Version.get
|
||||||
directory = Rails.root.join('config/translations')
|
directory = Rails.root.join('config/translations')
|
||||||
locals_to_sync(dedicated_locale).each { |locale|
|
locals_to_sync(dedicated_locale).each { |locale|
|
||||||
file = Rails.root.join("#{directory}/#{locale}.yml")
|
file = Rails.root.join("#{directory}/#{locale}-#{version}.yml")
|
||||||
return false if !File.exist?(file)
|
return false if !File.exist?(file)
|
||||||
data = YAML.load_file(file)
|
data = YAML.load_file(file)
|
||||||
to_database(locale, data)
|
to_database(locale, data)
|
||||||
|
@ -250,6 +251,7 @@ all:
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.fetch(dedicated_locale = nil)
|
def self.fetch(dedicated_locale = nil)
|
||||||
|
version = Version.get
|
||||||
locals_to_sync(dedicated_locale).each { |locale|
|
locals_to_sync(dedicated_locale).each { |locale|
|
||||||
url = "https://i18n.zammad.com/api/v1/translations/#{locale}"
|
url = "https://i18n.zammad.com/api/v1/translations/#{locale}"
|
||||||
if !UserInfo.current_user_id
|
if !UserInfo.current_user_id
|
||||||
|
@ -258,7 +260,7 @@ all:
|
||||||
result = UserAgent.get(
|
result = UserAgent.get(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
version: Version.get,
|
version: version,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
json: true,
|
json: true,
|
||||||
|
@ -272,7 +274,7 @@ all:
|
||||||
if !File.directory?(directory)
|
if !File.directory?(directory)
|
||||||
Dir.mkdir(directory, 0o755)
|
Dir.mkdir(directory, 0o755)
|
||||||
end
|
end
|
||||||
file = Rails.root.join("#{directory}/#{locale}.yml")
|
file = Rails.root.join("#{directory}/#{locale}-#{version}.yml")
|
||||||
File.open(file, 'w') do |out|
|
File.open(file, 'w') do |out|
|
||||||
YAML.dump(result.data, out)
|
YAML.dump(result.data, out)
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,14 +7,17 @@ require 'net/http'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
|
||||||
|
version = File.read('VERSION')
|
||||||
|
version.strip!
|
||||||
|
|
||||||
url_locales = 'https://i18n.zammad.com/api/v1/locales'
|
url_locales = 'https://i18n.zammad.com/api/v1/locales'
|
||||||
url_translations = 'https://i18n.zammad.com/api/v1/translations/'
|
url_translations = 'https://i18n.zammad.com/api/v1/translations/'
|
||||||
|
|
||||||
file_locales = 'config/locales.yml'
|
file_locales = "config/locales-#{version}.yml"
|
||||||
directory_translations = 'config/translations'
|
directory_translations = 'config/translations'
|
||||||
|
|
||||||
# download locales
|
# download locales
|
||||||
uri = URI.parse(url_locales)
|
uri = URI.parse("#{url_locales}?version=#{version}")
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
http.use_ssl = true
|
http.use_ssl = true
|
||||||
request = Net::HTTP::Get.new(uri)
|
request = Net::HTTP::Get.new(uri)
|
||||||
|
@ -31,14 +34,14 @@ if !File.directory?(directory_translations)
|
||||||
Dir.mkdir(directory_translations, 0o755)
|
Dir.mkdir(directory_translations, 0o755)
|
||||||
end
|
end
|
||||||
data.each { |locale|
|
data.each { |locale|
|
||||||
url = "#{url_translations}#{locale['locale']}.yml"
|
url = "#{url_translations}#{locale['locale']}?version=#{version}"
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
http.use_ssl = true
|
http.use_ssl = true
|
||||||
request = Net::HTTP::Get.new(uri)
|
request = Net::HTTP::Get.new(uri)
|
||||||
response = http.request(request)
|
response = http.request(request)
|
||||||
data = JSON.parse(response.body)
|
data = JSON.parse(response.body)
|
||||||
file = "#{directory_translations}/#{locale['locale']}.yml"
|
file = "#{directory_translations}/#{locale['locale']}-#{version}.yml"
|
||||||
puts "Writing #{file}..."
|
puts "Writing #{file}..."
|
||||||
File.open(file, 'w') do |out|
|
File.open(file, 'w') do |out|
|
||||||
YAML.dump(data, out)
|
YAML.dump(data, out)
|
||||||
|
|
Loading…
Reference in a new issue