twine-flutter 0.1.0 → 0.2.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 +4 -4
- data/README.md +133 -3
- data/lib/formatter.rb +11 -10
- data/test/fixtures/app_en.arb +33 -0
- data/test/fixtures/test.arb +33 -0
- data/test/fixtures/twine.txt +8 -4
- data/test/fixtures/uncategorized_twine.txt +13 -0
- metadata +19 -3
- data/test/fixtures/flutter_format.arb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15a3ba2b0b13dd5f82be010a87d3bed56fefbfb493268aba7d17ee50e6d955cb
|
4
|
+
data.tar.gz: 812a54e3480ab12975c5082055960549552fe080a44803a568ba06698f2f17dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 261c6208aae7b9d0e609931adb369dd7adac7eeb2332bea965775e408df61a2300adcb4728ea445f59db12a41e97ee1671d536dbda8464a1f69a94695dc7efaa
|
7
|
+
data.tar.gz: 1bb62f33803a6ac2beb6103f51baaf2020a3a7d52eff7a7234f94a74bf1b37b6b0423df09e240d40b383cc7b377fc1640ece9662e8682fd88e5e7799dce7fe0a
|
data/README.md
CHANGED
@@ -1,11 +1,141 @@
|
|
1
1
|
# Twine Flutter formatter plugin
|
2
2
|
This [twine](https://github.com/scelis/twine) plugin provide a formatter for `.arb` files, used by Flutter projects.
|
3
3
|
|
4
|
+
## Features
|
5
|
+
|
6
|
+
* Generation of arb files from twine
|
7
|
+
* Consumation of localized arb files into twine
|
8
|
+
* Support of arb comments
|
9
|
+
* Basic support of arb placeholders
|
10
|
+
|
11
|
+
## Generation of localizations
|
12
|
+
To generate a localizations `.arb` file use twine `generate-localization-file` command.
|
13
|
+
|
14
|
+
Example:
|
15
|
+
`twine generate-localization-file twine.txt app_en.arb`
|
16
|
+
|
17
|
+
_Input twine file:_
|
18
|
+
```
|
19
|
+
[[Section A]]
|
20
|
+
[key1]
|
21
|
+
en = Text with comment for translators
|
22
|
+
comment = comment key1
|
23
|
+
[key2]
|
24
|
+
en = Simple text
|
25
|
+
```
|
26
|
+
|
27
|
+
_Output arb file:_
|
28
|
+
```json
|
29
|
+
{
|
30
|
+
"@@locale": "en",
|
31
|
+
|
32
|
+
"key1": "Text with comment for translators",
|
33
|
+
"@key1": {
|
34
|
+
"description": "comment key1"
|
35
|
+
},
|
36
|
+
"key2": "Simple text"
|
37
|
+
}
|
38
|
+
```
|
39
|
+
|
40
|
+
## Consumation of localizations
|
41
|
+
To consume a twin localizations file to an `.arb` file use twine `consume-localization-file` command.
|
42
|
+
If you want to consume comments add `-c` option to the twine command.
|
43
|
+
|
44
|
+
Example:
|
45
|
+
`twine consume-localization-file twine.txt app_en.arb -c`
|
46
|
+
|
47
|
+
_Input arb file:_
|
48
|
+
```json
|
49
|
+
{
|
50
|
+
"@@locale": "en",
|
51
|
+
|
52
|
+
"key1": "Text with comment for translators",
|
53
|
+
"@key1": {
|
54
|
+
"description": "comment key1"
|
55
|
+
},
|
56
|
+
"key2": "Simple text"
|
57
|
+
}
|
58
|
+
```
|
59
|
+
|
60
|
+
_Output twine file:_
|
61
|
+
```
|
62
|
+
[[Uncategorized]]
|
63
|
+
[key1]
|
64
|
+
en = Text with comment for translators
|
65
|
+
comment = comment key1
|
66
|
+
[key2]
|
67
|
+
en = Simple text
|
68
|
+
```
|
69
|
+
|
70
|
+
**Warning!** The arb file doesn't contain any reference to sections so all the keys are added to the "Uncategorized" section, when the `-a` option of `consume-localization-file` is used.
|
71
|
+
|
72
|
+
## Placeholders
|
73
|
+
Flutter provides [extended support](https://localizely.com/flutter-arb/) to placeholders in the localization files.
|
74
|
+
|
75
|
+
Currently this plugin support a basic use of placeholders automatically creating an untyped placeholder for every string wrapped with curlty braces.
|
76
|
+
Are only supported placeholders with lowercase chars, uppercase chars, digits, `.`, `_` and `-`.
|
77
|
+
|
78
|
+
Example:
|
79
|
+
|
80
|
+
_Input twine file:_
|
81
|
+
```
|
82
|
+
[[Section B]]
|
83
|
+
[key3]
|
84
|
+
en = Text with {name} placeholder
|
85
|
+
[key4]
|
86
|
+
en = Text with double placeholders {1} and {2} and a comment
|
87
|
+
comment = comment key4
|
88
|
+
|
89
|
+
[[Section C]]
|
90
|
+
[key5]
|
91
|
+
en = Placeholders with punctuation: {p_1}, {p-1}, {p.1}
|
92
|
+
```
|
93
|
+
|
94
|
+
_Output arb file:_
|
95
|
+
```json
|
96
|
+
{
|
97
|
+
"@@locale": "en",
|
98
|
+
|
99
|
+
"key3": "Text with {name} placeholder",
|
100
|
+
"@key3": {
|
101
|
+
"placeholders": {
|
102
|
+
"name": {}
|
103
|
+
}
|
104
|
+
},
|
105
|
+
"key4": "Text with double placeholders {1} and {2} and a comment",
|
106
|
+
"@key4": {
|
107
|
+
"description": "comment key4",
|
108
|
+
"placeholders": {
|
109
|
+
"1": {},
|
110
|
+
"2": {}
|
111
|
+
}
|
112
|
+
},
|
113
|
+
|
114
|
+
"key5": "Placeholders with punctuation: {p_1}, {p-1}, {p.1}",
|
115
|
+
"@key5": {
|
116
|
+
"placeholders": {
|
117
|
+
"p_1": {},
|
118
|
+
"p-1": {},
|
119
|
+
"p.1": {}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
```
|
124
|
+
|
4
125
|
## Installation
|
5
126
|
Install this gem:
|
6
127
|
|
7
|
-
```
|
128
|
+
```ruby
|
129
|
+
gem install twine-flutter
|
130
|
+
```
|
131
|
+
|
132
|
+
Then setup twine to use this plugin as described [here](https://github.com/scelis/twine/blob/main/documentation/formatters.md#plugins) adding the following in a twine configuration file.
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
gems: twine-flutter
|
136
|
+
```
|
8
137
|
|
9
|
-
|
138
|
+
## TODO
|
10
139
|
|
11
|
-
|
140
|
+
* Automatic testing
|
141
|
+
* Extended placeholder support
|
data/lib/formatter.rb
CHANGED
@@ -21,18 +21,13 @@ module Twine
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def read(io, lang)
|
24
|
-
|
25
|
-
require "json"
|
26
|
-
rescue LoadError
|
27
|
-
raise Twine::Error.new "You must run `gem install json` in order to read or write flutter files."
|
28
|
-
end
|
24
|
+
require "json"
|
29
25
|
|
30
26
|
json = JSON.load(io)
|
31
27
|
json.each do |key, value|
|
32
28
|
if key == "@@locale"
|
33
29
|
# Ignore because it represents the file lang
|
34
30
|
elsif key[0,1] == "@"
|
35
|
-
description_value = "{\n \"description\":\"#{value}\"\n }"
|
36
31
|
if value["description"]
|
37
32
|
set_comment_for_key(key[1..-1], value["description"])
|
38
33
|
end
|
@@ -67,16 +62,22 @@ module Twine
|
|
67
62
|
end
|
68
63
|
|
69
64
|
def format_definition(definition, lang)
|
70
|
-
[format_key_value(definition, lang),
|
65
|
+
[format_key_value(definition, lang), format_comment_and_placeholders(definition, lang)].compact.join(",\n")
|
71
66
|
end
|
72
67
|
|
73
68
|
def key_value_pattern
|
74
69
|
" \"%{key}\": \"%{value}\""
|
75
70
|
end
|
76
71
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
72
|
+
def format_comment_and_placeholders(definition, lang)
|
73
|
+
placeholdersScan = definition.translation_for_lang(lang).scan(/{[a-zA-Z0-9\-\_\.]+}/m)
|
74
|
+
if definition.comment || !placeholdersScan.empty?
|
75
|
+
comment = " \"description\": \"#{definition.comment}\"" if definition.comment
|
76
|
+
placeholders = placeholdersScan.map! { |placeholder| " \"#{placeholder.tr('{}','')}\": {}" }.join(",\n") if !placeholdersScan.empty?
|
77
|
+
placeholdersBlock = " \"placeholders\": {\n#{placeholders}\n }" if placeholders
|
78
|
+
return " \"@#{definition.key}\": {\n#{[comment, placeholdersBlock].compact.join(",\n")}\n }"
|
79
|
+
end
|
80
|
+
end
|
80
81
|
|
81
82
|
def format_key(key)
|
82
83
|
escape_quotes(key)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"@@locale": "en",
|
3
|
+
|
4
|
+
"key1": "Text with comment for translators",
|
5
|
+
"@key1": {
|
6
|
+
"description": "comment key1"
|
7
|
+
},
|
8
|
+
"key2": "Simple text",
|
9
|
+
|
10
|
+
"key3": "Text with {name} placeholder",
|
11
|
+
"@key3": {
|
12
|
+
"placeholders": {
|
13
|
+
"name": {}
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"key4": "Text with double placeholders {1} and {2} and a comment",
|
17
|
+
"@key4": {
|
18
|
+
"description": "comment key4",
|
19
|
+
"placeholders": {
|
20
|
+
"1": {},
|
21
|
+
"2": {}
|
22
|
+
}
|
23
|
+
},
|
24
|
+
|
25
|
+
"key5": "Placeholders with punctuation: {p_1}, {p-1}, {p.1}",
|
26
|
+
"@key5": {
|
27
|
+
"placeholders": {
|
28
|
+
"p_1": {},
|
29
|
+
"p-1": {},
|
30
|
+
"p.1": {}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"@@locale": "en",
|
3
|
+
|
4
|
+
"key1": "Text with comment for translators",
|
5
|
+
"@key1": {
|
6
|
+
"description": "comment key1"
|
7
|
+
},
|
8
|
+
"key2": "Simple text",
|
9
|
+
|
10
|
+
"key3": "Text with {name} placeholder",
|
11
|
+
"@key3": {
|
12
|
+
"placeholders": {
|
13
|
+
"name": {}
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"key4": "Text with double placeholders {1} and {2} and a comment",
|
17
|
+
"@key4": {
|
18
|
+
"description": "comment key4",
|
19
|
+
"placeholders": {
|
20
|
+
"1": {},
|
21
|
+
"2": {}
|
22
|
+
}
|
23
|
+
},
|
24
|
+
|
25
|
+
"key5": "Placeholders with punctuation: {p_1}, {p-1}, {p.1}",
|
26
|
+
"@key5": {
|
27
|
+
"placeholders": {
|
28
|
+
"p_1": {},
|
29
|
+
"p-1": {},
|
30
|
+
"p.1": {}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
data/test/fixtures/twine.txt
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
[[Section A]]
|
2
2
|
[key1]
|
3
|
-
en =
|
3
|
+
en = Text with comment for translators
|
4
4
|
comment = comment key1
|
5
5
|
[key2]
|
6
|
-
en =
|
6
|
+
en = Simple text
|
7
7
|
|
8
8
|
[[Section B]]
|
9
9
|
[key3]
|
10
|
-
en =
|
10
|
+
en = Text with {name} placeholder
|
11
11
|
[key4]
|
12
|
-
en =
|
12
|
+
en = Text with double placeholders {1} and {2} and a comment
|
13
13
|
comment = comment key4
|
14
|
+
|
15
|
+
[[Section C]]
|
16
|
+
[key5]
|
17
|
+
en = Placeholders with punctuation: {p_1}, {p-1}, {p.1}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
[[Uncategorized]]
|
2
|
+
[key1]
|
3
|
+
en = Text with comment for translators
|
4
|
+
comment = comment key1
|
5
|
+
[key2]
|
6
|
+
en = Simple text
|
7
|
+
[key3]
|
8
|
+
en = Text with {name} placeholder
|
9
|
+
[key4]
|
10
|
+
en = Text with double placeholders {1} and {2} and a comment
|
11
|
+
comment = comment key4
|
12
|
+
[key5]
|
13
|
+
en = Placeholders with punctuation: {p_1}, {p-1}, {p.1}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twine-flutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Butti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twine
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.6.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.6.0
|
27
41
|
description: Plugin for twine that enables .arb generation for use with Flutter.
|
28
42
|
email:
|
29
43
|
- butti.fabio@tiknil.com
|
@@ -35,8 +49,10 @@ files:
|
|
35
49
|
- README.md
|
36
50
|
- lib/formatter.rb
|
37
51
|
- lib/twine-flutter.rb
|
38
|
-
- test/fixtures/
|
52
|
+
- test/fixtures/app_en.arb
|
53
|
+
- test/fixtures/test.arb
|
39
54
|
- test/fixtures/twine.txt
|
55
|
+
- test/fixtures/uncategorized_twine.txt
|
40
56
|
- test/test_flutter_formatter.rb
|
41
57
|
homepage: https://github.com/tiknil/twine-flutter
|
42
58
|
licenses:
|