jp_quest 0.1.3 → 0.2.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 +4 -4
- data/.rubocop.yml +0 -2
- data/CHANGELOG.md +6 -1
- data/README.md +3 -3
- data/dist/Gemfile +1 -1
- data/dist/example.rb +2 -2
- data/lib/jp_quest/formatter.rb +71 -64
- data/lib/jp_quest/indent_helper.rb +0 -16
- data/lib/jp_quest/version.rb +1 -1
- data/lib/jp_quest/writer.rb +2 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0c36a1f3e9e85ef6e690ec96ddbb36391efe55d9d996490a5905c0d7dc98c15
|
4
|
+
data.tar.gz: 66555ea8f531ae8ac001f97d852b4f38797e4e3d38db294f1804fdbc76cb901b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3011529e8f7a2b4808223fd3bcfaf4c078f56ca637748d3fbd33eb226aebf07cfafd2d2654591ea56ca5a2e6069e0ecc5d691db72d4570465d5763a5ff4169a
|
7
|
+
data.tar.gz: 63ee1e3a2ee419b72654a2cd87fec57e1e8eb2cbf26c93114347de58fa5e0874d5b9c91e833fab740b84c40216751d48d1e30bf552ba3253cf785f4ed51586a4
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## JpQuest
|
2
2
|
|
3
|
-
Translator for
|
3
|
+
Translator for FTBQuest. (title, subtitle, description)
|
4
4
|
If you want to translate to other languages than Japanese,
|
5
5
|
please add the `exchange_language` option during initialization.
|
6
6
|
Can always get help with `JpQuest.help`
|
@@ -15,7 +15,7 @@ Can always get help with `JpQuest.help`
|
|
15
15
|
2. Make `.env` file
|
16
16
|
3. Add `OPENAI_API_KEY=your_api_key` to `.env`
|
17
17
|
4. Optional: Add `OPENAI_MODEL=some_openai_model` to `.env` **(default: gpt-4o-mini)**
|
18
|
-
5. Add `some.snbt` to `quests` directory
|
18
|
+
5. Add `some.snbt` or `quests` directory contents to `quests` directory
|
19
19
|
6. Check `output` directory
|
20
20
|
|
21
21
|
## Initialize Options
|
@@ -38,4 +38,4 @@ Which language do you want to translate to?
|
|
38
38
|
#### display_help
|
39
39
|
|
40
40
|
Want to display help?
|
41
|
-
**(default: true)**
|
41
|
+
**(default: true)**
|
data/dist/Gemfile
CHANGED
data/dist/example.rb
CHANGED
data/lib/jp_quest/formatter.rb
CHANGED
@@ -11,53 +11,70 @@ module JpQuest
|
|
11
11
|
# @param [String] indent インデント
|
12
12
|
# @return [String] SNBT形式に整形したコンテンツ
|
13
13
|
def format_overwritable_lines(content, indent)
|
14
|
-
|
15
|
-
|
16
|
-
formatted_lines = add_missing_lines(indented_lines, content, mid_indent)
|
17
|
-
format_for_snbt(formatted_lines, indent, content[:type])
|
14
|
+
full_lines = add_missing_lines(content)
|
15
|
+
format_for_snbt(full_lines, indent, content)
|
18
16
|
end
|
19
17
|
|
20
18
|
# SNBT形式に整形
|
21
19
|
#
|
22
20
|
# @param [Array<String>] lines 行
|
23
21
|
# @param [String] indent インデント
|
24
|
-
# @param [
|
22
|
+
# @param [Hash] content コンテンツ
|
25
23
|
# @return [String] SNBT形式に整形した行
|
26
|
-
def format_for_snbt(lines, indent,
|
27
|
-
lines
|
28
|
-
|
29
|
-
|
30
|
-
formatted_lines =
|
31
|
-
if lines.length == 1
|
32
|
-
type == :description ? "[#{lines[0].strip}]" : lines[0].strip.to_s
|
33
|
-
else
|
34
|
-
# description: [
|
35
|
-
# "Hello"
|
36
|
-
# "World"
|
37
|
-
# ]
|
38
|
-
"[\n#{lines.join("\n")}\n#{indent}]"
|
39
|
-
end
|
40
|
-
|
41
|
-
# " description: ["hoge"]"のような形式にする
|
42
|
-
"#{indent}#{type}: #{formatted_lines}"
|
24
|
+
def format_for_snbt(lines, indent, content)
|
25
|
+
lines = prepare_lines_for_snbt(lines, content)
|
26
|
+
formatted_lines = format_lines(lines, indent, content)
|
27
|
+
"#{indent}#{content[:type]}: #{formatted_lines}"
|
43
28
|
end
|
44
29
|
|
45
30
|
# 不足している行を追加
|
46
31
|
#
|
47
|
-
# @param [Array<String>] lines 行
|
48
32
|
# @param [Hash] content コンテンツ
|
49
|
-
# @param [String] middle_indent 中間行のインデント
|
50
33
|
# @return [void]
|
51
|
-
def add_missing_lines(
|
34
|
+
def add_missing_lines(content)
|
52
35
|
required_lines = extract_required_line_counts(content)
|
36
|
+
lines = content[:text].split("\n")
|
53
37
|
|
54
38
|
while lines.length < required_lines
|
55
|
-
lines << empty_middle_line(
|
39
|
+
lines << empty_middle_line(content[:indent])
|
56
40
|
end
|
57
41
|
|
58
42
|
lines
|
59
43
|
end
|
60
44
|
|
45
|
+
private
|
46
|
+
|
47
|
+
# 不要な文字を削除する
|
48
|
+
#
|
49
|
+
# @param [String] lines 行
|
50
|
+
# @param [Hash] content コンテンツ
|
51
|
+
# @return [Array<String>] 不要な文字を削除した行
|
52
|
+
def prepare_lines_for_snbt(lines, content)
|
53
|
+
lines.map! { |line| delete_unwanted_symbols(line) }
|
54
|
+
lines.map!(&:strip) unless content[:type] == :description
|
55
|
+
lines
|
56
|
+
end
|
57
|
+
|
58
|
+
# SNBT形式に変換しやすい形に整形
|
59
|
+
#
|
60
|
+
# @param [Array<String>] lines 行
|
61
|
+
# @param [String] indent インデント
|
62
|
+
# @param [Hash] content コンテンツ
|
63
|
+
# @return [String] SNBT形式に変換しやすく整形した行
|
64
|
+
def format_lines(lines, indent, content)
|
65
|
+
if lines.length == 1
|
66
|
+
content[:type] == :description ? "[#{lines[0].strip}]" : lines[0].strip.to_s
|
67
|
+
else
|
68
|
+
# [
|
69
|
+
# "Hello"
|
70
|
+
# "World"
|
71
|
+
# ]
|
72
|
+
mid_indent = middle_indent(content[:indent])
|
73
|
+
lines = lines.map { |line| "#{mid_indent}#{line.strip}" }
|
74
|
+
"[\n#{lines.join("\n")}\n#{indent}]"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
61
78
|
# 必要な行数を抽出
|
62
79
|
#
|
63
80
|
# @param [Hash] content コンテンツ
|
@@ -70,62 +87,52 @@ module JpQuest
|
|
70
87
|
(content[:end_line] - content[:start_line]) + line_offset - without_brackets
|
71
88
|
end
|
72
89
|
|
73
|
-
# 中間行のインデントを追加
|
74
|
-
#
|
75
|
-
# @param [Hash] content コンテンツ
|
76
|
-
# @param [String] middle_indent 中間行のインデント
|
77
|
-
# @return [Array<String>] 中間行のインデントを追加した行
|
78
|
-
def add_indent_for_middle_lines(content, middle_indent)
|
79
|
-
content[:text].split("\n").map do |line|
|
80
|
-
"#{middle_indent}\"#{line}\""
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
90
|
# 中間行の空行を作成
|
85
91
|
#
|
86
|
-
# @param [String] middle_indent 中間行のインデント
|
87
92
|
# @return [String] 空行
|
88
|
-
def empty_middle_line(
|
89
|
-
|
93
|
+
def empty_middle_line(indent)
|
94
|
+
middle_indent(indent).to_s
|
90
95
|
end
|
91
96
|
|
92
|
-
#
|
97
|
+
# 不要な記号を削除
|
93
98
|
#
|
94
99
|
# @param [String] line 行
|
95
|
-
# @return [String]
|
96
|
-
def
|
100
|
+
# @return [String] 不要な記号を削除した行
|
101
|
+
def delete_unwanted_symbols(line)
|
102
|
+
line = delete_backslash(line)
|
103
|
+
line = delete_semicolon(line)
|
97
104
|
line = delete_dup_quotes(line)
|
98
105
|
line = delete_jp_quotes(line)
|
99
106
|
delete_curved_quotes(line)
|
100
107
|
end
|
101
108
|
|
102
|
-
|
109
|
+
# 不要なバックスラッシュを削除
|
110
|
+
#
|
111
|
+
# @param [String] line 行
|
112
|
+
# @return [String] 不要なバックスラッシュを削除した行
|
113
|
+
def delete_backslash(line)
|
114
|
+
line.gsub("\\", "")
|
115
|
+
end
|
116
|
+
|
117
|
+
# 不要なセミコロンを削除
|
118
|
+
#
|
119
|
+
# @param [String] line 行
|
120
|
+
# @return [String] 不要なセミコロンを削除した行
|
121
|
+
def delete_semicolon(line)
|
122
|
+
line.gsub(";", "")
|
123
|
+
end
|
103
124
|
|
104
125
|
# 不要なダブルクオートを削除
|
105
126
|
#
|
106
127
|
# @param [String] line 行
|
107
128
|
# @return [String] 不要なダブルクオートを削除した行
|
108
129
|
def delete_dup_quotes(line)
|
109
|
-
#
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
# """"に一致する場合は空白行なので、""に変換する
|
116
|
-
if line.strip.match?(deletable_regs[1])
|
117
|
-
line.gsub(dup_reg, '""')
|
118
|
-
else
|
119
|
-
# 行間にある余計なダブルクオートを削除するため、一度全てのダブルクオートを削除している
|
120
|
-
line = line.gsub('"', "")
|
121
|
-
# インデントの調整
|
122
|
-
indent_count = normalize_indent(line[/^\s*/].length)
|
123
|
-
line_start = /^(\s*)/
|
124
|
-
# 行頭にインデントとダブルクオートを追加
|
125
|
-
line = line.sub(line_start, "#{" " * indent_count}\"")
|
126
|
-
# 行末のダブルクオートを追加
|
127
|
-
"#{line}\""
|
128
|
-
end
|
130
|
+
# 行間にある余計なダブルクオートを削除するため、一度全てのダブルクオートを削除している
|
131
|
+
# 全て削除したあと、行頭、行末にダブルクオートを追加する
|
132
|
+
line = line.gsub('"', "")
|
133
|
+
line_start = /^(\s*)/
|
134
|
+
line = line.sub(line_start, "\"")
|
135
|
+
"#{line}\""
|
129
136
|
end
|
130
137
|
|
131
138
|
# 不要な鍵括弧を削除
|
@@ -16,21 +16,5 @@ module JpQuest
|
|
16
16
|
def middle_indent(indent)
|
17
17
|
" " * (indent + 1)
|
18
18
|
end
|
19
|
-
|
20
|
-
# インデントを調整
|
21
|
-
#
|
22
|
-
# @param [Integer] indent インデント数
|
23
|
-
# @return [Integer] 調整後のインデント数
|
24
|
-
def normalize_indent(indent)
|
25
|
-
dup_indent = 12
|
26
|
-
if indent > dup_indent
|
27
|
-
half = 2
|
28
|
-
half_indent = indent / half
|
29
|
-
# インデントの数は偶数にする
|
30
|
-
half_indent.even? ? half_indent : half_indent + 1
|
31
|
-
else
|
32
|
-
indent
|
33
|
-
end
|
34
|
-
end
|
35
19
|
end
|
36
20
|
end
|
data/lib/jp_quest/version.rb
CHANGED
data/lib/jp_quest/writer.rb
CHANGED
@@ -11,7 +11,8 @@ module JpQuest
|
|
11
11
|
# @return [JpQuest::Writer]
|
12
12
|
def initialize(file_path)
|
13
13
|
@input_file_path = file_path
|
14
|
-
|
14
|
+
# questsとすると、quests.snbtも変換されてしまうので、quests/とする
|
15
|
+
@output_file_path = file_path.gsub("quests/", "output/quests/")
|
15
16
|
@formatter = JpQuest::Formatter.new
|
16
17
|
end
|
17
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jp_quest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- milkeclair
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jp_translator_from_gpt
|
@@ -91,7 +91,7 @@ metadata:
|
|
91
91
|
source_code_uri: https://github.com/milkeclair/jp_quest/blob/main
|
92
92
|
changelog_uri: https://github.com/milkeclair/jp_quest/blob/main/CHANGELOG.md
|
93
93
|
rubygems_mfa_required: 'true'
|
94
|
-
post_install_message:
|
94
|
+
post_install_message:
|
95
95
|
rdoc_options: []
|
96
96
|
require_paths:
|
97
97
|
- lib
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubygems_version: 3.5.21
|
110
|
-
signing_key:
|
110
|
+
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: translate to japanese for ftbquest
|
113
113
|
test_files: []
|