ad_localize 5.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +6 -3
  3. data/.rubocop.yml +5 -0
  4. data/.rubocop_todo.yml +319 -0
  5. data/CHANGELOG.md +24 -0
  6. data/Gemfile +1 -0
  7. data/Gemfile.lock +54 -48
  8. data/README.md +32 -10
  9. data/Rakefile +1 -0
  10. data/ad_localize.gemspec +10 -9
  11. data/bin/console +1 -0
  12. data/exe/ad_localize +2 -1
  13. data/lib/ad_localize/ad_logger.rb +5 -10
  14. data/lib/ad_localize/cli.rb +10 -3
  15. data/lib/ad_localize/entities/key.rb +3 -76
  16. data/lib/ad_localize/entities/locale_wording.rb +32 -52
  17. data/lib/ad_localize/entities/platform.rb +13 -0
  18. data/lib/ad_localize/entities/simple_wording.rb +6 -0
  19. data/lib/ad_localize/entities/wording_type.rb +11 -0
  20. data/lib/ad_localize/interactors/base_generate_files.rb +37 -0
  21. data/lib/ad_localize/interactors/download_spreadsheets.rb +20 -0
  22. data/lib/ad_localize/interactors/export_wording.rb +26 -20
  23. data/lib/ad_localize/interactors/generate_info_plist.rb +24 -0
  24. data/lib/ad_localize/interactors/generate_ios_files.rb +12 -0
  25. data/lib/ad_localize/interactors/generate_json.rb +20 -0
  26. data/lib/ad_localize/interactors/generate_localizable_strings.rb +24 -0
  27. data/lib/ad_localize/interactors/generate_localizable_strings_dict.rb +24 -0
  28. data/lib/ad_localize/interactors/generate_properties.rb +20 -0
  29. data/lib/ad_localize/interactors/generate_strings.rb +25 -0
  30. data/lib/ad_localize/interactors/generate_yaml.rb +20 -0
  31. data/lib/ad_localize/interactors/merge_wordings.rb +49 -18
  32. data/lib/ad_localize/interactors/parse_csv_files.rb +22 -0
  33. data/lib/ad_localize/interactors/process_export_request.rb +21 -0
  34. data/lib/ad_localize/mappers/locale_wording_to_hash.rb +45 -24
  35. data/lib/ad_localize/mappers/options_to_export_request.rb +14 -22
  36. data/lib/ad_localize/option_handler.rb +50 -27
  37. data/lib/ad_localize/parsers/csv_parser.rb +84 -0
  38. data/lib/ad_localize/parsers/key_parser.rb +62 -0
  39. data/lib/ad_localize/repositories/drive_repository.rb +53 -0
  40. data/lib/ad_localize/repositories/file_system_repository.rb +2 -1
  41. data/lib/ad_localize/requests/export_request.rb +95 -57
  42. data/lib/ad_localize/sanitizers/ios_sanitizer.rb +12 -0
  43. data/lib/ad_localize/{mappers/android_translation_mapper.rb → sanitizers/ios_to_android_sanitizer.rb} +8 -8
  44. data/lib/ad_localize/sanitizers/pass_through_sanitizer.rb +10 -0
  45. data/lib/ad_localize/serializers/info_plist_serializer.rb +9 -11
  46. data/lib/ad_localize/serializers/json_serializer.rb +3 -5
  47. data/lib/ad_localize/serializers/localizable_strings_serializer.rb +9 -15
  48. data/lib/ad_localize/serializers/localizable_stringsdict_serializer.rb +12 -25
  49. data/lib/ad_localize/serializers/properties_serializer.rb +9 -11
  50. data/lib/ad_localize/serializers/strings_serializer.rb +12 -21
  51. data/lib/ad_localize/serializers/templated_serializer.rb +51 -0
  52. data/lib/ad_localize/serializers/yaml_serializer.rb +4 -6
  53. data/lib/ad_localize/templates/android/strings.xml.erb +6 -6
  54. data/lib/ad_localize/templates/ios/Localizable.stringsdict.erb +14 -14
  55. data/lib/ad_localize/version.rb +2 -1
  56. data/lib/ad_localize/view_models/compound_wording_view_model.rb +2 -0
  57. data/lib/ad_localize/view_models/simple_wording_view_model.rb +2 -0
  58. data/lib/ad_localize.rb +33 -35
  59. metadata +70 -47
  60. data/lib/ad_localize/constant.rb +0 -6
  61. data/lib/ad_localize/entities/translation.rb +0 -32
  62. data/lib/ad_localize/entities/wording.rb +0 -24
  63. data/lib/ad_localize/interactors/execute_export_request.rb +0 -45
  64. data/lib/ad_localize/interactors/export_csv_files.rb +0 -20
  65. data/lib/ad_localize/interactors/export_g_spreadsheet.rb +0 -64
  66. data/lib/ad_localize/interactors/platforms/export_android_locale_wording.rb +0 -44
  67. data/lib/ad_localize/interactors/platforms/export_csv_locale_wording.rb +0 -22
  68. data/lib/ad_localize/interactors/platforms/export_ios_locale_wording.rb +0 -75
  69. data/lib/ad_localize/interactors/platforms/export_json_locale_wording.rb +0 -27
  70. data/lib/ad_localize/interactors/platforms/export_platform_factory.rb +0 -50
  71. data/lib/ad_localize/interactors/platforms/export_properties_locale_wording.rb +0 -32
  72. data/lib/ad_localize/interactors/platforms/export_yaml_locale_wording.rb +0 -27
  73. data/lib/ad_localize/mappers/csv_path_to_wording.rb +0 -73
  74. data/lib/ad_localize/mappers/ios_translation_mapper.rb +0 -12
  75. data/lib/ad_localize/mappers/translation_group_mapper.rb +0 -14
  76. data/lib/ad_localize/mappers/translation_mapper.rb +0 -30
  77. data/lib/ad_localize/mappers/value_range_to_wording.rb +0 -67
  78. data/lib/ad_localize/repositories/g_sheets_repository.rb +0 -44
  79. data/lib/ad_localize/requests/export_wording_options.rb +0 -24
  80. data/lib/ad_localize/requests/g_spreadsheet_options.rb +0 -47
  81. data/lib/ad_localize/requests/merge_policy.rb +0 -28
  82. data/lib/ad_localize/serializers/with_template.rb +0 -19
  83. data/lib/ad_localize/validators/key_validator.rb +0 -31
  84. data/lib/ad_localize/view_models/translation_group_view_model.rb +0 -19
  85. data/lib/ad_localize/view_models/translation_view_model.rb +0 -23
