Skip to content

Commit 4f42381

Browse files
Extend localization sync command to support return reasons
- Update sync_en_localizations_command.rb to add return_reasons target - Enable syncing return reasons English localizations - Maintains backward compatibility with existing targets - Uses existing localizations_serializer for consistent output - Establishes foundation for multi-locale support
1 parent ed70e6b commit 4f42381

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

dev/lib/product_taxonomy/commands/sync_en_localizations_command.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module ProductTaxonomy
44
class SyncEnLocalizationsCommand < Command
5-
PERMITTED_TARGETS = ["categories", "attributes", "values"].freeze
5+
PERMITTED_TARGETS = ["categories", "attributes", "values", "return_reasons"].freeze
66

77
def initialize(options)
88
super
@@ -19,6 +19,7 @@ def execute
1919
sync_categories if @targets.include?("categories")
2020
sync_attributes if @targets.include?("attributes")
2121
sync_values if @targets.include?("values")
22+
sync_return_reasons if @targets.include?("return_reasons")
2223
end
2324

2425
private
@@ -41,8 +42,15 @@ def sync_values
4142
write_localizations("values", localizations)
4243
end
4344

45+
def sync_return_reasons
46+
logger.info("Syncing return_reasons...")
47+
localizations = Serializers::ReturnReason::Data::LocalizationsSerializer.serialize_all
48+
write_localizations("return_reasons", localizations)
49+
end
50+
4451
def write_localizations(type, localizations)
4552
file_path = File.expand_path("localizations/#{type}/en.yml", ProductTaxonomy.data_path)
53+
FileUtils.mkdir_p(File.dirname(file_path))
4654
File.open(file_path, "w") do |file|
4755
file.puts "# This file is auto-generated. Do not edit directly."
4856
file.write(YAML.dump(localizations, line_width: -1))

dev/test/commands/sync_en_localizations_command_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SyncEnLocalizationsCommandTest < TestCase
2323

2424
test "initialize sets targets to all permitted targets when not specified" do
2525
command = SyncEnLocalizationsCommand.new({})
26-
assert_equal ["categories", "attributes", "values"], command.instance_variable_get(:@targets)
26+
assert_equal ["categories", "attributes", "values", "return_reasons"], command.instance_variable_get(:@targets)
2727
end
2828

2929
test "initialize accepts custom targets" do

0 commit comments

Comments
 (0)