ad_localize 6.0.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c1c393dd716aa7f1306df1a86b7e166194efebe24d94e6f5c61628d62026a60
4
- data.tar.gz: 4e1d02d8e92919e656c1fdb77efb620e9f5c812b4c59da5d6682269917886b00
3
+ metadata.gz: b70487e0e8087dbbdb3c6873b025748b9fc97e68ac2abc5c13a0fe71a1a1011c
4
+ data.tar.gz: c82fe7eeb8bc946411c094f51d69df40a35bc9b9e5c5805203a976c4d2aba9c0
5
5
  SHA512:
6
- metadata.gz: 2a041906d4a7f138fc762be1dc4b30ef2b91fcb8419ad4a28c90c24689deb5eb684877671721156ff63c3044788116252789cd14bddefd968731625bb6766cb5
7
- data.tar.gz: f9e3cc3ad69de48aa334471443a554562a2f9a7a47364737bfd5af6755dc5040eba68249dd37e9c5ae4445e7afd0e6259e5d97181c9feb4d4443696f2344bf36
6
+ metadata.gz: 8acdef650f29ede65b72fed96666be542f078337dd6e7b950a8be2ec18b1ff55ee65279dcd5736e5b4d229fed9796b30480cee9b72194ad1bdbba87fa388d81b
7
+ data.tar.gz: cad8b9ba73f3055cb7d000fdda14eb45f59a418d6e563a5d272855ff86000779c221282b07e8f33f07f793ecaec6e9150dc9b889c485e8a1496ee1839a5b9daa
data/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## Unreleased
9
+
10
+ ## 6.1.0
11
+ ### Added
12
+
13
+ - new option (iOS only) `--auto-escape-percent` that escapes % character in wording. This option should be used if the wording is intended to be used with `String(format:)`.
14
+
15
+ ## 6.0.0
9
16
  ### Added
10
17
 
11
18
  - Remove extra spaces before and after key/translation contents
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ad_localize (6.0.0)
4
+ ad_localize (6.1.0)
5
5
  activesupport (>= 6.1.3.2, < 8.0)
6
6
  colorize (~> 0.8)
7
7
  google-apis-drive_v3 (~> 0.33.0)
data/README.md CHANGED
@@ -76,6 +76,11 @@ $ ad_localize -d
76
76
  $ ad_localize -x
77
77
  ```
78
78
 
79
+ * Will escape % character present in wordings (iOS feature only), this is useful when using the wording through String(format:)
80
+ ```
81
+ $ ad_localize --auto-escape-percent
82
+ ```
83
+
79
84
  * Only generate wording files for the specified locales
80
85
  ```
81
86
  $ ad_localize -l fr,en
@@ -10,6 +10,7 @@ module AdLocalize
10
10
  end
11
11
 
12
12
  def call(wording:, export_request:)
13
+ @serializer.configure(export_request: export_request) if @serializer.respond_to?(:configure)
13
14
  wording.each do |locale, locale_wording|
14
15
  next unless has_wording?(locale_wording: locale_wording)
15
16
 
@@ -6,6 +6,7 @@ module AdLocalize
6
6
  request = Requests::ExportRequest.new
7
7
  request.locales = options[:locales]
8
8
  request.bypass_empty_values = options[:'non-empty-values']
9
+ request.auto_escape_percent = options[:'auto-escape-percent']
9
10
  request.csv_paths = options[:csv_paths]
10
11
  request.merge_policy = options[:'merge-policy']
11
12
  request.output_path = options[:'target-dir']