data/ad_localize.gemspec CHANGED
@@ -1,4 +1,4 @@
1
-
1
+ # frozen_string_literal: true
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'ad_localize/version'
@@ -7,7 +7,6 @@ Gem::Specification.new do |spec|
7
7
  spec.name = 'ad_localize'
8
8
  spec.version = AdLocalize::VERSION
9
9
  spec.license = 'MIT'
10
- spec.date = '2018-04-18'
11
10
  spec.authors = [
12
11
  'Edouard Siegel',
13
12
  'Patrick Nollet',
@@ -24,11 +23,11 @@ Gem::Specification.new do |spec|
24
23
  'Satyan Jacquens',
25
24
  'Thomas Esterlin'
26
25
  ]
27
- spec.email = %w(joanna.vigne@fabernovel.com pierre.felgines@fabernovel.com edouard.siegel@fabernovel.com)
26
+ spec.email = %w[joanna.vigne@fabernovel.com pierre.felgines@fabernovel.com edouard.siegel@fabernovel.com]
28
27
 
29
- spec.summary = %q{AdLocalize helps with mobile and web applications wording}
30
- spec.description = %q{AdLocalize produces localization files from platform agnostic wording.
31
- Supported wording format : CSV. Supported export format: iOS, Android, JSON and YAML}
28
+ spec.summary = %q(AdLocalize helps with mobile and web applications wording)
29
+ spec.description = %q(AdLocalize produces localization files from platform agnostic wording.
30
+ Supported wording format : CSV. Supported export format: iOS, Android, JSON and YAML)
32
31
  spec.homepage = 'https://github.com/applidium/ad_localize'
