modpack_localizer 0.1.2 → 0.1.4

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: 3cafef6f707a0fd987dc803597657ff94a27500fd5249d84cde9373c138e1258
4
- data.tar.gz: f9a1065a77d4963a387f2cd517cd57ae614b635f0c8c1cf92179b84967b4dab9
3
+ metadata.gz: 65237e7c68103c07d9095203160a773c8f4505388c603bdf486532cdda316749
4
+ data.tar.gz: 7146c2952c2756916956ec9aecab7bb293c9ec10a2b9d1ca8540efb7b464c16c
5
5
  SHA512:
6
- metadata.gz: 866d8449995556f189b2229ae34b648fa2870f0b126308edd45fab9f5e9920051ee1a354628370a747deca177cf844906da5df494ab659f8a5c99e5b8ab1a1d6
7
- data.tar.gz: b007267965376a36a548c015ff16761c3808ae9782321bd5e4a0536646af4efe48937918406061383892840532a79d6eeb9f9c4990a51242a72f2d64defe857b
6
+ metadata.gz: 1cae0fbdbf08073726a869d9224edf75fcd50aa559cd75adbc18cf401c9f2e9f1fb85a1c16976ee7323774113191bcfb4f8b1e6a228f148782a075424b407fb8
7
+ data.tar.gz: c96db56cf3534f287f63545e76bd53c51aa017245d99fe63541604a7ccc1da283ec64e03c05ebdbe406e6738a089877dd9c4bdb0ff6a7ae1a5096bb3148885b9
data/.licensed.yml CHANGED
@@ -1,4 +1,4 @@
1
- name: "jp_quest"
1
+ name: "modpack_localizer"
2
2
 
3
3
  allowed:
4
4
  - mit
data/CHANGELOG.md CHANGED
@@ -48,4 +48,12 @@
48
48
 
49
49
  ## [0.1.2] -2024-11/9
50
50
 
51
- - 言語ファイルが既に存在する場合のメッセージが出力されない問題を修正
51
+ - 言語ファイルが既に存在する場合のメッセージが出力されない問題を修正
52
+
53
+ ## [0.1.3] -2024-11/11
54
+
55
+ - BOM付きの言語ファイルでJSON.parseに失敗する問題を修正
56
+
57
+ ## [0.1.4] -2025-03/31
58
+
59
+ - ライブラリ名の更新
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## ModpackLocalizer
2
2
 
3
- Translator for FTBQuest. (title, subtitle, description)
3
+ Localizer for Minecraft Modpack.
4
4
  If you want to translate to other languages than Japanese,
5
5
  please add the `language` option during initialization.
6
6
  Can always get help with `ModpackLocalizer.help`
@@ -8,6 +8,7 @@ Can always get help with `ModpackLocalizer.help`
8
8
  #### Example
9
9
 
10
10
  `ModpackLocalizer::SNBT::Performer.new(language: "English")`
11
+ `ModpackLocalizer::JAR::Performer.new(language: "English")`
11
12
  or if no specific configs required
12
13
  `ModpackLocalizer.omakase(language: "English")`
13
14
 
@@ -18,62 +19,64 @@ or if no specific configs required
18
19
  3. Add `OPENAI_API_KEY=your_api_key` to `.env`
19
20
  4. Optional: Add `OPENAI_MODEL=some_openai_model` to `.env` **(default: gpt-4o-mini)**
20
21
  5. Add `some.snbt` or `quests` directory contents to `quests` directory
21
- 6. Check `output` directory
22
+ 6. Add `some.jar` files to `mods` directory
23
+ 7. Double click `start.bat` file
24
+ 8. Check `output` directory
22
25
 
23
- ## ModpackLocalizer.omakase Options
26
+ ## Options for omakase method
24
27
 
25
28
  #### language
26
29
 
27
- Which language do you want to translate to?
30
+ Which language do you want to translate to?
28
31
  **(default: Japanese)**
29
32
 
30
33
  #### country
31
34
 
32
- Your country name
35
+ Your country name
33
36
  **(default: Japan)**
34
37
 
35
38
  #### locale_code
36
39
 
37
40
  Which locale code do you want to use?
38
- If you specified this, you don't need to specify the country.
41
+ If you specified this, you don't need to specify the country.
39
42
  **(default: nil)**
40
43
 
41
44
  #### threadable
42
45
 
43
- Do you want to exec in parallel?
46
+ Do you want to exec in parallel?
44
47
  **(default: false)**
45
48
 
46
- ## Initialize Options
49
+ ## Initialize options
47
50
 
48
51
  #### output_logs
49
52
 
50
- Want to output OpenAI usage logs?
53
+ Want to output OpenAI usage logs?
51
54
  **(default: true)**
