fastlane-plugin-translate_gpt 0.1.8.2 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b892379c42264401fe57500783b0b8ab2ad3b84ab81a5cd68e0e3c16250f74e1
4
- data.tar.gz: 35e9901ddf7a0435cebaefd55393e45800731f4a5eaba81b5c8d49e848cec070
3
+ metadata.gz: 954eb550c534e78643e493d55a44aad05a28ea4545a7f965b393efeec7d8113b
4
+ data.tar.gz: ca96f089100daaa43b0ed5942d03be22658a1ae0fecf7a24062eb7a4cb51dd11
5
5
  SHA512:
6
- metadata.gz: 83d0ba21ea5b3df1ae37084401525638efc6ed04535b460a204e90d572208eace9717e7bcc0252806b7fa74a00ed9d8479d8bdb0e5ba7899453cfa523f17c067
7
- data.tar.gz: 03527622c722c86560a2d386053dabd1740087e57639c96cb622f3146fcd3b258254db95c420a970e2d9636310621c6011486832b14e4d59eca72e1fb14a7989
6
+ metadata.gz: bb6ed4b1b44fd5c97ce495524ea644911d55d0bec333611c53be68c9aba8becb8687c4d5bce0fa228bee2c48fd3bec227729664afff0e742073cd8de2f7a6423
7
+ data.tar.gz: 1a1faac3623a8795115112629db8d0f35399bbee0c1b1295453f9236ef1c7b9cc7a4f26f855a5029f8d1f7fbd007e7a568c1779bacb8f84e262353ada3c28095
data/README.md CHANGED
@@ -54,6 +54,7 @@ The following options are available for `translate-gpt`:
54
54
  | `target_file` | The path to the output file for the translated strings. | `GPT_TARGET_FILE` |
55
55
  | `context` | Common context for the translation | `GPT_COMMON_CONTEXT` |
56
56
  | `bunch_size` | Number of strings to translate in a single request.| `GPT_BUNCH_SIZE` |
57
+ | `mark_for_review` | If string has been translated by GPT, mark it for review | `GPT_MARK_FOR_REVIEW` |
57
58
 
58
59
  **Note:** __I advise using `bunch_size`. It will reduce the number of API requests and translations will be more accurate.__
59
60
 
@@ -8,15 +8,15 @@ module Fastlane
8
8
  class TranslateGptAction < Action
9
9
  def self.run(params)
10
10
  helper = Helper::TranslateGptHelper.new(params)
11
- helper.prepare_hashes()
12
- bunch_size = params[:bunch_size]
11
+ helper.prepare_hashes
12
+ bunch_size = params[:bunch_size]
13
13
  helper.log_input(bunch_size)
14
14
  if bunch_size.nil? || bunch_size < 1
15
- helper.translate_strings()
16
- else
15
+ helper.translate_strings
16
+ else
17
17
  helper.translate_bunch_of_strings(bunch_size)
18
18
  end
19
- helper.write_output()
19
+ helper.write_output
20
20
  end
21
21
 
22
22
  #####################################################
