ios_polyglot_cli 2.4.0 → 2.5.1

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: 8a4772a7586a26e165ab7b05bb5adc917e597f80d0aadd1681c447eb18294e80
4
- data.tar.gz: 8a441b6e7f109e310aa33caf67ec22751a39da6eb46766f83a002e9f801d9802
3
+ metadata.gz: 3a28da6027422897aaf071d3f6d1a4f5dc569f3669c8f5e3ccdf6188260c02eb
4
+ data.tar.gz: 1f1746b9383063d36a932f7e509cb417a4b6ac608dcde8278c2913ab7c4f25a4
5
5
  SHA512:
6
- metadata.gz: 9b776a929067b05d066076163a060bab2ff210db020d9a75c3d2357e217b817247a4b5fc1a44ae9abd78fbb746879659b7d47f3126c557d9b86f1e77821a5c5a
7
- data.tar.gz: 0173e073f01dbfcf7a9318ecf9a9cbebabcfea04be5433c19a2c398d0d092f0fdbfc268d6efa5e910d5f5b4f680059bd8505e077558a6f9fab6c2e1d4002e3a3
6
+ metadata.gz: 7d9b465ed705ad0c0d6eba37d4aa2179353fd327eee8babc7ebadb033b5cb4754de573bf0de2dd33b690984861adbe4464b1a50183ff329ed9ada961fc7bcd68
7
+ data.tar.gz: 181d35960b6bf13327689d57e0074440a2b1a4b1a7874756a2dd089d15c6d008a190feb7beff98a7ccdab1d168379ef58ef7e260026a0bca7e8ce46be3503e89
data/.gitignore CHANGED
@@ -126,4 +126,4 @@ DerivedData/
126
126
  /*.gcno
127
127
  **/xcshareddata/WorkspaceSettings.xcsettings
128
128
 
129
- # End of https://www.gitignore.io/api/ruby,xcode,macos,visualstudiocode
129
+ polyglot.yml
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.1.0
data/Gemfile.lock CHANGED
@@ -1,30 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ios_polyglot_cli (2.4.0)
4
+ ios_polyglot_cli (2.5.1)
5
5
  activesupport
6
6
  commander
7
7
  json_api_client
8
+ parallel
8
9
  tty-prompt
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
13
- activemodel (7.0.4)
14
- activesupport (= 7.0.4)
15
- activesupport (7.0.4)
14
+ activemodel (7.1.3.2)
15
+ activesupport (= 7.1.3.2)
16
+ activesupport (7.1.3.2)
17
+ base64
18
+ bigdecimal
16
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ connection_pool (>= 2.2.5)
21
+ drb
17
22
  i18n (>= 1.6, < 2)
18
23
  minitest (>= 5.1)
24
+ mutex_m
19
25
  tzinfo (~> 2.0)
20
- addressable (2.8.1)
26
+ addressable (2.8.6)
21
27
  public_suffix (>= 2.0.2, < 6.0)
28
+ base64 (0.2.0)
29
+ bigdecimal (3.1.7)
22
30
  byebug (11.1.3)
23
31
  coderay (1.1.3)
24
- commander (4.6.0)
25
- highline (~> 2.0.0)
26
- concurrent-ruby (1.2.2)
27
- faraday (1.10.2)
32
+ commander (5.0.0)
33
+ highline (~> 3.0.0)
34
+ concurrent-ruby (1.2.3)
35
+ connection_pool (2.4.1)
36
+ drb (2.2.1)
37
+ faraday (1.10.3)
28
38
  faraday-em_http (~> 1.0)
29
39
  faraday-em_synchrony (~> 1.0)
30
40
  faraday-excon (~> 1.1)
@@ -49,10 +59,10 @@ GEM
49
59
  faraday-retry (1.0.3)
50
60
  faraday_middleware (1.2.0)
51
61
  faraday (~> 1.0)
52
- highline (2.0.3)
53
- i18n (1.12.0)
62
+ highline (3.0.1)
63
+ i18n (1.14.4)
54
64
  concurrent-ruby (~> 1.0)
55
- json_api_client (1.21.0)
65
+ json_api_client (1.22.0)
56
66
  activemodel (>= 3.2.0)
57
67
  activesupport (>= 3.2.0)
58
68
  addressable (~> 2.2)
@@ -60,19 +70,21 @@ GEM
60
70
  faraday_middleware (>= 0.9.0, < 2.0)
