jp_quest 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +3 -3
- data/dist/example.rb +1 -1
- data/lib/jp_quest/formatter.rb +51 -62
- data/lib/jp_quest/version.rb +1 -1
- data/lib/jp_quest/writer.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bacad61b26638c3d1bd038a0da019946218db0cd4008b99cd24107ff2838aa84
|
4
|
+
data.tar.gz: 98d0c0c49ee3d1d18dcee40e0f747f3866239af824cb25faf285b8f601eb70c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a318a51f4ca3feee083b749aa96cd53eeb3761f5bcd2c3d68e259e4c79a12e996a653dcb36688cb45ce5d88b2f3f8adbc17c21c1e3c292b758fbf6149f3e7ee7
|
7
|
+
data.tar.gz: 0635bcd6aff4e1958b833d31a8f7ba9cc153349450fd2e8336014767c99e8f113d906a3738b927e79898bc1d8c622778f99bde58d64a729c4320d90bae05b603
|
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/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_quotes(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,23 +87,11 @@ 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
|
# 不要な引用符を削除
|
@@ -99,33 +104,17 @@ module JpQuest
|
|
99
104
|
delete_curved_quotes(line)
|
100
105
|
end
|
101
106
|
|
102
|
-
private
|
103
|
-
|
104
107
|
# 不要なダブルクオートを削除
|
105
108
|
#
|
106
109
|
# @param [String] line 行
|
107
110
|
# @return [String] 不要なダブルクオートを削除した行
|
108
111
|
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
|
112
|
+
# 行間にある余計なダブルクオートを削除するため、一度全てのダブルクオートを削除している
|
113
|
+
# 全て削除したあと、行頭、行末にダブルクオートを追加する
|
114
|
+
line = line.gsub('"', "")
|
115
|
+
line_start = /^(\s*)/
|
116
|
+
line = line.sub(line_start, "\"")
|
117
|
+
"#{line}\""
|
129
118
|
end
|
130
119
|
|
131
120
|
# 不要な鍵括弧を削除
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- milkeclair
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jp_translator_from_gpt
|