33
32
 
34
33
  # Specify which files should be added to the gem when it is released.
@@ -45,12 +44,14 @@ Gem::Specification.new do |spec|
45
44
  spec.add_development_dependency 'minitest', '~> 5.11'
46
45
  spec.add_development_dependency 'minitest-reporters', '~> 1.3'
47
46
  spec.add_development_dependency 'diffy', '~> 3.3'
47
+ spec.add_development_dependency 'debug', ">= 1.0.0", '< 2.0'
48
+ spec.add_development_dependency 'rubocop', "~> 1.0"
48
49
 
49
50
  spec.add_dependency 'activesupport', '>= 6.1.3.2', '< 8.0'
50
- spec.add_dependency 'nokogiri', '~> 1.10'
51
51
  spec.add_dependency 'colorize', '~> 0.8'
52
- spec.add_dependency 'googleauth', '~> 0.12'
53
52
  spec.add_dependency 'google-apis-sheets_v4', '~> 0.9'
53
+ spec.add_dependency 'google-apis-drive_v3', '~> 0.33.0'
54
54
 
55
- spec.required_ruby_version = '>= 2.7'
55
+ spec.required_ruby_version = '>= 2.7', '< 4.0'
56
+ spec.metadata['rubygems_mfa_required'] = 'true'
56
57
  end
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "ad_localize"
data/exe/ad_localize CHANGED
@@ -1,3 +1,4 @@
1
1
  #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  require 'ad_localize'
3
- AdLocalize::CLI.start(args: ARGV)
4
+ AdLocalize::CLI.start(args: ARGV)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module AdLocalize
2
3
  class AdLogger
3
4
  def initialize
@@ -6,19 +7,19 @@ module AdLocalize
6
7
  end
7
8
 
8
9
  def warn(text)
9
- log(level: Logger::WARN, text: text.yellow)
10
+ @logger.warn(text.yellow)
10
11
  end
11
12
 
12
13
  def info(text)
13
- log(level: Logger::INFO, text: text.blue)
14
+ @logger.info(text.blue)
14
15
  end
15
16
 
16
17
  def error(text)
17
- log(level: Logger::ERROR, text: text.red)
18
+ @logger.error(text.red)
18
19
  end
19
20
 
20
21
  def debug(text)
21
- log(level: Logger::DEBUG, text: text)
22
+ @logger.debug(text)
22
23
  end
23
24
 
24
25
  def info!
@@ -36,11 +37,5 @@ module AdLocalize
36
37
  def close
37
38
  @logger.close
38
39
  end
39
-
40
- private
41
-
42
- def log(level:, text:)
43
- @logger.add(level, text)
44
- end
45
40
  end
46
41
  end
@@ -1,10 +1,17 @@
1
+ # frozen_string_literal: true
1
2
  module AdLocalize
2
3
  class CLI
3
4
  def self.start(args:)
4
5
  options = OptionHandler.parse!(args)
5
6
  export_request = Mappers::OptionsToExportRequest.new.map(options: options)
6
- export_request.csv_paths = options[:csv_paths]
7
- Interactors::ExecuteExportRequest.new.call(export_request: export_request)
7
+ LOGGER.debug("Export request options : #{export_request}")
8
+ export_request.downloaded_csvs = Interactors::DownloadSpreadsheets.new.call(export_request: export_request) if export_request.has_sheets?
9
+ Interactors::ProcessExportRequest.new.call(export_request: export_request)
10
+ ensure
11
+ export_request&.downloaded_csvs&.each do |file|
12
+ file.close
13
+ file.unlink
14
+ end
8
15
  end