61
71
  rack (>= 0.2)
62
72
  method_source (1.0.0)
63
- minitest (5.16.3)
64
- multipart-post (2.2.3)
73
+ minitest (5.22.3)
74
+ multipart-post (2.4.0)
75
+ mutex_m (0.2.0)
76
+ parallel (1.24.0)
65
77
  pastel (0.8.0)
66
78
  tty-color (~> 0.5)
67
- pry (0.14.1)
79
+ pry (0.14.2)
68
80
  coderay (~> 1.1)
69
81
  method_source (~> 1.0)
70
82
  pry-byebug (3.10.1)
71
83
  byebug (~> 11.0)
72
84
  pry (>= 0.13, < 0.15)
73
- public_suffix (5.0.0)
74
- rack (3.0.1)
75
- rake (10.5.0)
85
+ public_suffix (5.0.4)
86
+ rack (3.0.9.1)
87
+ rake (13.1.0)
76
88
  ruby2_keywords (0.0.5)
77
89
  tty-color (0.6.0)
78
90
  tty-cursor (0.7.1)
@@ -83,8 +95,8 @@ GEM
83
95
  tty-cursor (~> 0.7)
84
96
  tty-screen (~> 0.8)
85
97
  wisper (~> 2.0)
86
- tty-screen (0.8.1)
87
- tzinfo (2.0.5)
98
+ tty-screen (0.8.2)
99
+ tzinfo (2.0.6)
88
100
  concurrent-ruby (~> 1.0)
89
101
  wisper (2.0.1)
90
102
 
@@ -92,10 +104,10 @@ PLATFORMS
92
104
  arm64-darwin-21
93
105
 
94
106
  DEPENDENCIES
95
- bundler (~> 2.3)
107
+ bundler
96
108
  ios_polyglot_cli!
97
109
  pry-byebug
98
- rake (~> 10.0)
110
+ rake
99
111
 
100
112
  BUNDLED WITH
101
113
  2.3.26
data/README.md CHANGED
@@ -14,19 +14,23 @@ Then to install polyglot simply run:
14
14
 
15
15
  gem install ios_polyglot_cli
16
16
 
