fastlane-plugin-translate_gpt 0.1.0 → 0.1.1

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: d61950fe5af16ec1511687b4cab646b8397be0d4870a5e7c2a8d7f22adc06687
4
- data.tar.gz: a04a4b37ba73505bdfea8d6ca7a1b6b0b63cd95f8e2856c9d237a21f513d0a91
3
+ metadata.gz: b7c0d621832f411e542d6c8dad89a1d3014a6d339d2d384d6f1c06af11263804
4
+ data.tar.gz: 5feaad22d9a7fdc77dc03420276ba2284946b381e760cdb49297634e51f4eb36
5
5
  SHA512:
6
- metadata.gz: 15b62929364a8be8f709c950d728a22ee72179a65aeffcb7a1156a23d3883404daf36219101b9aab8c2f0c8b12e22316d93a60407c9addaa72fdac5a1a68ca42
7
- data.tar.gz: 6ac27ed65e2acca6a533ada325f1fe3e0756befd2fb803429b79864092a66eadaefff681a1eefd5fcd74e3f2b65bb87b301ded820a6541e628183df816a2a8ee
6
+ metadata.gz: 82b6bdab41b284e766cb3132e05ac232bcc67699d1f6dd1dca6bdfc944a439148d21d0938802a23fa7cc381ac691c705c077d0a97197b506f78039ab07d968a2
7
+ data.tar.gz: 90566f6958edcd137faa972a4aa7d3e96ea58ea9cb5fd9d17fa9f2aecf137bf1a3744ae7ee264d1380508aa182aef5be8c02b0532ab5b5825c83da3fa13cf5bf
data/README.md CHANGED
@@ -52,6 +52,34 @@ The following options are available for `translate-gpt`:
52
52
  | `target_language` | The target language of the translated strings. Required. | `GPT_TARGET_LANGUAGE` |
53
53
  | `source_file` | The path to the `Localizable.strings` file to be translated. Defaults to `./Resources/Localizable.strings`. | `GPT_SOURCE_FILE` |
54
54
  | `target_file` | The path to the output file for the translated strings. Defaults to `./Resources/Localizable.strings.<target_language>`. | `GPT_TARGET_FILE` |
55
+ | `context` | Common context for the translation | `GPT_COMMON_CONTEXT` |
56
+
57
+ ## Providing context
58
+
59
+ The `TranslateGptAction` allows you to provide additional context for your translation requests in two ways:
60
+
61
+ ### 1. Using a common context
62
+
63
+ You can provide a common context for your project that will be used in all translation requests. This can be done by setting the `common` property when calling the `TranslateGptAction`. The `common` property should be a string that describes the context of your project.
64
+
65
+ ```ruby
66
+ translate_gpt(
67
+ target_language: 'fr',
68
+ common: "This is a mobile app for ordering food online"
69
+ )
70
+ ```
71
+
72
+ ### 2. Adding comments for specific keys
73
+
74
+ You can also add comments to your Localizable.strings file for specific keys. These comments will be included in the translation request for that key. To add a comment for a specific key, simply include a comment before the key in your Localizable.strings file.
75
+
76
+ ```text
77
+ /* This is a comment for KEY1 */
78
+ "KEY1" = "Value for KEY1";
79
+ ```
80
+
81
+ When you run the `TranslateGptAction`, the comment will be included in the translation request for `KEY1`.
82
+
55
83
 
56
84
  ## Authentication
57
85
 
@@ -20,14 +20,17 @@ module Fastlane
20
20
  to_translate = input_hash
21
21
  end
22
22
 
23
- UI.message "Translating #{input_hash.size} strings..."
23
+ UI.message "Translating #{to_translate.size} strings..."
24
24
 
25
- to_translate.each do |key, value|
26
- prompt = "Translate the following string from #{params[:source_language]} to #{params[:target_language]}:\n#{value}"
25
+ to_translate.each_with_index do |(key, value), index|
26
+ prompt = "Translate the following string from #{params[:source_language]} to #{params[:target_language]}: #{value}"
27
27
  context = Helper::TranslateGptHelper.get_context(params[:source_file], key)
28
28
  if context && !context.empty?
29
29
  prompt += "\n\nAdditional context:\n#{context}"
30
30
  end
31
+ if params[:context] && !params[:context].empty?
32
+ prompt += "\n\nCommon context:\n#{params[:context]}"
33
+ end
31
34
  # translate the source string to the target language
32
35
  response = client.chat(
33
36
  parameters: {
@@ -36,7 +39,6 @@ module Fastlane
36
39
  temperature: params[:temperature],
37
40
  }
38
41
  )
39
- #puts response
40
42
  # extract the translated string from the response
41
43
  error = response.dig("error", "message")
42
44
  if error
@@ -50,7 +52,9 @@ module Fastlane
50
52
  UI.warning "Unable to translate #{key} - #{value}"
51
53
  end
52
54
  end
53
- Helper::TranslateGptHelper.timeout params[:request_timeout]
55
+ if index < to_translate.size - 1
56
+ Helper::TranslateGptHelper.timeout params[:request_timeout]
57
+ end
54
58
  end
55
59
 
56
60
  UI.message "Writing #{output_hash.size} strings to #{params[:target_file]}..."
@@ -138,7 +142,14 @@ module Fastlane
138
142
  UI.user_error!("Invalid file path: #{value}") unless File.exist?(value)
139
143
  UI.user_error!("Translation file must have .strings extension") unless File.extname(value) == ".strings"
140
144
  end
141
- ),
145
+ ),
146
+ FastlaneCore::ConfigItem.new(
147
+ key: :context,
148
+ env_name: "GPT_COMMON_CONTEXT",
149
+ description: "Common context for the translation",
150
+ optional: true,
151
+ type: String
152
+ )
142
153
  ]
143
154
  end
144
155
 
@@ -30,7 +30,7 @@ module Fastlane
30
30
  content = File.read(localization_file)
31
31
 
32
32
  # search for the comments associated with the localization key
33
- regex = /\/\*\*\n\s*\* @key\s+#{localization_key}\n((\s*\*.*\n)+)\s*\*\/\n\s*"#{localization_key}"/
33
+ regex = /^\/\*(.+)\*\/\n"#{localization_key}"/
34
34
  match = content.match(regex)
35
35
 
36
36
  # return the comments, if found
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module TranslateGpt
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-translate_gpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Cherepanov