9
16
  end
10
- end
17
+ end
@@ -1,79 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  module AdLocalize
2
3
  module Entities
3
- class Key
4
- PLURAL_KEY_REGEXP = /\#\#\{([A-Za-z]+)\}/.freeze
5
- ADAPTIVE_KEY_REGEXP = /\#\#\{(\d+)\}/.freeze
6
- # see https://developer.apple.com/documentation/bundleresources/information_property_list
7
- INFO_PLIST_KEY_REGEXP = /(NS.+UsageDescription)|(CF.+Name)|NFCReaderUsageDescription/.freeze
8
-
9
- def initialize(label:)
10
- @label = label
11
- end
12
-
13
- def plural_key
14
- @plural_key ||= compute_plural_key
15
- end
16
-
17
- def plural?
18
- plural_key.present?
19
- end
20
-
21
- def adaptive?
22
- adaptive_key.present?
23
- end
24
-
25
- def adaptive_key
26
- @adaptive_key ||= compute_adaptive_key
27
- end
28
-
29
- def info_plist?
30
- @label.match(INFO_PLIST_KEY_REGEXP).present?
31
- end
32
-
33
- def singular?
34
- !(plural? || adaptive? || info_plist?)
35
- end
36
-
37
- def label
38
- compute_label.strip
39
- end
40
-
41
- def raw_label
42
- @label
43
- end
44
-
45
- def same_as?(key:)
46
- raw_label == key.raw_label
47
- end
48
-
49
- def ==(o)
50
- o.class == self.class &&
51
- o.raw_label == raw_label
52
- end
53
-
54
- private
55
-
56
- def compute_label
57
- if plural?
58
- @label.gsub(PLURAL_KEY_REGEXP, '')
59
- elsif adaptive?
60
- @label.gsub(ADAPTIVE_KEY_REGEXP, '')
61
- else
62
- @label
63
- end
64
- end
65
-
66
- def compute_plural_key
67
- match = @label.match(PLURAL_KEY_REGEXP)
68
- return unless match
69
- match.captures.first
70
- end
71
-
72
- def compute_adaptive_key
73
- match = @label.match(ADAPTIVE_KEY_REGEXP)
74
- return unless match
75
- match.captures.first
76
- end
77
- end
4
+ Key = Struct.new(:id, :label, :variant_name, :type, keyword_init: true)
78
5
  end
79
- end
6
+ end
@@ -1,60 +1,40 @@
1
+ # frozen_string_literal: true
1
2
  module AdLocalize
2
3
  module Entities
3
4
  class LocaleWording
4
- attr_reader(:locale, :translations)
5
+ attr_reader :locale, :is_default, :singulars, :plurals, :adaptives, :info_plists
5
6
 
6
- def initialize(locale:, translations:)
7
+ def initialize(locale:, is_default:)
7
8
  @locale = locale