52
55
 
53
56
  #### except_words
54
57
 
55
- Words that you don't want to translate
58
+ Words that you don't want to translate
56
59
  **(default: empty array)**
57
60
 
58
61
  #### language
59
62
 
60
- Which language do you want to translate to?
63
+ Which language do you want to translate to?
61
64
  **(default: Japanese)**
62
65
 
63
66
  #### display_help
64
67
 
65
- Want to display help?
68
+ Want to display help?
66
69
  **(default: true)**
67
70
 
68
- ## Only for jar performer
71
+ ## Only for jar performer initialize options
69
72
 
70
73
  #### country
71
74
 
72
- Your country name
75
+ Your country name
73
76
  **(default: Japan)**
74
77
 
75
78
  #### locale_code
76
79
 
77
80
  Which locale code do you want to use?
78
- If you specified this, you don't need to specify the country.
79
- **(default: nil)**
81
+ If you specified this, you don't need to specify the country.
82
+ **(default: nil)**
data/dist/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "jp_quest"
3
+ gem "modpack_localizer"
data/dist/example.rb CHANGED
@@ -1,10 +1,13 @@
1
+ # require "modpack_localizer"
2
+
3
+ # ModpackLocalizer.omakase(language: "English")
4
+ # or
5
+ # ModpackLocalizer.omakase(language: "Japanese", country: "Japan", locale_code: "ja_jp", threadable: true)
6
+
1
7
  require_relative "../lib/modpack_localizer"
2
8
 
3
- file_path = "dist/mods"
9
+ file_path = "dist/quests"
4
10
  language = "japanese"
5
- country_name = "japan"
6
11
 
7
- performer = ModpackLocalizer::JAR::Performer.new(language: language, country: country_name, display_help: false)
12
+ performer = ModpackLocalizer::SNBT::Performer.new(language: language)
8
13
  performer.perform_directory(dir_path: file_path)
9
-
10
- #ModpackLocalizer.omakase(language: "Japanese", country: "Japan", locale_code: nil, threadable: true)
@@ -1,4 +1,4 @@
1
- require "jp_translator_from_gpt"
1
+ require "translation_api"
2
2
  require "active_support/core_ext/string/inflections"
3
3
  require_relative "../util/help"
4
4
  require_relative "../util/error"
@@ -8,7 +8,6 @@ require_relative "writer"
8
8
  module ModpackLocalizer
9
9
  module JAR
10
10
  # .jarの翻訳を実行するクラス
11
- # JpTranslatorFromGptを使用して翻訳を行う
12
11
  class Performer
13
12
  # locale_codeを指定する場合、countryの指定は不要
14
13
  #
@@ -23,10 +22,11 @@ module ModpackLocalizer
23
22
  output_logs: true, except_words: [], language: "Japanese",
24
23
  country: "Japan", locale_code: nil, display_help: true
25
24
  )
26
- @translator = JpTranslatorFromGpt::Translator.new(
25
+ @translator = TranslationAPI::Mediator.new(
27
26
  output_logs: output_logs,
28
27
  except_words: except_words,
29
- exchange_language: language
28
+ language: language,
29
+ agent: :openai
30
30
  )
31
31
  @language, @country_name, @locale_code = language, country, locale_code
32
32
  @reader, @writer, @progress_bar, @loggable, @tierdown = nil
@@ -9,6 +9,8 @@ module ModpackLocalizer
9
9
  class Reader
10
10
  # 例: ja_jp
11
11
  LOCALE_CODE_REGEX = /\A[a-z]{2,3}_[a-z]{2,3}\z/
12
+ # BOM付きだとJSON.parseでエラーが出る
13
+ BOM_REGEX = /\A\xEF\xBB\xBF/
12
14
 
13
15
  # performerに渡すレスポンス
14
16
  #
@@ -60,7 +62,7 @@ module ModpackLocalizer
60
62
  )
61
63
  end
62
64
 
63
- raw_json = JSON.parse(lang_file.get_input_stream.read)
65
+ raw_json = parse_json(lang_file)
64
66
 