@@ -4,6 +4,7 @@ module AdLocalize
4
4
  DEFAULT_OPTIONS = {
5
5
  locales: Requests::ExportRequest::DEFAULTS[:locales],
6
6
  :'non-empty-values' => Requests::ExportRequest::DEFAULTS[:bypass_empty_values],
7
+ :'auto-escape-percent' => Requests::ExportRequest::DEFAULTS[:auto_escape_percent],
7
8
  csv_paths: Requests::ExportRequest::DEFAULTS[:csv_paths],
8
9
  :'merge-policy' => Requests::ExportRequest::DEFAULTS[:merge_policy],
9
10
  :'target-dir' => Requests::ExportRequest::DEFAULTS[:output_path],
@@ -16,26 +17,10 @@ module AdLocalize
16
17
 
17
18
  def self.parse!(options)
18
19
  args = DEFAULT_OPTIONS
19
- export_all_option = <<~DOC
20
- Export all sheets from spreadsheet specified by --drive-key option.
21
- \tBy default, generates one export directory per sheet (see -m|--merge-sheets option to merge them).
22
- \tAn GCLOUD_CLIENT_SECRET environment variable containing the client_secret.json content is needed.
23
- DOC
24
- merge_policy_option = <<~DOC
25
- Merge specified csv (or sheets from --export-all) instead of exporting each csv.
26
- \treplace: if a key is already defined, replace its value.
27
- \tkeep: if a key is already defined, keep the previous value.
28
- DOC
29
- platforms_option = <<~DOC
30
- PLATFORMS is a comma separated list.
31
- \tOnly generate localisation files for the specified platforms.
32
- \tSupported platforms : #{Entities::Platform::SUPPORTED_PLATFORMS.to_sentence}
33
- DOC
34
-
35
20
  OptionParser.new do |parser|
36
21
  parser.banner = 'Usage: exe/ad_localize [options] file(s)'
37
22
  parser.on("-d", "--debug", TrueClass, 'Run in debug mode')
38
- parser.on("-e", "--export-all-sheets", TrueClass, export_all_option)
23
+ export_all_option(parser)
39
24
  parser.on("-h", "--help", 'Prints help') do
40
25
  puts parser
41
26
  exit
@@ -43,8 +28,8 @@ module AdLocalize
43
28
  parser.on("-k", "--drive-key SPREADSHEET_ID", String, 'Use google drive spreadsheets')
44
29
  parser.on("-l", "--locales LOCALES", Array,
45
30
  'LOCALES is a comma separated list. Only generate localisation files for the specified locales')
46
- parser.on("-m", "--merge-policy POLICY", Interactors::MergeWordings::MERGE_POLICIES, merge_policy_option)
47
- parser.on("-o", "--only PLATFORMS", Array, platforms_option)
31
+ merge_policy_option(parser)
32
+ platforms_option(parser)
48
33
  parser.on("-s", "--sheets SHEET_IDS", Array,
49
34
  'SHEET_IDS is a comma separated list. Use a specific sheet id for Google Drive spreadsheets with several sheets')
50
35
  parser.on("-t", "--target-dir PATH", String, 'Path to the target directory')
@@ -53,10 +38,38 @@ module AdLocalize
53
38
  exit
54
39
  end
55
40
  parser.on("-x", "--non-empty-values", TrueClass, 'Do not export keys with empty values (iOS only)')
41
+ parser.on("--auto-escape-percent", TrueClass, 'Add escaping for % symbol to support wording use with String formatting (iOS only)')
56
42
  end.parse!(options, into: args)
57
43
 
58
44
  args[:csv_paths] = options
59
45
  return args
60
46
  end
47
+
48
+ def self.export_all_option(parser)
49
+ export_all_option = <<~DOC
50
+ Export all sheets from spreadsheet specified by --drive-key option.
51
+ \tBy default, generates one export directory per sheet (see -m|--merge-sheets option to merge them).
52
+ \tAn GCLOUD_CLIENT_SECRET environment variable containing the client_secret.json content is needed.
53
+ DOC
54
+ parser.on("-e", "--export-all-sheets", TrueClass, export_all_option)
55
+ end
56
+
57
+ def self.merge_policy_option(parser)
58
+ merge_policy_option = <<~DOC
59
+ Merge specified csv (or sheets from --export-all) instead of exporting each csv.
60
+ \treplace: if a key is already defined, replace its value.
61
+ \tkeep: if a key is already defined, keep the previous value.
62
+ DOC
63
+ parser.on("-m", "--merge-policy POLICY", Interactors::MergeWordings::MERGE_POLICIES, merge_policy_option)
64
+ end
65
+
66
+ def self.platforms_option(parser)
67
+ platforms_option = <<~DOC
68
+ PLATFORMS is a comma separated list.
69
+ \tOnly generate localisation files for the specified platforms.
70
+ \tSupported platforms : #{Entities::Platform::SUPPORTED_PLATFORMS.to_sentence}
71
+ DOC
72
+ parser.on("-o", "--only PLATFORMS", Array, platforms_option)
73
+ end
61
74
  end
62
75
  end
@@ -5,6 +5,7 @@ module AdLocalize
5
5
  DEFAULTS = {
6
6
  locales: [],
7
7
  bypass_empty_values: false,
8
+ auto_escape_percent: false,
8
9
  csv_paths: [],
9
10
  merge_policy: Interactors::MergeWordings::DEFAULT_POLICY,
10
11
  output_path: Pathname.new('exports'),
@@ -21,6 +22,7 @@ module AdLocalize
21
22
  attr_reader(
22
23
  :locales,
23
24
  :bypass_empty_values,
25
+ :auto_escape_percent,
24
26
  :csv_paths,
25
27
  :merge_policy,
26
28
  :output_path,
@@ -35,6 +37,7 @@ module AdLocalize
35
37
  def initialize
36
38
  @locales = DEFAULTS[:locales]
37
39
  @bypass_empty_values = DEFAULTS[:bypass_empty_values]
40
+ @auto_escape_percent = DEFAULTS[:auto_escape_percent]
38
41
  @csv_paths = DEFAULTS[:csv_paths]
39
42
  @merge_policy = DEFAULTS[:merge_policy]
40
43
  @output_path = DEFAULTS[:output_path]
@@ -56,6 +59,10 @@ module AdLocalize
56
59
  @bypass_empty_values = [true, 'true'].include?(value)
57
60
  end
58
61
 
62
+ def auto_escape_percent=(value)
63
+ @auto_escape_percent = [true, 'true'].include?(value)
64
+ end
65
+
59
66
  def csv_paths=(value)
60
67
  return unless value.is_a? Array
61
68
 
@@ -119,6 +126,7 @@ module AdLocalize
119
126
  def to_s
120
127
  "locales: #{locales}, " \
121
128
  "bypass_empty_values: #{bypass_empty_values}, " \
129
+ "auto_escape_percent: #{auto_escape_percent}, " \
122
130
  "csv_paths: #{csv_paths}, " \
123
131
  "merge_policy: #{merge_policy}, " \
124
132
  "output_path: #{output_path}, " \
@@ -2,10 +2,21 @@
2
2
  module AdLocalize
3
3
  module Sanitizers
4
4
  class IOSSanitizer
5
+ attr_accessor :should_auto_escape_percent
6
+
7
+ def initialize
8
+ @should_auto_escape_percent = false
9
+ end
10
+
5
11
  def sanitize(value:)
6
12
  return if value.blank?
7
13
 
8
- value.gsub(/(?<!\\)\"/, "\\\"")
14
+ processed_value = value.gsub(/(?<!\\)\"/, "\\\"")
15
+ if @should_auto_escape_percent
16
+ # we should escape % sign when not used as formatting function (see: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html)
17
+ processed_value = processed_value.gsub(/%(?!((\d+\$)?([a-zA-Z]|@)))/, '%%')
18
+ end
19
+ processed_value
9
20
  end
10
21
  end
11
22
  end
@@ -8,6 +8,10 @@ module AdLocalize
8
8
  super(sanitizer: Sanitizers::IOSSanitizer.new)
9
9
  end
10
10
 
11
+ def configure(export_request:)
12
+ @sanitizer.should_auto_escape_percent = export_request.auto_escape_percent
13
+ end
14
+
11
15
  private
12
16
 
13
17
  def template_path
@@ -8,6 +8,10 @@ module AdLocalize
8
8
  super(sanitizer: Sanitizers::IOSSanitizer.new)
9
9
  end
10
10
 
11
+ def configure(export_request:)
12
+ @sanitizer.should_auto_escape_percent = export_request.auto_escape_percent
13
+ end
14
+
11
15
  private
12
16
 
13
17
  def template_path
@@ -13,6 +13,10 @@ module AdLocalize
13
13
  render_template(template_path: template_path, variable_binding: variable_binding)
14
14
  end
15
15
 
16
+ def configure(export_request:)
17
+ # override if you need flags from export_request
18
+ end
19
+
16
20
  protected
17
21
 
18
22
  TEMPLATES_DIRECTORY = __dir__ + "/../templates"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module AdLocalize
3
- VERSION = "6.0.0"
3
+ VERSION = "6.1.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ad_localize
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Siegel
@@ -21,7 +21,7 @@ authors:
21
21
  autorequire:
22
22
  bindir: exe
23
23
  cert_chain: []
24
- date: 2023-07-17 00:00:00.000000000 Z
24
+ date: 2023-09-12 00:00:00.000000000 Z
25
25
  dependencies:
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bundler
@@ -302,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
302
302
  - !ruby/object:Gem::Version
303
303
  version: '0'
304
304
  requirements: []
305
- rubygems_version: 3.3.7
305
+ rubygems_version: 3.4.10
306
306
  signing_key:
307
307
  specification_version: 4
308
308
  summary: AdLocalize helps with mobile and web applications wording