8
- @translations = translations
9
- end
10
-
11
- def has_plural_keys?
12
- plurals.present?
13
- end
14
-
15
- def has_info_plist_keys?
16
- info_plists.present?
17
- end
18
-
19
- def has_singular_keys?
20
- singulars.present?
21
- end
22
-
23
- def has_adaptive_keys?
24
- adaptives.present?
25
- end
26
-
27
- def plurals
28
- @plurals ||= @translations.select { |translation| translation.key.plural? }.group_by { |translation| translation.key.label }
29
- end
30
-
31
- def info_plists
32
- @info_plists ||= @translations.select { |translation| translation.key.info_plist? }
33
- end
34
-
35
- def singulars
36
- @singulars ||= @translations.select { |translation| translation.key.singular? }
37
- end
38
-
39
- def adaptives
40
- @adaptives ||= @translations.select { |translation| translation.key.adaptive? }.group_by { |translation| translation.key.label }
41
- end
42
-
43
- def add_translation(translation:)
44
- @translations.push(translation)
45
- end
46
-
47
- def keys
48
- @translations.map(&:key)
49
- end
50
-
51
- def has_key?(key:)
52
- translation_for(key: key).present?
53
- end
54
-
55
- def translation_for(key:)
56
- @translations.find { |translation| translation.key.same_as?(key: key) }
9
+ @is_default = is_default
10
+ @singulars = {} # label => SimpleWording
11
+ @info_plists = {} # label => SimpleWording
12
+ @plurals = Hash.new { |hash, key| hash[key] = {} } # label: String => { variant_name: String => SimpleWording }
13
+ @adaptives = Hash.new { |hash, key| hash[key] = {} } # label: String => { variant_name: String => SimpleWording }
14
+ end
15
+
16
+ def add_wording(key:, value:, comment:)
17
+ wording = SimpleWording.new(key: key, value: value, comment: comment)
18
+
19
+ case key.type
20
+ when WordingType::PLURAL
21
+ @plurals[key.label][key.variant_name] = wording
22
+ when WordingType::ADAPTIVE
23
+ @adaptives[key.label][key.variant_name] = wording
24
+ when WordingType::INFO_PLIST
25
+ @info_plists[key.label] = wording
26
+ else
27
+ @singulars[key.label] = wording
28
+ end
29
+ end
30
+
31
+ def to_s
32
+ "Locale\nis default: #{is_default}\n==========\n" +
33
+ "Singulars\n#{singulars}\n==========\n" +
34
+ "InfoPlists\n#{info_plists}\n==========\n" +
35
+ "Plurals\n#{plurals}\n==========\n" +
36
+ "Adaptives\n#{adaptives}\n==========\n"
57
37
  end
58
38
  end
59
39
  end
60
- end
40
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Entities
4
+ module Platform
5
+ IOS = 'ios'
6
+ ANDROID = 'android'
7
+ YML = 'yml'
8
+ JSON = 'json'
9
+ PROPERTIES = 'properties'
10
+ SUPPORTED_PLATFORMS = [IOS, ANDROID, YML, JSON, PROPERTIES]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Entities
4
+ SimpleWording = Struct.new(:key, :value, :comment, keyword_init: true)
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Entities
4
+ module WordingType
5
+ SINGULAR = 'singular'
6
+ PLURAL = 'plural'
7
+ INFO_PLIST = 'info_plist'
8
+ ADAPTIVE = 'adaptive'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class BaseGenerateFiles
5
+ def initialize(serializer:)
6
+ @serializer = serializer
7
+ raise MissingArgument.new('Missing Serializer') unless serializer
8
+
9
+ @file_system_repository = Repositories::FileSystemRepository.new
10
+ end
11
+
12
+ def call(wording:, export_request:)
13
+ wording.each do |locale, locale_wording|
14
+ next unless has_wording?(locale_wording: locale_wording)
15
+
16
+ path = output_path(locale_wording: locale_wording, export_request: export_request)
17
+ filename = path.basename
18
+ LOGGER.debug("[#{locale}] Generating #{filename}")
19
+ @file_system_repository.create_directory(path: path.dirname)
20
+ content = @serializer.render(locale_wording: locale_wording)
21
+ @file_system_repository.write(content: content, path: path)
22
+ LOGGER.debug("[#{locale}] #{filename} done !")
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def has_wording?(locale_wording:)
29
+ raise 'override me!'
30
+ end
31
+
32
+ def output_path(locale_wording:, export_request:)
33
+ raise 'override me!'
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class DownloadSpreadsheets
5
+ def initialize
6
+ @drive_repository = Repositories::DriveRepository.new
7
+ end
8
+
9
+ def call(export_request:)
10
+ LOGGER.debug("Downloading spreadsheets")
11
+ if export_request.export_all
12
+ @drive_repository.download_all_sheets(spreadsheet_id: export_request.spreadsheet_id)
13
+ else
14
+ @drive_repository.download_sheets_by_id(spreadsheet_id: export_request.spreadsheet_id,
15
+ sheet_ids: export_request.sheet_ids)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,34 +1,40 @@
1
+ # frozen_string_literal: true
1
2
  module AdLocalize
