mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 19:13:38 +08:00
DEV: Add a rake task to export/import translation overrides (#18487)
Use `bin/rake export:translation_overrides` to export to a file. Then, copy that file to a new site and run `bin/rake import:file["filename"].
This commit is contained in:
parent
15f192447b
commit
4d8011032e
|
@ -6,6 +6,7 @@ require "import_export/category_structure_exporter"
|
||||||
require "import_export/category_exporter"
|
require "import_export/category_exporter"
|
||||||
require "import_export/topic_exporter"
|
require "import_export/topic_exporter"
|
||||||
require "import_export/group_exporter"
|
require "import_export/group_exporter"
|
||||||
|
require "import_export/translation_overrides_exporter"
|
||||||
require "json"
|
require "json"
|
||||||
|
|
||||||
module ImportExport
|
module ImportExport
|
||||||
|
@ -31,4 +32,7 @@ module ImportExport
|
||||||
ImportExport::GroupExporter.new(include_users).perform.save_to_file(filename)
|
ImportExport::GroupExporter.new(include_users).perform.save_to_file(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.export_translation_overrides(filename = nil)
|
||||||
|
ImportExport::TranslationOverridesExporter.new.perform.save_to_file(filename)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -178,6 +178,12 @@ module ImportExport
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def export_translation_overrides
|
||||||
|
@export_data[:translation_overrides] = TranslationOverride.all.select(:locale, :translation_key, :value)
|
||||||
|
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
def default_filename_prefix
|
def default_filename_prefix
|
||||||
raise "Overwrite me!"
|
raise "Overwrite me!"
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ module ImportExport
|
||||||
@groups = data[:groups]
|
@groups = data[:groups]
|
||||||
@categories = data[:categories]
|
@categories = data[:categories]
|
||||||
@topics = data[:topics]
|
@topics = data[:topics]
|
||||||
|
@translation_overrides = data[:translation_overrides]
|
||||||
|
|
||||||
# To support legacy `category_export` script
|
# To support legacy `category_export` script
|
||||||
if data[:category].present?
|
if data[:category].present?
|
||||||
|
@ -25,6 +26,7 @@ module ImportExport
|
||||||
import_groups
|
import_groups
|
||||||
import_categories
|
import_categories
|
||||||
import_topics
|
import_topics
|
||||||
|
import_translation_overrides
|
||||||
|
|
||||||
self
|
self
|
||||||
ensure
|
ensure
|
||||||
|
@ -167,6 +169,18 @@ module ImportExport
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def import_translation_overrides
|
||||||
|
return if @translation_overrides.blank?
|
||||||
|
|
||||||
|
puts "Importing translation overrides..."
|
||||||
|
|
||||||
|
@translation_overrides.each do |tu|
|
||||||
|
TranslationOverride.upsert!(tu[:locale], tu[:translation_key], tu[:value])
|
||||||
|
end
|
||||||
|
|
||||||
|
TranslationOverride.reload_all_overrides!
|
||||||
|
end
|
||||||
|
|
||||||
def new_user_id(external_user_id)
|
def new_user_id(external_user_id)
|
||||||
ucf = UserCustomField.where(name: "import_id", value: "#{external_user_id}#{import_source}").first
|
ucf = UserCustomField.where(name: "import_id", value: "#{external_user_id}#{import_source}").first
|
||||||
ucf ? ucf.user_id : Discourse::SYSTEM_USER_ID
|
ucf ? ucf.user_id : Discourse::SYSTEM_USER_ID
|
||||||
|
|
24
lib/import_export/translation_overrides_exporter.rb
Normal file
24
lib/import_export/translation_overrides_exporter.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module ImportExport
|
||||||
|
class TranslationOverridesExporter < BaseExporter
|
||||||
|
|
||||||
|
def initialize()
|
||||||
|
@export_data = {
|
||||||
|
translation_overrides: []
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform
|
||||||
|
puts "Exporting all translation overrides...", ""
|
||||||
|
export_translation_overrides
|
||||||
|
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_filename_prefix
|
||||||
|
"translation-overrides"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -24,3 +24,11 @@ task 'export:groups', [:include_group_users, :file_name] => [:environment] do |_
|
||||||
ImportExport.export_groups(args[:include_group_users], args[:file_name])
|
ImportExport.export_groups(args[:include_group_users], args[:file_name])
|
||||||
puts "", "Done", ""
|
puts "", "Done", ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'Export all translation overrides'
|
||||||
|
task 'export:translation_overrides' => [:environment] do |_, args|
|
||||||
|
require "import_export"
|
||||||
|
|
||||||
|
ImportExport.export_translation_overrides
|
||||||
|
puts "", "Done", ""
|
||||||
|
end
|
||||||
|
|
3
spec/fixtures/json/import-export.json
vendored
3
spec/fixtures/json/import-export.json
vendored
|
@ -27,5 +27,8 @@
|
||||||
{"id":7,"user_id":-1,"post_number":2,"raw":"Edit the first post in this topic to change the contents of the FAQ/Guidelines page.","created_at":"2017-10-26T17:15:03.822Z","reply_to_post_number":null,"hidden":false,"hidden_reason_id":null,"wiki":false}
|
{"id":7,"user_id":-1,"post_number":2,"raw":"Edit the first post in this topic to change the contents of the FAQ/Guidelines page.","created_at":"2017-10-26T17:15:03.822Z","reply_to_post_number":null,"hidden":false,"hidden_reason_id":null,"wiki":false}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"translation_overrides":[
|
||||||
|
{"locale":"en","translation_key":"login_required.welcome_message","value":"## [Dude, Welcome to %{title}](#welcome)\nAn account is required. Please create an account or log in to continue again!\n"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,7 @@ RSpec.describe ImportExport::Importer do
|
||||||
.and change { Group.count }.by(2)
|
.and change { Group.count }.by(2)
|
||||||
.and change { Topic.count }.by(8)
|
.and change { Topic.count }.by(8)
|
||||||
.and change { User.count }.by(2)
|
.and change { User.count }.by(2)
|
||||||
|
.and change { TranslationOverride.count }.by(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user