flutter-intl-twine-formatter 1.0.0
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 +7 -0
- data/lib/flutter-intl-twine-formatter.rb +92 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0487dcc7a37d12903179aa2e040dd8524a938d96112d3e89fbc48a6c42e19787'
|
4
|
+
data.tar.gz: 4636baeb0c9a3bc6d9d25f92215d03d70e9ca99f705878f086b11af32c89b9eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbee2fbaa03f8a9274bae476c986302fb6098cba2b10a8eba687fe5b7c9eb709ebe2b5ad71c8cb6c714f98bdce8b0fd2291dc681e26528d387dbc7b909abc73e
|
7
|
+
data.tar.gz: e9109bc75b9c483380e2bb8516821b4041e7c8e643aa23da87042a676116ffad97add5223134b1b0b10d2a20d86102f5f3b85715e8d9441ea58c1f81bc6918c0
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Twine
|
2
|
+
module Formatters
|
3
|
+
class Flutter < Abstract
|
4
|
+
|
5
|
+
include Twine::Placeholders
|
6
|
+
|
7
|
+
def format_name
|
8
|
+
'flutter'
|
9
|
+
end
|
10
|
+
|
11
|
+
def extension
|
12
|
+
'.arb'
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_file_name
|
16
|
+
'intl_en.arb'
|
17
|
+
end
|
18
|
+
|
19
|
+
def determine_language_given_path(path)
|
20
|
+
path_arr = path.split(File::SEPARATOR)
|
21
|
+
path_arr.each do |segment|
|
22
|
+
match = /^((.+)-)?([^-]+)\.arb$/.match(segment)
|
23
|
+
if match
|
24
|
+
return match[3]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
def read(io, lang)
|
32
|
+
begin
|
33
|
+
require "json"
|
34
|
+
rescue LoadError
|
35
|
+
raise Twine::Error.new "You must run 'gem install json' in order to read or write Flutter-localize files."
|
36
|
+
end
|
37
|
+
|
38
|
+
json = JSON.load(io)
|
39
|
+
json.each do |key, value|
|
40
|
+
set_translation_for_key(key, lang, value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def format_file(lang)
|
45
|
+
result = super
|
46
|
+
return result unless result
|
47
|
+
"{\n#{super}\n}\n"
|
48
|
+
end
|
49
|
+
|
50
|
+
def format_sections(twine_file, lang)
|
51
|
+
sections = twine_file.sections.map { |section| format_section(section, lang) }
|
52
|
+
sections.delete_if &:empty?
|
53
|
+
sections.join(",\n\n")
|
54
|
+
end
|
55
|
+
|
56
|
+
def format_section_header(section)
|
57
|
+
end
|
58
|
+
|
59
|
+
def format_section(section, lang)
|
60
|
+
definitions = section.definitions.dup
|
61
|
+
|
62
|
+
definitions.map! { |definition| format_definition(definition, lang) }
|
63
|
+
definitions.compact! # remove nil definitions
|
64
|
+
definitions.join(",\n")
|
65
|
+
end
|
66
|
+
|
67
|
+
def key_value_pattern
|
68
|
+
"\"%{key}\": \"%{value}\""
|
69
|
+
end
|
70
|
+
|
71
|
+
def format_key(key)
|
72
|
+
escape_quotes(key)
|
73
|
+
end
|
74
|
+
|
75
|
+
def format_value(value)
|
76
|
+
convert_placeholders_from_twine_to_icu(value)
|
77
|
+
end
|
78
|
+
|
79
|
+
def convert_placeholders_from_twine_to_icu(input)
|
80
|
+
value = convert_twine_string_placeholder(input)
|
81
|
+
|
82
|
+
value.gsub(PLACEHOLDER_REGEX).each_with_index do |match, index|
|
83
|
+
"{arg#{index + 1}}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
Twine::Formatters.formatters << Twine::Formatters::Flutter.new
|
92
|
+
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flutter-intl-twine-formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Williamson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-30 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description: A Twine formatter for Flutter and intl
|
28
|
+
email: dwilliamson@freelancer.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/flutter-intl-twine-formatter.rb
|
34
|
+
homepage: http://rubygems.org/gems/flutter-intl-twine-formatter
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.7.7
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A Twine formatter for Flutter and intl
|
58
|
+
test_files: []
|