2
3
  module Interactors
3
4
  class ExportWording
4
- def initialize
5
- @export_platform_factory = Platforms::ExportPlatformFactory.new
6
- end
7
-
8
5
  def call(export_request:, wording:)
9
- LOGGER.debug("Starting export wording")
10
6
  export_request.platforms.each do |platform|
11
- platform_interactor = @export_platform_factory.build(platform: platform)
12
- options = build_export_wording_options(wording: wording, export_request: export_request, platform: platform)
13
- platform_interactor.call(export_wording_options: options)
7
+ configure_output_directory(platform: platform, export_request: export_request)
8
+ LOGGER.debug("[#{platform}] Start exporting in #{export_request.output_dir}")
9
+ export_platform(wording: wording, platform: platform, export_request: export_request)
10
+ LOGGER.debug("[#{platform}] done !")
14
11
  end
15
12
  end
16
13
 
17
14
  private
18
15
 
19
- def build_export_wording_options(wording:, export_request:, platform:)
20
- platform_output_directory = export_request.output_path
21
- platform_output_directory = platform_output_directory.join(platform.to_s) if export_request.multiple_platforms?
22
- locales = export_request.locales.size.zero? ? wording.locales : wording.locales & export_request.locales
16
+ def configure_output_directory(platform:, export_request:)
17
+ if export_request.many_platforms?
18
+ export_request.output_dir = export_request.output_path.join(platform)
19
+ else
20
+ export_request.output_dir = export_request.output_path
21
+ end
22
+ end
23
23
 
24
- Requests::ExportWordingOptions.new(
25
- locales: locales,
26
- wording: wording,
27
- platform_output_directory: platform_output_directory,
28
- bypass_empty_values: export_request.non_empty_values,
29
- csv_paths: export_request.csv_paths
30
- )
24
+ def export_platform(wording:, platform:, export_request:)
25
+ case platform
26
+ when Entities::Platform::IOS
27
+ GenerateIOSFiles.new.call(wording: wording, export_request: export_request)
28
+ when Entities::Platform::ANDROID
29
+ GenerateStrings.new.call(wording: wording, export_request: export_request)
30
+ when Entities::Platform::YML
31
+ GenerateYAML.new.call(wording: wording, export_request: export_request)
32
+ when Entities::Platform::JSON
33
+ GenerateJSON.new.call(wording: wording, export_request: export_request)
34
+ when Entities::Platform::PROPERTIES
35
+ GenerateProperties.new.call(wording: wording, export_request: export_request)
36
+ end
31
37
  end
32
38
  end
33
39
  end
