swift_twine_formatter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/formatter.rb +96 -0
- data/lib/swift_twine_formatter.rb +6 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e2272da7485deb67f7e7023bffbac8f87127c5555c21e692a5fe9e972b41eca6
|
4
|
+
data.tar.gz: bdc16f04960875eb0e4134b7bc315d0d14909de31506ca0efdd56cbfbd1651e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b1e4aeb431366dcea212bda82197b3e194e6dde51678ab71a4a22a50325a212f8caa37375f0a19e6d58262d608a995e788a392026bd94cc0acd4bc3bc359bdc
|
7
|
+
data.tar.gz: 64f085976f745a6bde6eaaf9bb926c6417ddbb14bf0d4174106866fe1cdfe05f3fc7555932f40b9f7a2e62a5ddf6fd2e2023584d68043bdb39a60379a0020753
|
data/lib/formatter.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# based on Apple formatter
|
4
|
+
# https://github.com/scelis/twine/blob/main/lib/twine/formatters/apple.rb
|
5
|
+
|
6
|
+
module Twine
|
7
|
+
module Formatters
|
8
|
+
class SwiftFormatter < Abstract
|
9
|
+
def format_name
|
10
|
+
'swift'
|
11
|
+
end
|
12
|
+
|
13
|
+
def extension
|
14
|
+
'.strings'
|
15
|
+
end
|
16
|
+
|
17
|
+
def can_handle_directory?(path)
|
18
|
+
Dir.entries(path).any? { |item| /^.+\.lproj$/.match(item) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_file_name
|
22
|
+
'Localizable.strings'
|
23
|
+
end
|
24
|
+
|
25
|
+
def determine_language_given_path(path)
|
26
|
+
path_arr = path.split(File::SEPARATOR)
|
27
|
+
path_arr.each do |segment|
|
28
|
+
match = /^(.+)\.lproj$/.match(segment)
|
29
|
+
if match
|
30
|
+
if match[1] == "Base"
|
31
|
+
return @options[:developer_language]
|
32
|
+
else
|
33
|
+
return match[1]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
return super
|
39
|
+
end
|
40
|
+
|
41
|
+
def output_path_for_language(lang)
|
42
|
+
"#{lang}.lproj"
|
43
|
+
end
|
44
|
+
|
45
|
+
def read(io, lang)
|
46
|
+
last_comment = nil
|
47
|
+
while line = io.gets
|
48
|
+
# matches a `key = "value"` line, where key may be quoted or unquoted. The former may also contain escaped characters
|
49
|
+
match = /^\s*((?:"(?:[^"\\]|\\.)+")|(?:[^"\s=]+))\s*=\s*"((?:[^"\\]|\\.)*)"/.match(line)
|
50
|
+
if match
|
51
|
+
key = match[1]
|
52
|
+
key = key[1..-2] if key[0] == '"' and key[-1] == '"'
|
53
|
+
key.gsub!('\\"', '"')
|
54
|
+
value = match[2]
|
55
|
+
value.gsub!('\\"', '"')
|
56
|
+
set_translation_for_key(key, lang, value)
|
57
|
+
if last_comment
|
58
|
+
set_comment_for_key(key, last_comment)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
match = /\/\* (.*) \*\//.match(line)
|
63
|
+
if match
|
64
|
+
last_comment = match[1]
|
65
|
+
else
|
66
|
+
last_comment = nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def format_header(lang)
|
72
|
+
"//\n// Apple Strings File\n// Generated by Twine #{Twine::VERSION}\n//\n// Language: #{lang}\n//"
|
73
|
+
end
|
74
|
+
|
75
|
+
def format_section_header(section)
|
76
|
+
"// MARK: - #{section.name}\n"
|
77
|
+
end
|
78
|
+
|
79
|
+
def key_value_pattern
|
80
|
+
"\"%{key}\" = \"%{value}\";"
|
81
|
+
end
|
82
|
+
|
83
|
+
def format_comment(definition, lang)
|
84
|
+
"/* #{definition.comment.gsub('*/', '* /')} */\n" if definition.comment
|
85
|
+
end
|
86
|
+
|
87
|
+
def format_key(key)
|
88
|
+
escape_quotes(key)
|
89
|
+
end
|
90
|
+
|
91
|
+
def format_value(value)
|
92
|
+
escape_quotes(value)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swift_twine_formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergei Romashenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: twine
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.3
|
27
|
+
description: Plugin to generate .strings files with classic comments and marks format.
|
28
|
+
email:
|
29
|
+
- romashenko.sergey@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/formatter.rb
|
35
|
+
- lib/swift_twine_formatter.rb
|
36
|
+
homepage:
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.4'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.4.17
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Plugin to generate .strings files with classic comments and marks format
|
59
|
+
test_files: []
|