65
67
  LangData.new(
66
68
  true, except_comment(raw_json), lang_file, @locale_code, extract_mod_name(lang_file), nil
@@ -99,6 +101,42 @@ module ModpackLocalizer
99
101
  lang_files.find { |entry| target_locale_file?(entry, locale_code) }
100
102
  end
101
103
 
104
+ # JSONを解析する
105
+ # BOMを削除し、UTF-8に変換する
106
+ #
107
+ # @param [Zip::Entry] zip_entry ファイル
108
+ # @return [Hash] JSONのハッシュ
109
+ def parse_json(zip_entry)
110
+ content = read_inner_zip(zip_entry)
111
+ content = change_to_utf8(content)
112
+ content = remove_bom(content)
113
+ JSON.parse(content)
114
+ end
115
+
116
+ # zip内のファイルの内容を読み込む
117
+ #
118
+ # @param [Zip::Entry] zip_entry ファイル
119
+ # @return [String] ファイルの内容
120
+ def read_inner_zip(zip_entry)
121
+ zip_entry.get_input_stream.read
122
+ end
123
+
124
+ # BOMを削除する
125
+ #
126
+ # @param [String] str 文字列
127
+ # @return [String] BOMを削除した文字列
128
+ def remove_bom(str)
129
+ str.gsub(BOM_REGEX, "")
130
+ end
131
+
132
+ # UTF-8に変換する
133
+ #
134
+ # @param [String] str 文字列
135
+ # @return [String] UTF-8に変換した文字列
136
+ def change_to_utf8(str)
137
+ str.force_encoding("UTF-8")
138
+ end
139
+
102
140
  # JSONからコメントを除外する
103
141
  #
104
142
  # @param [Hash] hash JSONのハッシュ
@@ -1,4 +1,4 @@
1
- require "jp_translator_from_gpt"
1
+ require "translation_api"
2
2
  require_relative "../util/help"
3
3
  require_relative "../util/error"
4
4
  require_relative "reader"
@@ -7,7 +7,6 @@ require_relative "writer"
7
7
  module ModpackLocalizer
8
8
  module SNBT
9
9
  # .snbtの翻訳を実行するクラス
10
- # JpTranslatorFromGptを使用して翻訳を行う
11
10
  class Performer
12
11
  # @param [Boolean] output_logs APIのログを出力するか
13
12
  # @param [Array<String>] except_words 翻訳しない単語
@@ -15,10 +14,11 @@ module ModpackLocalizer
15
14
  # @param [Boolean] display_help ヘルプを表示するか
16
15
  # @return [ModpackLocalizer::SNBT::Performer]
17
16
  def initialize(output_logs: true, except_words: [], language: "Japanese", display_help: true)
18
- @translator = JpTranslatorFromGpt::Translator.new(
17
+ @translator = TranslationAPI::Mediator.new(
19
18
  output_logs: output_logs,
20
19
  except_words: except_words,
21
- exchange_language: language
20
+ language: language,
21
+ agent: :openai
22
22
  )
23
23
  @reader, @writer, @progress_bar, @loggable = nil
24
24
 
@@ -116,8 +116,8 @@ module ModpackLocalizer
116
116
  #{link("https://github.com/milkeclair/modpack_localizer")}
117
117
  current version: #{ModpackLocalizer::VERSION}
118
118
  translator:
119
- #{link("https://github.com/milkeclair/jp_translator_from_gpt")}
120
- current version: #{JpTranslatorFromGpt::VERSION}
119
+ #{link("https://github.com/milkeclair/translation_api")}
120
+ current version: #{TranslationAPI::VERSION}
121
121
  INFORMATION
122
122
  end
123
123
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ModpackLocalizer
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modpack_localizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - milkeclair
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-09 00:00:00.000000000 Z
10
+ date: 2025-03-30 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -52,20 +51,6 @@ dependencies:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
53
  version: 0.3.8
55
- - !ruby/object:Gem::Dependency
56
- name: jp_translator_from_gpt
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 1.1.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 1.1.0
69
54
  - !ruby/object:Gem::Dependency
70
55
  name: json
71
56
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +107,20 @@ dependencies:
122
107
  - - '='
123
108
  - !ruby/object:Gem::Version
124
109
  version: 3.0.0.alpha
110
+ - !ruby/object:Gem::Dependency
111
+ name: translation_api
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.1.1
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.1.1
125
124
  description: localize minecraft modpack
126
125
  email:
127
126
  - milkeclair.noreply@gmail.com
@@ -165,7 +164,6 @@ metadata:
165
164
  source_code_uri: https://github.com/milkeclair/modpack_localizer/blob/main
166
165
  changelog_uri: https://github.com/milkeclair/modpack_localizer/blob/main/CHANGELOG.md
167
166
  rubygems_mfa_required: 'true'
168
- post_install_message:
169
167
  rdoc_options: []
170
168
  require_paths:
171
169
  - lib
@@ -180,8 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
178
  - !ruby/object:Gem::Version
181
179
  version: '0'
182
180
  requirements: []
183
- rubygems_version: 3.5.21
184
- signing_key:
181
+ rubygems_version: 3.6.2
185
182
  specification_version: 4
186
183
  summary: localize minecraft modpack
187
184
  test_files: []