ad_localize 4.1.1 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) 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 +70 -15
  6. data/Gemfile +1 -0
  7. data/Gemfile.lock +63 -61
  8. data/README.md +37 -10
  9. data/Rakefile +1 -0
  10. data/ad_localize.gemspec +14 -13
  11. data/bin/console +1 -1
  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 +27 -18
  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 -21
  36. data/lib/ad_localize/option_handler.rb +50 -26
  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 +97 -53
  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 -11
  48. data/lib/ad_localize/serializers/localizable_stringsdict_serializer.rb +12 -19
  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 -34
  59. metadata +86 -69
  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 -43
  64. data/lib/ad_localize/interactors/export_csv_files.rb +0 -17
  65. data/lib/ad_localize/interactors/export_g_spreadsheet.rb +0 -59
  66. data/lib/ad_localize/interactors/platforms/export_android_locale_wording.rb +0 -43
  67. data/lib/ad_localize/interactors/platforms/export_csv_locale_wording.rb +0 -25
  68. data/lib/ad_localize/interactors/platforms/export_ios_locale_wording.rb +0 -66
  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 -33
  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/g_spreadsheet_options.rb +0 -47
  80. data/lib/ad_localize/requests/merge_policy.rb +0 -28
  81. data/lib/ad_localize/serializers/with_template.rb +0 -19
  82. data/lib/ad_localize/validators/key_validator.rb +0 -31
  83. data/lib/ad_localize/view_models/translation_group_view_model.rb +0 -19
  84. data/lib/ad_localize/view_models/translation_view_model.rb +0 -23
@@ -1,47 +0,0 @@
1
- module AdLocalize
2
- module Requests
3
- class GSpreadsheetOptions
4
- attr_accessor(
5
- :spreadsheet_id,
6
- :sheet_ids,
7
- :export_all,
8
- :service_account_config
9
- )
10
-
11
- def initialize(**args)
12
- @spreadsheet_id = args[:spreadsheet_id]
13
- @sheet_ids = Array(args[:sheet_ids])
14
- @export_all = args[:export_all] || false
15
- @service_account_config = args[:service_account_config].presence
16
- end
17
-
18
- def valid?
19
- (spreadsheet_id && !export_all) || (spreadsheet_id && service_account_config.present?)
20
- end
21
-
22
- def public_download_urls
23
- return [] if @service_account_config
24
- if @sheet_ids.size.zero?
25
- [public_download_url(sheet_id: nil)]
26
- else
27
- @sheet_ids.map { |sheet_id| public_download_url(sheet_id: sheet_id) }
28
- end
29
- end
30
-
31
- def has_multiple_sheets?
32
- export_all || @sheet_ids.size > 1
33
- end
34
-
35
- private
36
-
37
- def public_download_url(sheet_id:)
38
- query_id = sheet_id.blank? ? "id=#{@spreadsheet_id}" : "gid=#{sheet_id}"
39
- "https://docs.google.com/spreadsheets/d/#{@spreadsheet_id}/export?format=csv&#{query_id}"
40
- end
41
-
42
- def valid_export_all_config
43
- export_all && service_account_config.present?
44
- end
45
- end
46
- end
47
- end
@@ -1,28 +0,0 @@
1
- module AdLocalize
2
- module Requests
3
- class MergePolicy
4
- REPLACE_POLICY = 'replace'.freeze
5
- KEEP_POLICY = 'keep'.freeze
6
- MERGE_POLICIES = [KEEP_POLICY, REPLACE_POLICY]
7
- DEFAULT_POLICY = KEEP_POLICY
8
-
9
- attr_reader(:policy)
10
-
11
- def initialize(policy:)
12
- @policy = policy
13
- end
14
-
15
- def keep?
16
- @policy == KEEP_POLICY
17
- end
18
-
19
- def replace?
20
- @policy == REPLACE_POLICY
21
- end
22
-
23
- def valid?
24
- @policy.present? && MERGE_POLICIES.include?(@policy)
25
- end
26
- end
27
- end
28
- end
@@ -1,19 +0,0 @@
1
- module AdLocalize
2
- module Serializers
3
- module WithTemplate
4
- TEMPLATES_DIRECTORY = __dir__ + "/../templates"
5
-
6
- def render(locale_wording:)
7
- hash_binding = hash_binding(locale_wording: locale_wording)
8
- return unless hash_binding
9
- render_template(template_path: template_path, hash_binding: hash_binding)
10
- end
11
-
12
- def render_template(template_path:, hash_binding:)
13
- template = File.read(template_path)
14
- renderer = ERB.new(template, trim_mode: '-')
15
- renderer.result_with_hash(hash_binding)
16
- end
17
- end
18
- end
19
- end
@@ -1,31 +0,0 @@
1
- module AdLocalize
2
- module Validators
3
- class KeyValidator
4
-
5
- def initialize
6
- @existing_key_for_label = {}
7
- end
8
-
9
- def has_warnings?(current_key)
10
- current_label = current_key.label
11
- existing_key = @existing_key_for_label[current_label]
12
-
13
- has_warnings = false
14
-
15
- unless existing_key.nil?
16
- existing_plural_key = existing_key.label == current_key.label && existing_key.plural? && current_key.singular?
17
- existing_singular_key = existing_key.label == current_key.label && existing_key.singular? && current_key.plural?
18
- is_same_key = existing_key.same_as?(key: current_key)
19
- LOGGER.warn "A plural value already exist for key '#{current_label}'. Remove duplicates." if existing_plural_key
20
- LOGGER.warn "A singular value already exist for key '#{current_label}'. Remove duplicates." if existing_singular_key
21
- LOGGER.warn "Some values already exist for key '#{current_label}'. Remove duplicates." if is_same_key
22
- has_warnings = is_same_key || existing_plural_key || existing_singular_key
23
- end
24
-
25
- @existing_key_for_label[current_label] = current_key
26
-
27
- has_warnings
28
- end
29
- end
30
- end
31
- end
@@ -1,19 +0,0 @@
1
- module AdLocalize
2
- module ViewModels
3
- class TranslationGroupViewModel
4
- attr_reader(
5
- :label,
6
- :translation_view_models
7
- )
8
-
9
- def initialize(label:, translation_view_models:)
10
- @label = label
11
- @translation_view_models = translation_view_models
12
- end
13
-
14
- def has_translations?
15
- (translation_view_models || []).any?(&:has_value?)
16
- end
17
- end
18
- end
19
- end
@@ -1,23 +0,0 @@
1
- module AdLocalize
2
- module ViewModels
3
- class TranslationViewModel
4
- attr_reader(
5
- :label,
6
- :key,
7
- :value,
8
- :comment
9
- )
10
-
11
- def initialize(label:, key:, value:, comment:)
12
- @label = label
13
- @key = key
14
- @value = value
15
- @comment = comment
16
- end
17
-
18
- def has_value?
19
- value.present?
20
- end
21
- end
22
- end
23
- end