natsukantou 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/monkey_patch/oga_document.rb +64 -0
- data/lib/natsukantou/deep_l.rb +2 -0
- data/lib/natsukantou/minhon.rb +2 -0
- data/lib/natsukantou/setup/config_load_or_prompt.rb +2 -0
- data/lib/natsukantou/utility/env.rb +4 -1
- data/lib/natsukantou/utility/language_code.rb +5 -3
- data/lib/natsukantou/version.rb +1 -1
- data/lib/natsukantou.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c57ca088a6f550986f0d3d4244a5ec85ba4271b8034b76d9c389ebbce5a6219d
|
4
|
+
data.tar.gz: 6ef86b82bf6ba37ef22e0235aa4219d3c0e91f6578ea783a53b808ac5753e9ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b405772e21b46d959122c0e9e4c1f24eb55bc75b34a3b5b64e21c13f645766a47cfcf8d26a5bb5e307d458c2aca11d34a3f75228464dda7d82e020c277eac31a
|
7
|
+
data.tar.gz: 59cc9abd5cacf466de075265b9a30d867cf8cec019d9b272382975ab6dd08f9d5fc4c7e9be37e4cfae68583af90b87a91ae398c1378ca5c15077b7c3cc05892a
|
data/README.md
CHANGED
@@ -18,13 +18,17 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
To run it as a command:
|
22
|
+
|
23
|
+
$ natsukantou [XML_FILE]
|
22
24
|
|
23
25
|
It's a wizard that guides you through setting up a translator configuration.
|
24
26
|
|
25
27
|
Then it will translate the XML document.
|
26
28
|
|
27
|
-
If you choose to save the config (`translator_config.rb`), next time you can reuse it by calling
|
29
|
+
If you choose to save the config (`translator_config.rb`), next time you can reuse it by calling
|
30
|
+
|
31
|
+
$ natsukantou -c [CONFIG_FILE] [XML_FILE]
|
28
32
|
|
29
33
|
## Feature
|
30
34
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Oga
|
2
|
+
module XML
|
3
|
+
class Element
|
4
|
+
def lang
|
5
|
+
get('lang')
|
6
|
+
end
|
7
|
+
|
8
|
+
def lang=(lang)
|
9
|
+
if lang
|
10
|
+
set('lang', lang)
|
11
|
+
set('xml:lang', lang) if attribute('xml:lang')
|
12
|
+
else
|
13
|
+
unset('lang')
|
14
|
+
unset('xml:lang')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Document
|
20
|
+
def html_node
|
21
|
+
at_xpath('html')
|
22
|
+
end
|
23
|
+
|
24
|
+
def lang
|
25
|
+
html_node&.lang
|
26
|
+
end
|
27
|
+
|
28
|
+
# TODO: handle non-HTML
|
29
|
+
def lang=(lang)
|
30
|
+
html_node&.lang = lang
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param other [Oga::XML::Document] other to interlace from.
|
34
|
+
# Note this will have side-effects on it, so be aware not to persist it.
|
35
|
+
# @param level [String] CSS selector to interlace
|
36
|
+
def interlace(other, level:)
|
37
|
+
nodes = css(level).to_a
|
38
|
+
nodes_other = other.css(level).to_a
|
39
|
+
|
40
|
+
root_lang = lang
|
41
|
+
root_lang_other = other.lang
|
42
|
+
|
43
|
+
nodes.each.with_index do |node, i|
|
44
|
+
node_other = nodes_other[i]
|
45
|
+
|
46
|
+
node.lang = root_lang
|
47
|
+
node_other.lang = root_lang_other
|
48
|
+
|
49
|
+
node.after(node_other)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Generator
|
55
|
+
def on_text(node, output)
|
56
|
+
if @html_mode && (parent = node.parent) && parent.literal_html_name?
|
57
|
+
output << node.text.encode('utf-8')
|
58
|
+
else
|
59
|
+
output << Entities.encode(node.text).encode('utf-8')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/natsukantou/deep_l.rb
CHANGED
data/lib/natsukantou/minhon.rb
CHANGED
@@ -14,7 +14,10 @@ module Natsukantou
|
|
14
14
|
def initialize(env)
|
15
15
|
# Convert languages
|
16
16
|
[:lang_from, :lang_to].each do |key|
|
17
|
-
|
17
|
+
lang = env.fetch(key)
|
18
|
+
next if lang.is_a?(LanguageCode)
|
19
|
+
|
20
|
+
env[key] = LanguageCode.new(lang)
|
18
21
|
end
|
19
22
|
|
20
23
|
# Required keys
|
@@ -7,14 +7,16 @@ module Natsukantou
|
|
7
7
|
@main, @sub = @code.split('-')
|
8
8
|
|
9
9
|
if @main.length != 2
|
10
|
-
raise 'Language code
|
10
|
+
raise 'Language code should be in the form of xx or xx-yy'
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
attr_reader :code, :main, :sub
|
15
15
|
|
16
|
-
def is?(
|
17
|
-
other
|
16
|
+
def is?(other)
|
17
|
+
if !other.is_a?(self.class)
|
18
|
+
other = self.class.new(other)
|
19
|
+
end
|
18
20
|
|
19
21
|
return false if other.main != main
|
20
22
|
|
data/lib/natsukantou/version.rb
CHANGED
data/lib/natsukantou.rb
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
require 'logger'
|
4
4
|
require 'middleware'
|
5
5
|
require_relative "monkey_patch/builder"
|
6
|
-
require_relative "monkey_patch/runner"
|
7
6
|
require 'oga'
|
7
|
+
require_relative "monkey_patch/oga_document"
|
8
|
+
require_relative "monkey_patch/runner"
|
8
9
|
|
9
10
|
require_relative "natsukantou/version"
|
10
11
|
require_relative "natsukantou/setup/registry"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natsukantou
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lulalala
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleware
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- Rakefile
|
126
126
|
- exe/natsukantou
|
127
127
|
- lib/monkey_patch/builder.rb
|
128
|
+
- lib/monkey_patch/oga_document.rb
|
128
129
|
- lib/monkey_patch/runner.rb
|
129
130
|
- lib/natsukantou.rb
|
130
131
|
- lib/natsukantou/deep_l.rb
|