17
- If you have any issues with above command, please consult this [thread](https://stackoverflow.com/questions/2119064/sudo-gem-install-or-gem-install-and-gem-locations).
17
+ If you have any issues with the above command, please consult this [thread](https://stackoverflow.com/questions/2119064/sudo-gem-install-or-gem-install-and-gem-locations).
18
18
 
19
19
  You can check if everything is OK running:
20
20
 
21
21
  polyglot --help
22
22
 
23
- You should see output with all commands and their description.
23
+ You should see the output with all commands and their description.
24
24
 
25
25
  ## Usage
26
26
 
27
- ### Login
27
+ ### Login - soon to be deprecated!
28
28
 
29
- You will have to login with your Infinum ID if you want to use polyglot:
29
+ > Login command will be deprecated in the near future!
30
+ > To obtain a new token then, please visit https://infinum.polyglothq.com, generate a new token under Settings and store
31
+ > it in your environment variables under POLYGLOT_TOKEN environment variable (or whatever variable your project is using).
32
+
33
+ You will have to log in with your Infinum ID if you want to use polyglot:
30
34
 
31
35
  polyglot login
32
36
 
@@ -38,9 +42,12 @@ To setup polyglot in your Xcode project use:
38
42
 
39
43
  polyglot init
40
44
 
41
- It will prompt you with project list to select one you are setting up. You can provide source language (Swift/ObjC), translations path and resources path. It will create `polyglot.yml` file which you can edit later and add additional Polyglot projects.
45
+ It will prompt you with a project list to select the one you are setting up. You can provide source language (Swift/ObjC), translations path and resources path. It will create `polyglot.yml` file which you can edit later and add additional Polyglot projects.
42
46
 
43
- Also, you can pass optional parameter `--query` or `-q`. It will prompt you with a list of all projects that match specified query.
47
+ Optional parameters:
48
+ * `--query` will prompt you with a list of all projects that match the specified query.
49
+ * `--url` URL of the Polyglot API, if not provided, either https://infinum.polyglothq.com/api/v2/ or one from `polyglot.yml` file will be used.
50
+ * `--token` Auth token. If not provided, an environment variable value will be used (either `POLYGLOT_TOKEN` or one from `polyglot.yml`).
44
51
 
45
52
  ### Projects
46
53
 
@@ -48,21 +55,48 @@ If you want to see all polyglot projects and their `IDs` enter:
48
55
 
49
56
  polyglot projects
50
57
 
51
- Also, you can pass optional parameter `--query` or `-q`. It will prompt you with a list of all projects that match specified query.
58
+ Optional parameters:
59
+ * `--query` will prompt you with a list of all projects that match the specified query.
60
+ * `--url` URL of the Polyglot API, if not provided, either https://infinum.polyglothq.com/api/v2/ or one from `polyglot.yml` file will be used.
61
+ * `--token` Auth token. If not provided, an environment variable value will be used (either `POLYGLOT_TOKEN` or one from `polyglot.yml`).
52
62
 
53
- ### Legacy projects
63
+ ### Pull
64
+
65
+ Finally, to fetch translations use:
66
+
67
+ $ polyglot pull
68
+
69
+ Optional parameters:
70
+ * `--url` URL of the Polyglot API, if not provided, either https://infinum.polyglothq.com/api/v2/ or one from `polyglot.yml` file will be used.
71
+ * `--token` Auth token. If not provided, an environment variable value will be used (either `POLYGLOT_TOKEN` or one from `polyglot.yml`).
54
72
 
55
- New style translations will create files names `en_US.strings` for example, and some old projects still use old naming in the style of `en.strings`. To get around this issue, you either need to migrate your project to use the new naming (be mindful of existing app's settings), or add this line under your path value:
73
+ ### Config syntax
56
74
 
57
75
  ```yaml
58
- useOldNaming: true
76
+ # polyglot.yml file
77
+ language: swift
78
+ url: https://myproject.polyglothq.com/api/v2/ # Optional, https://infinum.polyglothq.com/api/v2/ by default
79
+ token_env_variable: CUSTOM_POLYGLOT_TOKEN_VARIABLE # Optional, POLYGLOT_TOKEN by default
80
+ skip_writing_language_struct: false # Optional, false by default
81
+ useOldNaming: false # Optional, false by default
82
+ projects:
83
+ -
84
+ id: 1234
85
+ path: ./ProjectOne/Resources/Translations/
86
+ sourceFilesPath: ./ProjectOne/Sources/Translations/
87
+ -
88
+ id: 6789
89
+ path: ./ProjectTwo/Resources/Translations/
90
+ sourceFilesPath: ./ProjectTwo/Sources/Translations/
59
91
  ```
60
92
 
61
- ### Pull
93
+ ### Legacy projects
62
94
 
63
- Finally, to fetch translations use:
95
+ New style translations will create file names `en_US.strings` for example, and some old projects still use old naming in the style of `en.strings`. To get around this issue, you either need to migrate your project to use the new naming (be mindful of the existing app's settings), or add this line under your path value:
64
96
 
65
- $ polyglot pull
97
+ ```yaml
98
+ useOldNaming: true
99
+ ```
66
100
 
67
101
  ## Development
68
102
 
@@ -70,7 +104,7 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
70
104
 
71
105
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
72
106
 
73
- In order to release a new version to rubygems, you will need to be added as an owner of polyglot project on rubygems. Owners that can add other users are listed on [project's rubygems page.](https://rubygems.org/gems/ios_polyglot_cli)
107
+ To release a new version to rubygems, you will need to be added as an owner of polyglot project on rubygems. Owners that can add other users are listed on [project's rubygems page.](https://rubygems.org/gems/ios_polyglot_cli)
74
108
 
75
109
  ## Contributing
76
110
 
data/exe/polyglot CHANGED
@@ -10,11 +10,12 @@ program :version, PolyglotIos::VERSION
10
10
  program :description, 'An iOS client for managing polyglot\'s translations.'
11
11
 
12
12
  command :login do |c|
13
- c.syntax = 'polyglot login'
13
+ c.syntax = 'polyglot login [options]'
14
14
  c.description = 'Login to Polyglot and fetches the token using the email and password you provide.'
15
- c.action do
15
+ c.option '--url STRING', String, "URL of the Polyglot API. If not provided, #{PolyglotIos::DEFAULT_API_URL} will be used."
16
+ c.action do |_args, options|
16
17
  PolyglotIos::ErrorHandler.rescuable do
17
- PolyglotIos::Command::Login.init
18
+ PolyglotIos::Command::Login.init(options)
18
19
  end
19
20
  end
20
21
  end
@@ -23,6 +24,8 @@ command :init do |c|
23
24
  c.syntax = 'polyglot init [options]'
24
25
  c.description = 'Sets up a polyglot.yml config for selected project.'
25
26
  c.option '--query STRING', String, 'Only show projects which name matches query string.'
27
+ c.option '--url STRING', String, "URL of the Polyglot API. If not provided, #{PolyglotIos::DEFAULT_API_URL} will be used."
28
+ c.option '--token STRING', String, "Auth token. If not provided, #{PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE} environment variable value will be used."
26
29
  c.action do |_args, options|
27
30
  PolyglotIos::ErrorHandler.rescuable do
28
31
  PolyglotIos::Command::Setup.init(options)
@@ -34,6 +37,8 @@ command :projects do |c|
34
37
  c.syntax = 'polyglot projects [options]'
35
38
  c.description = 'Lists all available polyglot projects with their IDs.'
36
39
  c.option '--query STRING', String, 'Only show projects which name matches query string.'
40
+ c.option '--url STRING', String, "URL of the Polyglot API. If not provided, #{PolyglotIos::DEFAULT_API_URL} will be used."
41
+ c.option '--token STRING', String, "Auth token. If not provided, #{PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE} environment variable value will be used."
37
42
  c.action do |_args, options|
38
43
  PolyglotIos::ErrorHandler.rescuable do
39
44
  PolyglotIos::Command::Projects.init(options)
@@ -42,11 +47,13 @@ command :projects do |c|
42
47
  end
43
48
 
44
49
  command :pull do |c|
45
- c.syntax = 'polyglot pull'
50
+ c.syntax = 'polyglot pull [options]'
46
51
  c.description = 'Pulls all translations from Polyglot and generates necessary files'
52
+ c.option '--url STRING', String, "URL of the Polyglot API. If not provided, #{PolyglotIos::DEFAULT_API_URL} will be used."
53
+ c.option '--token STRING', String, "Auth token. If not provided, #{PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE} environment variable value will be used."
47
54
  c.action do |_args, options|
48
55
  PolyglotIos::ErrorHandler.rescuable do
49
- PolyglotIos::Command::Pull.init
56
+ PolyglotIos::Command::Pull.init(options)
50
57
  end
51
58
  end
52
59
  end
@@ -23,12 +23,13 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.add_development_dependency 'bundler', '~> 2.3'
27
- spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'rake'
28
28
  spec.add_development_dependency 'pry-byebug'
29
29
 
30
30
  spec.add_dependency 'json_api_client'
31
31
  spec.add_dependency 'tty-prompt'
32
32
  spec.add_dependency 'commander'
33
33
  spec.add_dependency 'activesupport'
34
+ spec.add_dependency 'parallel'
34
35
  end
@@ -3,7 +3,10 @@ module PolyglotIos
3
3
  class Base < JsonApiClient::Resource
4
4
  extend PolyglotIos::Helper::Depaginate
5
5
 
6
- self.site = 'https://infinum.polyglothq.com/api/v2/'
6
+ def self.api_url(url)
7
+ self.site = url
8
+ self
9
+ end
7
10
 
8
11
  def self.token(token)
9
12
  self.connection_options = { headers: { 'X-Auth-Token' => token } }
@@ -16,4 +19,3 @@ module PolyglotIos
16
19
  end
17
20
  end
18
21
  end
19
-
@@ -17,6 +17,7 @@ module PolyglotIos
17
17
  translation
18
18
  .gsub("\"", "\\\"")
19
19
  .gsub("%s", "%@")
20
+ .gsub(/(%\d+)(\$)(s)/, '\1\2@') # Positional parameter support, converts %1$s to %1$@ for example
20
21
  end
21
22
 
22
23
  end
@@ -3,8 +3,12 @@ module PolyglotIos
3
3
  class Login
4
4
  include Helper::Terminal
5
5
 
6
- def self.init
7
- new.call
6
+ def self.init(options = Commander::Command::Options.new)
7
+ new(options).call
8
+ end
9
+
10
+ def initialize(options = Commander::Command::Options.new)
11
+ @options = options
8
12
  end
9
13
 
10
14
  def call
@@ -14,8 +18,20 @@ module PolyglotIos
14
18
  private
15
19
 
16
20
  def token
21
+ prompt.warn(<<~WARN
22
+ Login command will be deprecated soon!
23
+ To obtain a token, please visit https://infinum.polyglothq.com, generate a new token under Settings and store
24
+ it in your environment variables under #{PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE} variable.
25
+ zsh:
26
+ echo '\\nexport #{PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE}=<YOUR_AUTH_TOKEN>' >> ~/.zshrc
27
+ source ~/.zshrc
28
+ bash:
29
+ echo '\\nexport #{PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE}=<YOUR_AUTH_TOKEN>' >> ~/.bashrc
30
+ source ~/.bashrc
31
+ WARN
32
+ )
17
33
  prompt.say('Logging into API...')
18
- @data = PolyglotIos::Resource::Session.create(email: email, password: password)
34
+ @data = PolyglotIos::Resource::Session.api_url(option_site_url).create(email: email, password: password)
19
35
  @data.token
20
36
  end
21
37
 
@@ -27,6 +43,10 @@ module PolyglotIos
27
43
  prompt.mask('Password:')
28
44
  end
29
45
 
46
+ def option_site_url
47
+ @option_site_url = @options.__hash__.fetch(:url, PolyglotIos::DEFAULT_API_URL)
48
+ end
49
+
30
50
  end
31
51
  end
32
52
  end
@@ -8,11 +8,11 @@ module PolyglotIos
8
8
  include Helper::General
9
9
 
10
10
  attr_accessor :options
11
-
11
+
12
12
  def self.init(options = Commander::Command::Options.new)
13
13
  new(options).call
14
14
  end
15
-
15
+
16
16
  def initialize(options = Commander::Command::Options.new)
17
17
  @options = options
18
18
  end
@@ -27,18 +27,26 @@ module PolyglotIos
27
27
  .sort_by { |p| p[0].downcase }
28
28
  .to_h
29
29
  end
30
-
30
+
31
31
  def projects
32
32
  prompt.say('Getting projects...')
33
- PolyglotIos::Resource::Project.token(token).depaginate.each_with_object({}) do |r, hash|
33
+ PolyglotIos::Resource::Project.api_url(option_site_url).token(option_token).depaginate.each_with_object({}) do |r, hash|
34
34
  hash[r.name] = r.id
35
35
  end
36
36
  end
37
-
37
+
38
38
  def option_query
39
39
  @option_query ||= @options.__hash__.fetch(:query, '')
40
40
  end
41
41
 
42
+ def option_site_url
43
+ @option_site_url = @options.__hash__.fetch(:url, PolyglotIos::DEFAULT_API_URL)
44
+ end
45
+
46
+ def option_token
47
+ @option_token = @options.__hash__.fetch(:token, nil) || token
48
+ end
49
+
42
50
  private
43
51
 
44
52
  def list_projects
@@ -1,11 +1,17 @@
1
+ require 'parallel'
2
+
1
3
  module PolyglotIos
2
4
  module Command
3
5
  class Pull
4
6
  include Helper::Terminal
5
7
  include Helper::General
6
8
 
7
- def self.init
8
- new.call
9
+ def self.init(options = Commander::Command::Options.new)
10
+ new(options).call
11
+ end
12
+
13
+ def initialize(options = Commander::Command::Options.new)
14
+ @options = options
9
15
  end
10
16
 
11
17
  def call
@@ -21,7 +27,7 @@ module PolyglotIos
21
27
  project_id = project[:id]
22
28
  languages = pull_languages(project_id)
23
29
  translation_keys = pull_translation_keys(project_id)
24
-
30
+
25
31
  write_translations(translation_keys, languages, project[:path], project[:useOldNaming])
26
32
  if !skip_writing_language_struct
27
33
  write_languages(languages, project[:sourceFilesPath], programming_language)
@@ -34,11 +40,10 @@ module PolyglotIos
34
40
 
35
41
  def write_translations(translation_keys, languages, translations_path, use_old_naming = false)
36
42
  return if translations_path.to_s.empty?
37
- languages.each do |language|
43
+ Parallel.each(languages) do |language|
38
44
  PolyglotIos::Serializer::Translation
39
45
  .write(translation_keys, language, translations_path, use_old_naming)
40
46
  end
41
-
42
47
  end
43
48
 
44
49
  def write_languages(languages, sources_path, programming_language)
@@ -65,15 +70,25 @@ module PolyglotIos
65
70
 
66
71
  # Pulling data
67
72
 
73
+ def option_token
74
+ @option_token = @options.__hash__.fetch(:token, nil) || token
75
+ end
76
+
77
+ def option_site_url
78
+ @option_site_url = @options.__hash__.fetch(:url, nil) || url
79
+ end
80
+
68
81
  def pull_languages(project_id)
69
82
  PolyglotIos::Resource::Language
70
- .token(token)
83
+ .api_url(option_site_url)
84
+ .token(option_token)
71
85
  .depaginate(project_id: project_id)
72
86
  end
73
87
 
74
88
  def pull_translation_keys(project_id)
75
89
  PolyglotIos::Resource::TranslationKey
76
- .token(token)
90
+ .api_url(option_site_url)
91
+ .token(option_token)
77
92
  .depaginate(project_id: project_id)
78
93
  .sort_by { |key| key.name.downcase }
79
94
  end
@@ -10,16 +10,18 @@ module PolyglotIos
10
10
  def self.init(options = Commander::Command::Options.new)
11
11
  new(options).call
12
12
  end
13
-
13
+
14
14
  def initialize(options = Commander::Command::Options.new)
15
15
  @options = options
16
16
  end
17
17
 
18
18
  def call
19
+ customUrl = option_site_url || custom_url_prompt
19
20
  project_id = project_id_prompt
20
21
  language = language_prompt
21
22
  translations_path = translations_path_prompt
22
23
  sources_path = sources_path_prompt
24
+ token_env_variable = custom_token_env_var_prompt
23
25
  project = {
24
26
  id: project_id,
25
27
  path: translations_path,
@@ -27,7 +29,9 @@ module PolyglotIos
27
29
  }
28
30
  config = {
29
31
  language: language,
30
- projects: [project]
32
+ projects: [project],
33
+ url: customUrl,
34
+ token_env_variable: token_env_variable
31
35
  }
32
36
  PolyglotIos::IO::Config.write(config)
33
37
  success
@@ -40,7 +44,7 @@ module PolyglotIos
40
44
  def project_id_prompt
41
45
  prompt.select('Choose a project: ', filtered_projects)
42
46
  end
43
-
47
+
44
48
  # Language
45
49
 
46
50
  def language_prompt
@@ -60,6 +64,22 @@ module PolyglotIos
60
64
  prompt.ask('Where would you like to store source files?', default: './Common/Translations/')
61
65
  end
62
66
 
67
+ # Custom URL
68
+
69
+ def custom_url_prompt
70
+ prompt.ask('Please enter your custom url:', default: PolyglotIos::DEFAULT_API_URL)
71
+ end
72
+
73
+ def option_site_url
74
+ @option_site_url = @options.__hash__.fetch(:url, nil)
75
+ end
76
+
77
+ # Custom Token Environment Variable Name
78
+
79
+ def custom_token_env_var_prompt
80
+ prompt.ask('Please enter the name of a token environment variable:', default: PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE)
81
+ end
82
+
63
83
  end
64
84
  end
65
85
  end
@@ -0,0 +1,4 @@
1
+ module PolyglotIos
2
+ DEFAULT_API_URL = 'https://infinum.polyglothq.com/api/v2/'
3
+ DEFAULT_TOKEN_ENVIRONMENT_VARIABLE = 'POLYGLOT_TOKEN'
4
+ end
@@ -13,7 +13,7 @@ module PolyglotIos
13
13
  prompt.error(
14
14
  case e
15
15
  when JsonApiClient::Errors::NotAuthorized
16
- "You are not authorized. Please call `polyglot login` and provide correct credentials."
16
+ "You are not authorized. Please check your token and provide correct credentials."
17
17
  when JsonApiClient::Errors::AccessDenied
18
18
  "You don't have the permission to access requested project."
19
19
  when Errno::ENOENT
@@ -1,18 +1,31 @@
1
+ require 'parallel'
2
+
1
3
  module PolyglotIos
2
4
  module Helper
3
5
  module Depaginate
4
6
  PER_PAGE = 100
5
7
 
6
8
  def depaginate_query(query)
7
- depaginated_array = []
8
- page = query.page(1).per(PER_PAGE).all
9
- until page.nil?
10
- depaginated_array += page
11
- page = page.pages.next
12
- end
13
- depaginated_array
9
+ # Polyglot has custom parameters for pagination
10
+ JsonApiClient::Paginating::Paginator.page_param = "number"
11
+ JsonApiClient::Paginating::Paginator.per_page_param = "size"
12
+
13
+ first_page = query.page(1).per(PER_PAGE).all
14
+
15
+ # Early return if there's only one page
16
+ return first_page if first_page.meta.total_pages <= 1
17
+
18
+ page_numbers_to_fetch = (2..first_page.meta.total_pages).to_a
19
+
20
+ items = Parallel
21
+ .map(page_numbers_to_fetch) { |page_number| query.page(page_number).per(PER_PAGE).all }
22
+ .append(first_page) # Fetched pages contain pages from 2 to n, so we need to add the first page
23
+ .sort_by { |page| page.meta.current_page }
24
+ .flat_map { |page| page.to_a }
25
+
26
+ items
14
27
  end
15
-
28
+
16
29
  end
17
30
  end
18
31
  end
@@ -1,6 +1,7 @@
1
1
  module PolyglotIos
2
2
  module Helper
3
3
  module General
4
+ include Terminal
4
5
  ESCAPE_KEYWORDS = ["associatedtype", "class", "deinit", "enum", "extension", "fileprivate", "func",
5
6
  "import", "init", "inout", "internal", "let", "operator", "private", "protocol",
6
7
  "public", "static", "struct", "subscript", "typealias", "var", "break", "case",
@@ -8,10 +9,14 @@ module PolyglotIos
8
9
  "in", "repeat", "return", "switch", "where", "while", "as", "Any", "catch", "false",
9
10
  "is", "nil", "rethrows", "super", "self", "Self", "throw", "throws", "true", "try", "_"]
10
11
  def token
11
- @token ||= PolyglotIos::IO::Token.read
12
+ @token ||= PolyglotIos::IO::Token.read(token_env_variable)
12
13
  if @token.to_s.empty?
13
- PolyglotIos::Command::Login.init
14
- @token = PolyglotIos::IO::Token.read
14
+ prompt.error(<<~MESSAGE
15
+ No Auth Token found under #{token_env_variable} environment variable.
16
+ Please add your token to the environemnt variables under #{token_env_variable} or pass it as an argument --token <YOUR_AUTH_TOKENb>
17
+ MESSAGE
18
+ )
19
+ exit
15
20
  end
16
21
  @token
17
22
  end
@@ -36,6 +41,18 @@ module PolyglotIos
36
41
  @useOldNaming ||= config[:useOldNaming]
37
42
  end
38
43
 
44
+ def url
45
+ @url ||= config[:url] || PolyglotIos::DEFAULT_API_URL
46
+ end
47
+
48
+ def token_env_variable
49
+ begin
50
+ @token_env_variable ||= config[:token_env_variable] || PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE
51
+ rescue
52
+ @token_env_variable = PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE
53
+ end
54
+ end
55
+
39
56
  def indent(level = 0, initial = "")
40
57
  (1..level)
41
58
  .to_a.reduce("") { |result, value| result + " " }
@@ -3,23 +3,21 @@ module PolyglotIos
3
3
  class Token
4
4
 
5
5
  @@in_memory_token = nil
6
-
7
- POLYGLOT_TOKEN_KEY = "POLYGLOT_TOKEN".freeze
8
-
6
+
9
7
  class << self
10
8
 
11
9
  def write(token)
12
10
  if @@in_memory_token.nil?
13
- out = <<-HELLO
11
+ out = <<~HELLO
14
12
 
15
- #{POLYGLOT_TOKEN_KEY}=#{token}
13
+ #{PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE}=#{token}
16
14
 
17
- To stay logged in, add the Polyglot token to your local environment (.zshrc, .bashrc...).
15
+ To stay logged in, add the Polyglot auth token to your local environment (.zshrc, .bashrc...).
18
16
  zsh:
19
- echo '\\nexport #{POLYGLOT_TOKEN_KEY}=#{token}' >> ~/.zshrc
17
+ echo '\\nexport #{PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE}=#{token}' >> ~/.zshrc
20
18
  source ~/.zshrc
21
19
  bash:
22
- echo '\\nexport #{POLYGLOT_TOKEN_KEY}=#{token}' >> ~/.bashrc
20
+ echo '\\nexport #{PolyglotIos::DEFAULT_TOKEN_ENVIRONMENT_VARIABLE}=#{token}' >> ~/.bashrc
23
21
  source ~/.bashrc
24
22
  HELLO
25
23
  puts out
@@ -27,12 +25,8 @@ HELLO
27
25
  @@in_memory_token = token
28
26
  end
29
27
 
30
- def read
31
- if !@@in_memory_token.nil?
32
- return @@in_memory_token
33
- else
34
- return ENV[POLYGLOT_TOKEN_KEY]
35
- end
28
+ def read(token_env_variable)
29
+ @@in_memory_token ||= ENV[token_env_variable]
36
30
  end
37
31
  end
38
32
  end
@@ -20,8 +20,20 @@ module PolyglotIos
20
20
  <<-TEMPLATE
21
21
  import Foundation
22
22
 
23
- // swiftlint:disable file_length type_body_length line_length superfluous_disable_command redundant_string_enum_value
23
+ // swiftlint:disable all
24
24
  <%= @root_enum.serialized() %>
25
+ public struct Strings: Hashable, ExpressibleByStringLiteral, StringsProtocol {
26
+ public let rawValue: String
27
+
28
+ public init(rawValue: String) {
29
+ self.rawValue = rawValue
30
+ }
31
+
32
+ public init(stringLiteral rawValue: String) {
33
+ self.rawValue = rawValue
34
+ }
35
+ }
36
+
25
37
  public protocol StringsProtocol: RawRepresentable {
26
38
  var localized: String { get }
27
39
  func localized(with args: CVarArg...) -> String
@@ -36,6 +48,7 @@ public extension StringsProtocol where RawValue == String {
36
48
  return String(format: self.rawValue.localized, arguments: args)
37
49
  }
38
50
  }
51
+ // swiftlint:enable all
39
52
  TEMPLATE
40
53
  end
41
54
 
@@ -14,7 +14,7 @@ module PolyglotIos
14
14
 
15
15
  def serialized()
16
16
  clean_name = clean_case_name(name)
17
- "case #{clean_name} = \"#{value}\""
17
+ "public static let #{clean_name}: Strings = \"#{value}\""
18
18
  end
19
19
 
20
20
  end
@@ -28,11 +28,11 @@ module PolyglotIos
28
28
  output = indent(indent_level)
29
29
  clean_name = clean_enum_name(name)
30
30
 
31
- if translations.count == 0
32
- # enum without any case statement cannot be RawRepresentable
33
- output.concat("public enum #{clean_name} {\n")
31
+ if indent_level == 0
32
+ # the root object should be an extension and not be public to avoid warnings
33
+ output.concat("extension #{clean_name} {\n")
34
34
  else
35
- output.concat("public enum #{clean_name}: String, StringsProtocol {\n")
35
+ output.concat("public enum #{clean_name} {\n")
36
36
  end
37
37
 
38
38
  translations
@@ -11,7 +11,7 @@ module PolyglotIos
11
11
  .map { |key, value| "\"#{key}\" = \"#{value}\";" }
12
12
  .join("\n")
13
13
  .concat("\n")
14
-
14
+
15
15
  FileUtils.mkdir_p translations_path unless File.exist? translations_path
16
16
  locale_code = language.code(use_old_naming)
17
17
  output_path = File.join(translations_path, "#{locale_code}.strings")
@@ -30,4 +30,3 @@ module PolyglotIos
30
30
  end
31
31
  end
32
32
  end
33
-
@@ -1,3 +1,3 @@
1
1
  module PolyglotIos
2
- VERSION = '2.4.0'
2
+ VERSION = '2.5.1'
3
3
  end
@@ -35,6 +35,9 @@ require 'ios_polyglot_cli/commands/pull'
35
35
 
36
36
  # Error Handler
37
37
  require 'ios_polyglot_cli/error_handler'
38
+
39
+ # Constants
40
+ require 'ios_polyglot_cli/constants'
38
41
  require 'ios_polyglot_cli/version'
39
42
 
40
43
  module PolyglotIos
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ios_polyglot_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filip Gulan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-20 00:00:00.000000000 Z
11
+ date: 2024-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry-byebug
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: parallel
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description:
112
126
  email:
113
127
  - filip.gulan@infinum.hr
@@ -138,6 +152,7 @@ files:
138
152
  - lib/ios_polyglot_cli/commands/projects.rb
139
153
  - lib/ios_polyglot_cli/commands/pull.rb
140
154
  - lib/ios_polyglot_cli/commands/setup.rb
155
+ - lib/ios_polyglot_cli/constants.rb
141
156
  - lib/ios_polyglot_cli/error_handler.rb
142
157
  - lib/ios_polyglot_cli/helpers/depaginate.rb
143
158
  - lib/ios_polyglot_cli/helpers/general.rb