34
- end
40
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class GenerateInfoPlist < BaseGenerateFiles
5
+ INFO_PLIST_FILENAME = "InfoPlist.strings".freeze
6
+ LOCALE_DIRECTORY_CONVENTION = "%{locale}.lproj".freeze
7
+
8
+ def initialize
9
+ super(serializer: Serializers::InfoPlistSerializer.new)
10
+ end
11
+
12
+ private
13
+
14
+ def has_wording?(locale_wording:)
15
+ locale_wording.info_plists.any?
16
+ end
17
+
18
+ def output_path(locale_wording:, export_request:)
19
+ locale_directory_name = LOCALE_DIRECTORY_CONVENTION % { locale: locale_wording.locale }
20
+ export_request.output_dir.join(locale_directory_name, INFO_PLIST_FILENAME)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class GenerateIOSFiles
5
+ def call(wording:, export_request:)
6
+ GenerateInfoPlist.new.call(wording: wording, export_request: export_request)
7
+ GenerateLocalizableStrings.new.call(wording: wording, export_request: export_request)
8
+ GenerateLocalizableStringsDict.new.call(wording: wording, export_request: export_request)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class GenerateJSON < BaseGenerateFiles
5
+ def initialize
6
+ super(serializer: Serializers::JSONSerializer.new)
7
+ end
8
+
9
+ private
10
+
11
+ def has_wording?(locale_wording:)
12
+ locale_wording.singulars.any? || locale_wording.plurals.any?
13
+ end
14
+
15
+ def output_path(locale_wording:, export_request:)
16
+ export_request.output_dir.join("#{locale_wording.locale}.json")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class GenerateLocalizableStrings < BaseGenerateFiles
5
+ LOCALIZABLE_STRINGS_FILENAME = "Localizable.strings".freeze
6
+ LOCALE_DIRECTORY_CONVENTION = "%{locale}.lproj".freeze
7
+
8
+ def initialize
9
+ super(serializer: Serializers::LocalizableStringsSerializer.new)
10
+ end
11
+
12
+ private
13
+
14
+ def has_wording?(locale_wording:)
15
+ locale_wording.singulars.any?
16
+ end
17
+
18
+ def output_path(locale_wording:, export_request:)
19
+ locale_directory_name = LOCALE_DIRECTORY_CONVENTION % { locale: locale_wording.locale }
20
+ export_request.output_dir.join(locale_directory_name, LOCALIZABLE_STRINGS_FILENAME)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class GenerateLocalizableStringsDict < BaseGenerateFiles
5
+ LOCALIZABLE_STRINGSDICT_FILENAME = "Localizable.stringsdict".freeze
6
+ LOCALE_DIRECTORY_CONVENTION = "%{locale}.lproj".freeze
7
+
8
+ def initialize
9
+ super(serializer: Serializers::LocalizableStringsdictSerializer.new)
10
+ end
11
+
12
+ private
13
+
14
+ def has_wording?(locale_wording:)
15
+ locale_wording.plurals.any? || locale_wording.adaptives.any?
16
+ end
17
+
18
+ def output_path(locale_wording:, export_request:)
19
+ locale_directory_name = LOCALE_DIRECTORY_CONVENTION % { locale: locale_wording.locale }
20
+ export_request.output_dir.join(locale_directory_name, LOCALIZABLE_STRINGSDICT_FILENAME)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class GenerateProperties < BaseGenerateFiles
5
+ def initialize
6
+ super(serializer: Serializers::PropertiesSerializer.new)
7
+ end
8
+
9
+ private
10
+
11
+ def has_wording?(locale_wording:)
12
+ locale_wording.singulars.any?
13
+ end
14
+
15
+ def output_path(locale_wording:, export_request:)
16
+ export_request.output_dir.join("#{locale_wording.locale}.properties")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class GenerateStrings < BaseGenerateFiles
5
+ STRINGS_FILENAME = 'strings.xml'.freeze
6
+ LOCALE_DIRECTORY_CONVENTION = "values".freeze
7
+
8
+ def initialize
9
+ super(serializer: Serializers::StringsSerializer.new)
10
+ end
11
+
12
+ private
13
+
14
+ def has_wording?(locale_wording:)
15
+ locale_wording.singulars.any? || locale_wording.plurals.any?
16
+ end
17
+
18
+ def output_path(locale_wording:, export_request:)
19
+ locale_dir = LOCALE_DIRECTORY_CONVENTION
20
+ locale_dir += "-#{locale_wording.locale}" if !locale_wording.is_default
21
+ export_request.output_dir.join(locale_dir, STRINGS_FILENAME)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module AdLocalize
3
+ module Interactors
4
+ class GenerateYAML < BaseGenerateFiles
5
+ def initialize
6
+ super(serializer: Serializers::YAMLSerializer.new)
7
+ end
8
+
9
+ private
10
+
11
+ def has_wording?(locale_wording:)
12
+ locale_wording.singulars.any? || locale_wording.plurals.any?
13
+ end
14
+
15
+ def output_path(locale_wording:, export_request:)
16
+ export_request.output_dir.join("#{locale_wording.locale}.yml")
17
+ end
18
+ end
19
+ end
20
+ end