bisu 1.7.3 → 1.8.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 -0
- data/README.md +6 -5
- data/lib/bisu.rb +6 -4
- data/lib/bisu/config.rb +3 -2
- data/lib/bisu/localizer.rb +12 -2
- data/lib/bisu/version.rb +2 -2
- data/spec/fixtures/sample.translatable.yml +2 -1
- data/spec/lib/bisu/config_spec.rb +9 -9
- data/spec/lib/bisu/localizer_spec.rb +7 -3
- data/spec/lib/bisu_spec.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: 2db1130663e6afdca1e4d1b22d34c5863db2f120cee81c1c802d69999b1c094b
|
4
|
+
data.tar.gz: 6f0cfd04fd34bb489055eaa0211aa74691f50f32c5fb13d8b7a1559c68a0f25a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2d8325f651a93ca9bc2edb7108af31ebc5d1e3d5e954c8a8890a1a7985d2afababe15166ca4d909984a0be453d6f6ad8965eb44b4e1588bd970bc0e3d9669af
|
7
|
+
data.tar.gz: 67699cebd837fc150ae54b433fb3386d79617211ff988b64bca73d681cd8daaeb6202c1e84280d1cfcf39a906c0930272c9f5f237f8d1eb187d856b0494570af
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
`Bisu` adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [1.8.0](https://github.com/hole19/bisu/releases/tag/v1.8.0)
|
6
|
+
Released on 2020/04/30
|
7
|
+
|
8
|
+
#### Added
|
9
|
+
- Adds a new option: allows a single translation to have a specific fallback language (example: "es-MX" fallback to "es")
|
10
|
+
|
5
11
|
## [1.7.3](https://github.com/hole19/bisu/releases/tag/v1.7.3)
|
6
12
|
Released on 2020/03/09
|
7
13
|
|
data/README.md
CHANGED
@@ -45,11 +45,12 @@ Setup your configuration file
|
|
45
45
|
out: path/to/2nd-%{locale}/strings.xml
|
46
46
|
|
47
47
|
languages:
|
48
|
-
- locale:
|
49
|
-
language: en
|
50
|
-
- locale:
|
51
|
-
language: en
|
52
|
-
|
48
|
+
- locale: en
|
49
|
+
language: en # the language as it appears in the dictionary
|
50
|
+
- locale: en-US
|
51
|
+
language: en-us
|
52
|
+
fallback_language: en
|
53
|
+
- locale: pt
|
53
54
|
language: pt
|
54
55
|
```
|
55
56
|
|
data/lib/bisu.rb
CHANGED
@@ -23,13 +23,15 @@ module Bisu
|
|
23
23
|
dictionary = dictionary_for(config: config.dictionary, options: options)
|
24
24
|
localizer = Bisu::Localizer.new(dictionary, config.type)
|
25
25
|
|
26
|
-
config.localize_files do |in_path, out_path, language,
|
26
|
+
config.localize_files do |in_path, out_path, locale, language, fallback_language|
|
27
27
|
unless dictionary.has_language?(language)
|
28
28
|
Logger.error("Unknown language #{language}")
|
29
29
|
return false
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
fallback_languages = ([fallback_language] + [options[:default_language]]).compact
|
33
|
+
|
34
|
+
localize_file(localizer, locale, language, fallback_languages, in_path, out_path)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
@@ -131,14 +133,14 @@ module Bisu
|
|
131
133
|
File.open(File.expand_path(file_name), method)
|
132
134
|
end
|
133
135
|
|
134
|
-
def localize_file(localizer, locale, language,
|
136
|
+
def localize_file(localizer, locale, language, fallback_languages, in_path, out_path)
|
135
137
|
Logger.info("Translating #{in_path} to #{language} > #{out_path}...")
|
136
138
|
|
137
139
|
return false unless in_file = open_file(in_path, "r", true)
|
138
140
|
return false unless out_file = open_file(out_path, "w", false)
|
139
141
|
|
140
142
|
in_file.each_line do |line|
|
141
|
-
out_file.write(localizer.localize(line, language, locale,
|
143
|
+
out_file.write(localizer.localize(line, language, locale, fallback_languages))
|
142
144
|
end
|
143
145
|
|
144
146
|
out_file.flush
|
data/lib/bisu/config.rb
CHANGED
@@ -27,7 +27,7 @@ module Bisu
|
|
27
27
|
@hash[:translate].each do |t|
|
28
28
|
@hash[:languages].each do |l|
|
29
29
|
downcase_locale = l[:locale].downcase.gsub("-", "_").gsub(" ", "_")
|
30
|
-
yield(t[:in], (t[:"out_#{downcase_locale}"] || t[:out]) % l, l[:language], l[:
|
30
|
+
yield(t[:in], (t[:"out_#{downcase_locale}"] || t[:out]) % l, l[:locale], l[:language], l[:fallback_language])
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -50,7 +50,8 @@ module Bisu
|
|
50
50
|
languages: { type: Array, elements: {
|
51
51
|
type: Hash, elements: {
|
52
52
|
locale: { type: String },
|
53
|
-
language: { type: String }
|
53
|
+
language: { type: String },
|
54
|
+
fallback_language: { type: String, optional: true }
|
54
55
|
}
|
55
56
|
} }
|
56
57
|
}
|
data/lib/bisu/localizer.rb
CHANGED
@@ -10,7 +10,7 @@ module Bisu
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def localize(text, language, locale,
|
13
|
+
def localize(text, language, locale, fallback_languages=[])
|
14
14
|
t = text
|
15
15
|
t = t.gsub("$specialKLanguage$", language)
|
16
16
|
t = t.gsub("$specialKLocale$", locale)
|
@@ -18,7 +18,7 @@ module Bisu
|
|
18
18
|
t = t.gsub("$specialKComment2$", "Remember to CHANGE THE TEMPLATE and not this file!")
|
19
19
|
|
20
20
|
to_localize(t).map do |l|
|
21
|
-
if localized =
|
21
|
+
if localized = localize_key(l[:key], [language] + fallback_languages)
|
22
22
|
localized = process(localized)
|
23
23
|
|
24
24
|
l[:params].each do |param, value|
|
@@ -44,6 +44,16 @@ module Bisu
|
|
44
44
|
t
|
45
45
|
end
|
46
46
|
|
47
|
+
def localize_key(key, ordered_languages)
|
48
|
+
ordered_languages.each do |language|
|
49
|
+
if localized = @dict.localize(language, key)
|
50
|
+
return localized
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
47
57
|
private
|
48
58
|
|
49
59
|
def to_localize(text)
|
data/lib/bisu/version.rb
CHANGED
@@ -22,7 +22,7 @@ describe Bisu::Config do
|
|
22
22
|
{ locale: "en-US", language: "english" },
|
23
23
|
{ locale: "pt", language: "portuguese" },
|
24
24
|
{ locale: "pt-PT", language: "portuguese" },
|
25
|
-
{ locale: "pt-Batatas", language: "portuguese" }
|
25
|
+
{ locale: "pt-Batatas", language: "portuguese-bt", fallback_language: "portuguese" }
|
26
26
|
]
|
27
27
|
} }
|
28
28
|
|
@@ -75,14 +75,14 @@ describe Bisu::Config do
|
|
75
75
|
expect { |b|
|
76
76
|
config.localize_files(&b)
|
77
77
|
}.to yield_successive_args(
|
78
|
-
["path/to/file/to/1.ext.translatable", "path/to/default/1.ext", "
|
79
|
-
["path/to/file/to/1.ext.translatable", "path/to/final-pt/1.ext", "
|
80
|
-
["path/to/file/to/1.ext.translatable", "path/to/final-pt-PT/1.ext", "
|
81
|
-
["path/to/file/to/1.ext.translatable", "path/to/final-pt-Batatas/1.ext", "
|
82
|
-
["path/to/file/to/2.ext.translatable", "path/to/default/2.ext", "
|
83
|
-
["path/to/file/to/2.ext.translatable", "path/to/final-pt/2.ext", "
|
84
|
-
["path/to/file/to/2.ext.translatable", "path/to/final-pt-PT/2.ext", "
|
85
|
-
["path/to/file/to/2.ext.translatable", "path/to/final-pt-Batatas/2.ext", "
|
78
|
+
["path/to/file/to/1.ext.translatable", "path/to/default/1.ext", "en-US", "english", nil ],
|
79
|
+
["path/to/file/to/1.ext.translatable", "path/to/final-pt/1.ext", "pt", "portuguese", nil ],
|
80
|
+
["path/to/file/to/1.ext.translatable", "path/to/final-pt-PT/1.ext", "pt-PT", "portuguese", nil ],
|
81
|
+
["path/to/file/to/1.ext.translatable", "path/to/final-pt-Batatas/1.ext", "pt-Batatas", "portuguese-bt", "portuguese"],
|
82
|
+
["path/to/file/to/2.ext.translatable", "path/to/default/2.ext", "en-US", "english", nil ],
|
83
|
+
["path/to/file/to/2.ext.translatable", "path/to/final-pt/2.ext", "pt", "portuguese", nil ],
|
84
|
+
["path/to/file/to/2.ext.translatable", "path/to/final-pt-PT/2.ext", "pt-PT", "portuguese", nil ],
|
85
|
+
["path/to/file/to/2.ext.translatable", "path/to/final-pt-Batatas/2.ext", "pt-Batatas", "portuguese-bt", "portuguese"]
|
86
86
|
)
|
87
87
|
end
|
88
88
|
end
|
@@ -19,6 +19,9 @@ describe Bisu::Localizer do
|
|
19
19
|
"kAtSign" => "\@johnsnow sabes alguma coisa?",
|
20
20
|
"kPercentage" => "Sabes 0% João das Neves."
|
21
21
|
},
|
22
|
+
"Spanish" => {
|
23
|
+
"kMissingTransKey" => "Sabes poco John Snow"
|
24
|
+
},
|
22
25
|
"English" => {
|
23
26
|
"kMissingTransKey" => "You know little John Snow"
|
24
27
|
}
|
@@ -30,8 +33,8 @@ describe Bisu::Localizer do
|
|
30
33
|
shared_examples_for "a localizer" do
|
31
34
|
it { expect { localizer }.not_to raise_error }
|
32
35
|
|
33
|
-
def translates(text,
|
34
|
-
translation = localizer.localize(text, lang || language, locale,
|
36
|
+
def translates(text, fallbacks: [], to:, lang: nil)
|
37
|
+
translation = localizer.localize(text, lang || language, locale, fallbacks)
|
35
38
|
expect(translation).to eq to
|
36
39
|
end
|
37
40
|
|
@@ -46,7 +49,8 @@ describe Bisu::Localizer do
|
|
46
49
|
it { translates("this key: $kTranslationKey$", to: "this key: Não sabes nada João das Neves", lang: "portuguese") }
|
47
50
|
it { translates("this unknown key: $kUnknownKey$", to: "this unknown key: $kUnknownKey$") }
|
48
51
|
it { translates("this key with missing translations: $kMissingTransKey$", to: "this key with missing translations: $kMissingTransKey$") }
|
49
|
-
it { translates("this key with missing translations: $kMissingTransKey$",
|
52
|
+
it { translates("this key with missing translations: $kMissingTransKey$", fallbacks: ["English"], to: "this key with missing translations: You know little John Snow") }
|
53
|
+
it { translates("this key with missing translations: $kMissingTransKey$", fallbacks: ["Spanish", "English"], to: "this key with missing translations: Sabes poco John Snow") }
|
50
54
|
it { translates("these 2 keys: $kTranslationKey$, $kTranslationKey2$", to: "these 2 keys: Não sabes nada João das Neves, Naaada!") }
|
51
55
|
|
52
56
|
it { translates("1 parameter: $k1ParameterKey$", to: "1 parameter: Não sabes nada %{name}") }
|
data/spec/lib/bisu_spec.rb
CHANGED
@@ -7,7 +7,8 @@ describe Bisu do
|
|
7
7
|
before do
|
8
8
|
allow(Bisu).to receive(:open_file).and_return(file)
|
9
9
|
allow_any_instance_of(Bisu::Source::GoogleSheet).to receive(:to_i18).and_return({
|
10
|
-
"english" => { "kKey" => "Value" }
|
10
|
+
"english" => { "kKey" => "Value" },
|
11
|
+
"english-us" => { "kKey" => "Value" }
|
11
12
|
})
|
12
13
|
allow(Bisu).to receive(:localize_file)
|
13
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bisu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joaoffcosta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: safe_yaml
|