@@ -31,89 +31,101 @@ module Fastlane
31
31
  [
32
32
  FastlaneCore::ConfigItem.new(
33
33
  key: :api_token,
34
- env_name: "GPT_API_KEY",
35
- description: "API token for ChatGPT",
34
+ env_name: 'GPT_API_KEY',
35
+ description: 'API token for ChatGPT',
36
36
  sensitive: true,
37
37
  code_gen_sensitive: true,
38
- default_value: ""
38
+ default_value: ''
39
39
  ),
40
40
  FastlaneCore::ConfigItem.new(
41
41
  key: :model_name,
42
- env_name: "GPT_MODEL_NAME",
43
- description: "Name of the ChatGPT model to use",
44
- default_value: "gpt-3.5-turbo"
42
+ env_name: 'GPT_MODEL_NAME',
43
+ description: 'Name of the ChatGPT model to use',
44
+ default_value: 'gpt-3.5-turbo'
45
45
  ),
46
46
  FastlaneCore::ConfigItem.new(
47
47
  key: :request_timeout,
48
- env_name: "GPT_REQUEST_TIMEOUT",
49
- description: "Timeout for the request in seconds",
48
+ env_name: 'GPT_REQUEST_TIMEOUT',
49
+ description: 'Timeout for the request in seconds',
50
50
  type: Integer,
51
51
  default_value: 30
52
52
  ),
53
53
  FastlaneCore::ConfigItem.new(
54
54
  key: :temperature,
55
- env_name: "GPT_TEMPERATURE",
56
- description: "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic",
55
+ env_name: 'GPT_TEMPERATURE',
56
+ description: 'What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic',
57
57
  type: Float,
58
58
  optional: true,
59
59
  default_value: 0.5
60
60
  ),
61
61
  FastlaneCore::ConfigItem.new(
62
62
  key: :skip_translated,
63
- env_name: "GPT_SKIP_TRANSLATED",
64
- description: "Whether to skip strings that have already been translated",
63
+ env_name: 'GPT_SKIP_TRANSLATED',
64
+ description: 'Whether to skip strings that have already been translated',
65
65
  type: Boolean,
66
66
  optional: true,
67
67
  default_value: true
68
68
  ),
69
69
  FastlaneCore::ConfigItem.new(
70
70
  key: :source_language,
71
- env_name: "GPT_SOURCE_LANGUAGE",
72
- description: "Source language to translate from",
73
- default_value: "auto"
71
+ env_name: 'GPT_SOURCE_LANGUAGE',
72
+ description: 'Source language to translate from',
73
+ default_value: 'auto'
74
74
  ),
75
75
  FastlaneCore::ConfigItem.new(
76
76
  key: :target_language,
77
- env_name: "GPT_TARGET_LANGUAGE",
78
- description: "Target language to translate to",
79
- default_value: "en"
77
+ env_name: 'GPT_TARGET_LANGUAGE',
78
+ description: 'Target language to translate to',
79
+ default_value: 'en'
80
80
  ),
81
81
  FastlaneCore::ConfigItem.new(
82
82
  key: :source_file,
83
- env_name: "GPT_SOURCE_FILE",
84
- description: "The path to the Localizable.strings file to be translated",
83
+ env_name: 'GPT_SOURCE_FILE',
84
+ description: 'The path to the Localizable.strings file to be translated',
85
85
  verify_block: proc do |value|
86
86
  UI.user_error!("Invalid file path: #{value}") unless File.exist?(value)
87
87
  extension = File.extname(value)
88
- available_extensions = [".strings", ".xcstrings"]
89
- UI.user_error!("Translation file must have any of these extensions: #{available_extensions}") unless available_extensions.include? extension
88
+ available_extensions = ['.strings', '.xcstrings']
89
+ unless available_extensions.include? extension
90
+ UI.user_error!("Translation file must have any of these extensions: #{available_extensions}")
91
+ end
90
92
  end
91
93
  ),
92
94
  FastlaneCore::ConfigItem.new(
93
95
  key: :target_file,
94
- env_name: "GPT_TARGET_FILE",
95
- description: "Path to the translation file to update",
96
+ env_name: 'GPT_TARGET_FILE',
97
+ description: 'Path to the translation file to update',
96
98
  verify_block: proc do |value|
97
99
  UI.user_error!("Invalid file path: #{value}") unless File.exist?(value)
98
100
  extension = File.extname(value)
99
- available_extensions = [".strings", ".xcstrings"]
100
- UI.user_error!("Translation file must have any of these extensions: #{available_extensions}") unless available_extensions.include? extension
101
+ available_extensions = ['.strings', '.xcstrings']
102
+ unless available_extensions.include? extension
103
+ UI.user_error!("Translation file must have any of these extensions: #{available_extensions}")
104
+ end
101
105
  end
102
- ),
106
+ ),
103
107
  FastlaneCore::ConfigItem.new(
104
108
  key: :context,
105
- env_name: "GPT_COMMON_CONTEXT",
106
- description: "Common context for the translation",
109
+ env_name: 'GPT_COMMON_CONTEXT',
110
+ description: 'Common context for the translation',
107
111
  optional: true,
108
112
  type: String
109
- ),
113
+ ),
110
114
  FastlaneCore::ConfigItem.new(
111
115
  key: :bunch_size,
112
- env_name: "GPT_BUNCH_SIZE",
113
- description: "Number of strings to translate in a single request",
116
+ env_name: 'GPT_BUNCH_SIZE',
117
+ description: 'Number of strings to translate in a single request',
114
118
  optional: true,
115
119
  type: Integer
116
- ),
120
+ ),
121
+ FastlaneCore::ConfigItem.new(
122
+ key: :mark_for_review,
123
+ env_name: 'GPT_MARK_FOR_REVIEW',
124
+ description: 'If string has been translated by GPT, mark it for review',
125
+ type: Boolean,
126
+ optional: true,
127
+ default_value: false
128
+ )
117
129
  ]
118
130
  end
119
131
 
@@ -128,15 +140,15 @@ module Fastlane
128
140
  def self.return_value
129
141
  # This action doesn't return any specific value, so we return nil
130
142
  nil
131
- end
143
+ end
132
144
 
133
145
  def self.authors
134
- ["ftp27"]
146
+ ['ftp27']
135
147
  end
136
148
 
137
149
  def self.is_supported?(platform)
138
- [:ios, :mac].include?(platform)
139
- end
150
+ %i[ios mac].include?(platform)
151
+ end
140
152
  end
141
153
  end
142
154
  end
@@ -160,7 +160,7 @@ module Fastlane
160
160
 
161
161
  json_hash = []
162
162
  strings.each do |key, string|
163
- UI.message "Translating #{key} - #{string}"
163
+ UI.message "Translating #{key} - #{string.value}"
164
164
  next if string.nil?
165
165
 
166
166
  string_hash = {}
@@ -267,12 +267,12 @@ module Fastlane
267
267
  if translated_string.is_a? Hash
268
268
  strings = {}
269
269
  translated_string.each do |pl_key, value|
270
- UI.message "#{index_log} Translating #{real_key} > #{pl_key} - #{value}"
270
+ UI.message "#{index_log} #{real_key}: #{pl_key} - #{value}"
271
271
  strings[pl_key] = LocoStrings::LocoString.new(pl_key, value, context)
272
272
  end
273
273
  string = LocoStrings::LocoVariantions.new(real_key, strings, context)
274
274
  elsif translated_string && !translated_string.empty?
275
- UI.message "#{index_log} Translating #{real_key} - #{translated_string}"
275
+ UI.message "#{index_log} #{real_key}: #{translated_string}"
276
276
  string = LocoStrings::LocoString.new(real_key, translated_string, context)
277
277
  end
278
278
  @output_hash[real_key] = string
@@ -299,13 +299,14 @@ module Fastlane
299
299
  end
300
300
  file.write
301
301
  else
302
+ default_state = if :mark_for_review then "needs_review" else "translated" end
302
303
  @xcfile.update_file_path(@params[:target_file])
303
304
  @output_hash.each do |key, value|
304
305
  if value.is_a? LocoStrings::LocoString
305
- @xcfile.update(key, value.value, value.comment, "translated", @params[:target_language])
306
+ @xcfile.update(key, value.value, value.comment, default_state, @params[:target_language])
306
307
  elsif value.is_a? LocoStrings::LocoVariantions
307
308
  value.strings.each do |pl_key, variant|
308
- @xcfile.update_variation(key, pl_key, variant.value, variant.comment, "translated", @params[:target_language])
309
+ @xcfile.update_variation(key, pl_key, variant.value, variant.comment, default_state, @params[:target_language])
309
310
  end
310
311
  end
311
312
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module TranslateGpt
3
- VERSION = "0.1.8.2"
3
+ VERSION = '0.1.9'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-translate_gpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.2
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Cherepanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-12 00:00:00.000000000 Z
11
+ date: 2025-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ruby-openai
14
+ name: loco_strings
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.7'
19
+ version: 0.1.5
20
20
  type: :runtime
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: '3.7'
26
+ version: 0.1.5
27
27
  - !ruby/object:Gem::Dependency
28
- name: loco_strings
28
+ name: ruby-openai
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.4.1
33
+ version: '3.7'
34
34
  type: :runtime
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: 0.1.4.1
40
+ version: '3.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement