bisu 1.7.0 → 1.9.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 +5 -5
- data/.rspec +0 -1
- data/.ruby-version +1 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +30 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +26 -21
- data/README.md +46 -18
- data/README_explanation.png +0 -0
- data/Rakefile +6 -5
- data/lib/bisu.rb +6 -4
- data/lib/bisu/config.rb +3 -2
- data/lib/bisu/localizer.rb +28 -9
- 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 +63 -11
- data/spec/lib/bisu/source/one_sky_spec.rb +1 -1
- data/spec/lib/bisu_spec.rb +2 -1
- metadata +6 -5
- data/.gitignore +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 14ce8b0b059747d79f5a63fc910129774a634d015bf02563ac888dc80c735ed0
|
4
|
+
data.tar.gz: 5158d8f04815351d0850c52d948a2dcebb5bb267a8154e716c31d01334fdd379
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2773ab4e5ea6f8b0f419650e2cd4f551dacfb43d438e892a98bb9ca317774a82c61122ad232de1cd1ede184178ac502352bc356702144b70f73b7912a23adcba
|
7
|
+
data.tar.gz: 1bae10ebc6fb6a915d2c2122b4ceff3341b426eb47543b9e1502242e47804aa9599ef3c22f4abd62b915177d83d4a0b6a3cf08f8e7fa4aaa5ae505a8c3538429
|
data/.rspec
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.3
|
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
language: ruby
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,36 @@
|
|
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.9.0](https://github.com/hole19/bisu/releases/tag/v1.9.0)
|
6
|
+
Released on 2021/05/21
|
7
|
+
|
8
|
+
#### Added
|
9
|
+
- Adds a new option to surpress missing params when that's intentional: add "//ignore-params" to the end of the translation key
|
10
|
+
|
11
|
+
## [1.8.0](https://github.com/hole19/bisu/releases/tag/v1.8.0)
|
12
|
+
Released on 2020/04/30
|
13
|
+
|
14
|
+
#### Added
|
15
|
+
- Adds a new option: allows a single translation to have a specific fallback language (example: "es-MX" fallback to "es")
|
16
|
+
|
17
|
+
## [1.7.3](https://github.com/hole19/bisu/releases/tag/v1.7.3)
|
18
|
+
Released on 2020/03/09
|
19
|
+
|
20
|
+
#### Added
|
21
|
+
- Correctly handles percentage sign on iOS platform
|
22
|
+
|
23
|
+
## [1.7.2](https://github.com/hole19/bisu/releases/tag/v1.7.2)
|
24
|
+
Released on 2020/03/09
|
25
|
+
|
26
|
+
#### Added
|
27
|
+
- Correctly handles percentage sign on Android platform
|
28
|
+
|
29
|
+
## [1.7.1](https://github.com/hole19/bisu/releases/tag/v1.7.1)
|
30
|
+
Released on 2019/03/04
|
31
|
+
|
32
|
+
#### Added
|
33
|
+
- Applies the same new line behaviour in every platform
|
34
|
+
|
5
35
|
## [1.7.0](https://github.com/hole19/bisu/releases/tag/v1.7.0)
|
6
36
|
Released on 2019/02/18
|
7
37
|
|
data/Gemfile
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
-
ruby '2.3
|
2
|
+
ruby '2.7.3'
|
3
3
|
|
4
4
|
gem 'safe_yaml', '~> 1.0'
|
5
5
|
gem 'colorize', '~> 0.7'
|
6
6
|
gem 'xml-simple', '~> 1.1'
|
7
7
|
|
8
|
-
|
9
|
-
gem '
|
10
|
-
gem '
|
8
|
+
group :test do
|
9
|
+
gem 'rake'
|
10
|
+
gem 'webmock', '~> 1.20'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rspec-its'
|
13
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,40 +1,45 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.
|
4
|
+
addressable (2.7.0)
|
5
|
+
public_suffix (>= 2.0.2, < 5.0)
|
5
6
|
colorize (0.8.1)
|
6
|
-
crack (0.4.
|
7
|
-
|
8
|
-
diff-lcs (1.
|
9
|
-
hashdiff (0.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
rspec-
|
16
|
-
|
7
|
+
crack (0.4.5)
|
8
|
+
rexml
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
hashdiff (1.0.1)
|
11
|
+
public_suffix (4.0.6)
|
12
|
+
rake (13.0.3)
|
13
|
+
rexml (3.2.5)
|
14
|
+
rspec (3.10.0)
|
15
|
+
rspec-core (~> 3.10.0)
|
16
|
+
rspec-expectations (~> 3.10.0)
|
17
|
+
rspec-mocks (~> 3.10.0)
|
18
|
+
rspec-core (3.10.1)
|
19
|
+
rspec-support (~> 3.10.0)
|
20
|
+
rspec-expectations (3.10.1)
|
17
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
18
|
-
rspec-support (~> 3.
|
19
|
-
rspec-its (1.
|
22
|
+
rspec-support (~> 3.10.0)
|
23
|
+
rspec-its (1.3.0)
|
20
24
|
rspec-core (>= 3.0.0)
|
21
25
|
rspec-expectations (>= 3.0.0)
|
22
|
-
rspec-mocks (3.
|
26
|
+
rspec-mocks (3.10.2)
|
23
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
-
rspec-support (~> 3.
|
25
|
-
rspec-support (3.
|
26
|
-
safe_yaml (1.0.
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-support (3.10.2)
|
30
|
+
safe_yaml (1.0.5)
|
27
31
|
webmock (1.24.6)
|
28
32
|
addressable (>= 2.3.6)
|
29
33
|
crack (>= 0.3.2)
|
30
34
|
hashdiff
|
31
|
-
xml-simple (1.1.
|
35
|
+
xml-simple (1.1.8)
|
32
36
|
|
33
37
|
PLATFORMS
|
34
38
|
ruby
|
35
39
|
|
36
40
|
DEPENDENCIES
|
37
41
|
colorize (~> 0.7)
|
42
|
+
rake
|
38
43
|
rspec
|
39
44
|
rspec-its
|
40
45
|
safe_yaml (~> 1.0)
|
@@ -42,7 +47,7 @@ DEPENDENCIES
|
|
42
47
|
xml-simple (~> 1.1)
|
43
48
|
|
44
49
|
RUBY VERSION
|
45
|
-
ruby 2.
|
50
|
+
ruby 2.7.3p183
|
46
51
|
|
47
52
|
BUNDLED WITH
|
48
|
-
1.
|
53
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
Bisu 홀
|
2
2
|
========
|
3
3
|
|
4
|
+
[](https://travis-ci.org/hole19/bisu?branch=master)
|
5
|
+
[](http://rubygems.org/gems/bisu "View this project in Rubygems")
|
6
|
+
|
4
7
|
Bisu manages your app iOS, Android and RoR localization files for you. No more copy+paste induced errors!
|
5
8
|
|
6
|
-
|
9
|
+
<p align="center">
|
10
|
+
<img src="https://raw.githubusercontent.com/hole19/bisu/master/README_explanation.png" width="500">
|
11
|
+
</p>
|
7
12
|
|
8
13
|
Instalation
|
9
14
|
-----
|
@@ -19,9 +24,9 @@ Usage
|
|
19
24
|
1. Run: `bisu`
|
20
25
|
1. That's it!*
|
21
26
|
|
22
|
-
|
27
|
+
\*_given that someone already configured Bisu_
|
23
28
|
|
24
|
-
|
29
|
+
Setup your configuration file
|
25
30
|
-----
|
26
31
|
|
27
32
|
1. Create in your project base folder a translatable.yml:
|
@@ -30,9 +35,7 @@ Configuration
|
|
30
35
|
type: <iOS|Android|RoR>
|
31
36
|
|
32
37
|
dictionary:
|
33
|
-
|
34
|
-
sheet_id: <GOOGLE-DRIVE-SHEET-ID>
|
35
|
-
keys_column: <GOOGLE-DRIVE-KEY-COLUMN-TITLE>
|
38
|
+
(see options below)
|
36
39
|
|
37
40
|
translate:
|
38
41
|
- in: path/to/1st/file.translatable
|
@@ -42,22 +45,39 @@ Configuration
|
|
42
45
|
out: path/to/2nd-%{locale}/strings.xml
|
43
46
|
|
44
47
|
languages:
|
45
|
-
- locale:
|
46
|
-
language: en
|
47
|
-
- locale:
|
48
|
-
language: en
|
49
|
-
|
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
|
50
54
|
language: pt
|
51
55
|
```
|
52
56
|
|
53
|
-
|
57
|
+
##### Dictionary from a URL source:
|
58
|
+
|
54
59
|
```
|
55
60
|
dictionary:
|
56
61
|
type: url
|
57
62
|
url: <A-GET-URL>
|
58
63
|
```
|
59
64
|
|
60
|
-
|
65
|
+
##### Google Sheets Dictionary:
|
66
|
+
|
67
|
+
1. First ["Publish to the web"](https://www.google.com/search?q=google+sheets+publish+to+web) your Google Sheet
|
68
|
+
1. Share only the sheet that contains the translations
|
69
|
+
1. First column should contain the translation keys
|
70
|
+
1. First row should contain the locale for each language
|
71
|
+
|
72
|
+
```
|
73
|
+
dictionary:
|
74
|
+
type: google_sheet
|
75
|
+
sheet_id: <GOOGLE-DRIVE-SHEET-ID>
|
76
|
+
keys_column: <GOOGLE-DRIVE-KEY-COLUMN-TITLE>
|
77
|
+
```
|
78
|
+
|
79
|
+
##### OneSky integration:
|
80
|
+
|
61
81
|
```
|
62
82
|
dictionary:
|
63
83
|
type: one_sky
|
@@ -67,7 +87,13 @@ Configuration
|
|
67
87
|
file_name: <ONE-SKY-FILE-NAME>
|
68
88
|
```
|
69
89
|
|
70
|
-
|
90
|
+
Create translation templates
|
91
|
+
-----
|
92
|
+
|
93
|
+
Create a \*.translatable version for your platform specific localization files:
|
94
|
+
|
95
|
+
##### iOS
|
96
|
+
*example: Localizable.strings.translatable*
|
71
97
|
|
72
98
|
```
|
73
99
|
// $specialKComment1$
|
@@ -82,10 +108,11 @@ Configuration
|
|
82
108
|
"klGeneral_Delete" = "$kDelete$";
|
83
109
|
"klGeneral_Cancel" = "$kCancel$";
|
84
110
|
"klGeneral_Close" = "$kClose$";
|
85
|
-
"klRequestName" = "$kRequestName
|
111
|
+
"klRequestName" = "$kRequestName{user_name: %@}$";
|
86
112
|
```
|
87
113
|
|
88
|
-
|
114
|
+
##### Android
|
115
|
+
*example: strings.xml.translatable*
|
89
116
|
|
90
117
|
```
|
91
118
|
<?xml version="1.0" encoding="utf-8"?>
|
@@ -98,11 +125,12 @@ Configuration
|
|
98
125
|
<string name="delete">$kDelete$</string>
|
99
126
|
<string name="cancel">$kCancel$</string>
|
100
127
|
<string name="close">$kClose$</string>
|
101
|
-
<string name="request_name">$kRequestName
|
128
|
+
<string name="request_name">$kRequestName{user_name: %s}$</string>
|
102
129
|
</resources>
|
103
130
|
```
|
104
131
|
|
105
|
-
|
132
|
+
##### Ruby on Rails
|
133
|
+
*example: config/locales/yml.translatable*
|
106
134
|
|
107
135
|
```
|
108
136
|
$specialKLocale$:
|
Binary file
|
data/Rakefile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "rake"
|
2
|
+
require "rspec/core/rake_task"
|
2
3
|
|
3
|
-
|
4
|
-
t.
|
4
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
5
|
+
t.pattern = Dir.glob("spec/**/*_spec.rb")
|
6
|
+
t.rspec_opts = "--format documentation"
|
5
7
|
end
|
6
8
|
|
7
|
-
|
8
|
-
task :default => :test
|
9
|
+
task default: :spec
|
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,9 @@ 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
|
+
localized = process(localized)
|
23
|
+
|
22
24
|
l[:params].each do |param, value|
|
23
25
|
if localized.match("%{#{param}}")
|
24
26
|
localized = localized.gsub("%{#{param}}", value)
|
@@ -27,25 +29,35 @@ module Bisu
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
unless t.gsub!(l[:match],
|
32
|
+
unless t.gsub!(l[:match], localized)
|
31
33
|
Logger.warn("Could not find translation for #{l[:match]} in #{language}")
|
32
34
|
end
|
35
|
+
|
36
|
+
unless @type.eql?(:ror) || l[:ignore_param_warn] == true
|
37
|
+
localized.scan(/%{[^}]+}/) { |match| Logger.error("Could not find translation param for #{match} in #{language}") }
|
38
|
+
end
|
33
39
|
else
|
34
40
|
Logger.warn("Could not find translation for #{l[:match]} in #{language}")
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
|
-
|
39
|
-
|
44
|
+
t
|
45
|
+
end
|
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
|
40
52
|
end
|
41
53
|
|
42
|
-
|
54
|
+
nil
|
43
55
|
end
|
44
56
|
|
45
57
|
private
|
46
58
|
|
47
59
|
def to_localize(text)
|
48
|
-
all_matches = text.to_enum(:scan, /\$([^\$\{]+)(?:\{(.+)\})?\$/).map { Regexp.last_match }
|
60
|
+
all_matches = text.to_enum(:scan, /\$([^\$\{\/]+)(?:\{(.+)\})?(\/\/ignore-params)?\$/).map { Regexp.last_match }
|
49
61
|
all_matches.map do |match|
|
50
62
|
params = if match[2]
|
51
63
|
params = match[2].split(",").map(&:strip).map do |param|
|
@@ -55,21 +67,28 @@ module Bisu
|
|
55
67
|
Hash[params]
|
56
68
|
end
|
57
69
|
|
58
|
-
{
|
70
|
+
{
|
71
|
+
match: match[0],
|
59
72
|
key: match[1],
|
60
|
-
params: params || {}
|
73
|
+
params: params || {},
|
74
|
+
ignore_param_warn: text.include?("//ignore-params")
|
75
|
+
}
|
61
76
|
end
|
62
77
|
end
|
63
78
|
|
64
79
|
def process(text)
|
80
|
+
text = text.gsub("\n", "\\n")
|
81
|
+
|
65
82
|
if @type.eql?(:android)
|
66
83
|
text = text.gsub(/[']/, "\\\\\\\\'")
|
67
84
|
text = text.gsub("...", "…")
|
68
85
|
text = text.gsub("& ", "& ")
|
69
86
|
text = text.gsub("@", "\\\\@")
|
87
|
+
text = text.gsub(/%(?!{)/, "\\\\%%")
|
70
88
|
|
71
89
|
elsif @type.eql?(:ios)
|
72
90
|
text = text.gsub(/\"/, "\\\\\"")
|
91
|
+
text = text.gsub(/%(?!{)/, "%%")
|
73
92
|
end
|
74
93
|
|
75
94
|
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
|
@@ -1,4 +1,9 @@
|
|
1
1
|
describe Bisu::Localizer do
|
2
|
+
def translates(text, fallbacks: [], to:, lang: nil)
|
3
|
+
translation = localizer.localize(text, lang || language, locale, fallbacks)
|
4
|
+
expect(translation).to eq to
|
5
|
+
end
|
6
|
+
|
2
7
|
let(:language) { "Portuguese" }
|
3
8
|
let(:locale) { "pt-PT" }
|
4
9
|
|
@@ -8,13 +13,19 @@ describe Bisu::Localizer do
|
|
8
13
|
"kTranslationKey2" => "Naaada!",
|
9
14
|
"k1ParameterKey" => "Não sabes nada %{name}",
|
10
15
|
"k2ParametersKey" => "Sabes %{perc} por cento %{name}",
|
16
|
+
"kNewLineSingle" => "Não sabes nada\nJoão das Neves",
|
17
|
+
"kNewLineMultiple" => "Não sabes nada\\nJoão das Neves",
|
11
18
|
|
12
19
|
# type dependent translations
|
13
20
|
"kDoubleQuoted" => "Não sabes nada \"João das Neves\"",
|
14
21
|
"kSingleQuoted" => "Não sabes nada 'João das Neves'",
|
15
22
|
"kEllipsis" => "Não sabes nada João das Neves...",
|
16
23
|
"kAmpersand" => "Não sabes nada João das Neves & Pícaros",
|
17
|
-
"kAtSign" => "\@johnsnow sabes alguma coisa?"
|
24
|
+
"kAtSign" => "\@johnsnow sabes alguma coisa?",
|
25
|
+
"kPercentage" => "Sabes 0% João das Neves."
|
26
|
+
},
|
27
|
+
"Spanish" => {
|
28
|
+
"kMissingTransKey" => "Sabes poco John Snow"
|
18
29
|
},
|
19
30
|
"English" => {
|
20
31
|
"kMissingTransKey" => "You know little John Snow"
|
@@ -27,11 +38,6 @@ describe Bisu::Localizer do
|
|
27
38
|
shared_examples_for "a localizer" do
|
28
39
|
it { expect { localizer }.not_to raise_error }
|
29
40
|
|
30
|
-
def translates(text, fallback: nil, to:, lang: nil)
|
31
|
-
translation = localizer.localize(text, lang || language, locale, fallback)
|
32
|
-
expect(translation).to eq to
|
33
|
-
end
|
34
|
-
|
35
41
|
it { translates("a line with no key", to: "a line with no key") }
|
36
42
|
|
37
43
|
it { translates("this special key: $specialKComment1$", to: "this special key: This file was automatically generated based on a translation template.") }
|
@@ -43,7 +49,8 @@ describe Bisu::Localizer do
|
|
43
49
|
it { translates("this key: $kTranslationKey$", to: "this key: Não sabes nada João das Neves", lang: "portuguese") }
|
44
50
|
it { translates("this unknown key: $kUnknownKey$", to: "this unknown key: $kUnknownKey$") }
|
45
51
|
it { translates("this key with missing translations: $kMissingTransKey$", to: "this key with missing translations: $kMissingTransKey$") }
|
46
|
-
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") }
|
47
54
|
it { translates("these 2 keys: $kTranslationKey$, $kTranslationKey2$", to: "these 2 keys: Não sabes nada João das Neves, Naaada!") }
|
48
55
|
|
49
56
|
it { translates("1 parameter: $k1ParameterKey$", to: "1 parameter: Não sabes nada %{name}") }
|
@@ -52,6 +59,9 @@ describe Bisu::Localizer do
|
|
52
59
|
it { translates("2 parameters: $k2ParametersKey{perc:%2$d, name:%1$s}$", to: "2 parameters: Sabes %2$d por cento %1$s") }
|
53
60
|
it { translates("2 parameters: $k2ParametersKey{name:%1$s, perc:%2$d}$", to: "2 parameters: Sabes %2$d por cento %1$s") }
|
54
61
|
|
62
|
+
it { translates("$kNewLineSingle$", to: "Não sabes nada\\nJoão das Neves") }
|
63
|
+
it { translates("$kNewLineMultiple$", to: "Não sabes nada\\nJoão das Neves") }
|
64
|
+
|
55
65
|
# type dependent translations
|
56
66
|
|
57
67
|
it { translates("$kDoubleQuoted$", to: expected[:double_quoted]) }
|
@@ -59,6 +69,7 @@ describe Bisu::Localizer do
|
|
59
69
|
it { translates("$kEllipsis$", to: expected[:ellipsis]) }
|
60
70
|
it { translates("$kAmpersand$", to: expected[:ampersand]) }
|
61
71
|
it { translates("$kAtSign$", to: expected[:at_sign]) }
|
72
|
+
it { translates("$kPercentage$", to: expected[:percentage]) }
|
62
73
|
|
63
74
|
# error handling
|
64
75
|
|
@@ -76,7 +87,7 @@ describe Bisu::Localizer do
|
|
76
87
|
.and not_change { Bisu::Logger.summary[:error] }
|
77
88
|
end
|
78
89
|
|
79
|
-
it "throws
|
90
|
+
it "throws a error when missing key parameters (expect on ruby on rails)" do
|
80
91
|
if type == :ror
|
81
92
|
expect {
|
82
93
|
localizer.localize("$k1ParameterKey$", language, locale)
|
@@ -103,6 +114,17 @@ describe Bisu::Localizer do
|
|
103
114
|
}.to not_change { Bisu::Logger.summary[:warn] }
|
104
115
|
.and change { Bisu::Logger.summary[:error] }.by(1)
|
105
116
|
end
|
117
|
+
|
118
|
+
# non localizable text with params
|
119
|
+
|
120
|
+
it "does not try to translate params outside $$" do
|
121
|
+
translates("%{some_text}", to: "%{some_text}")
|
122
|
+
|
123
|
+
expect {
|
124
|
+
localizer.localize("%{some_text}", language, locale)
|
125
|
+
}.to not_change { Bisu::Logger.summary[:warn] }
|
126
|
+
.and not_change { Bisu::Logger.summary[:error] }
|
127
|
+
end
|
106
128
|
end
|
107
129
|
|
108
130
|
let(:type_dependent_defaults) { {
|
@@ -110,17 +132,46 @@ describe Bisu::Localizer do
|
|
110
132
|
single_quoted: keys[language]["kSingleQuoted"],
|
111
133
|
ellipsis: keys[language]["kEllipsis"],
|
112
134
|
ampersand: keys[language]["kAmpersand"],
|
113
|
-
at_sign: keys[language]["kAtSign"]
|
135
|
+
at_sign: keys[language]["kAtSign"],
|
136
|
+
percentage: keys[language]["kPercentage"]
|
114
137
|
} }
|
115
138
|
|
116
139
|
describe "of type iOS" do
|
117
140
|
let(:type) { :ios }
|
118
141
|
|
119
142
|
let(:expected) { type_dependent_defaults.merge(
|
120
|
-
double_quoted: "Não sabes nada \\\"João das Neves\\\""
|
143
|
+
double_quoted: "Não sabes nada \\\"João das Neves\\\"",
|
144
|
+
percentage: "Sabes 0%% João das Neves."
|
121
145
|
) }
|
122
146
|
|
123
147
|
it_behaves_like "a localizer"
|
148
|
+
|
149
|
+
context "when a parameter replacemnt was not defined" do
|
150
|
+
let(:line) { "1 parameter: $k1ParameterKey$" }
|
151
|
+
let(:expected) { "1 parameter: Não sabes nada %{name}" }
|
152
|
+
|
153
|
+
it { translates(line, to: expected) }
|
154
|
+
|
155
|
+
it "returns an error" do
|
156
|
+
expect {
|
157
|
+
localizer.localize(line, language, locale)
|
158
|
+
}.to not_change { Bisu::Logger.summary[:warn] }
|
159
|
+
.and change { Bisu::Logger.summary[:error] }.by(1)
|
160
|
+
end
|
161
|
+
|
162
|
+
context "when passing //ignore-params" do
|
163
|
+
let(:line) { "1 parameter: $k1ParameterKey//ignore-params$" }
|
164
|
+
|
165
|
+
it { translates(line, to: expected) }
|
166
|
+
|
167
|
+
it "does not return an error" do
|
168
|
+
expect {
|
169
|
+
localizer.localize(line, language, locale)
|
170
|
+
}.to not_change { Bisu::Logger.summary[:warn] }
|
171
|
+
.and not_change { Bisu::Logger.summary[:error] }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
124
175
|
end
|
125
176
|
|
126
177
|
describe "of type Android" do
|
@@ -130,7 +181,8 @@ describe Bisu::Localizer do
|
|
130
181
|
single_quoted: "Não sabes nada \\'João das Neves\\'",
|
131
182
|
ellipsis: "Não sabes nada João das Neves…",
|
132
183
|
ampersand: "Não sabes nada João das Neves & Pícaros",
|
133
|
-
at_sign: "\\@johnsnow sabes alguma coisa?"
|
184
|
+
at_sign: "\\@johnsnow sabes alguma coisa?",
|
185
|
+
percentage: "Sabes 0\\%% João das Neves."
|
134
186
|
) }
|
135
187
|
|
136
188
|
it_behaves_like "a localizer"
|
@@ -45,7 +45,7 @@ describe Bisu::Source::OneSky do
|
|
45
45
|
expect(to_i18).to eq({
|
46
46
|
"en" => {
|
47
47
|
"kRegularNewLine" => "This is the first line\\nthis is the second line",
|
48
|
-
"kErrorNewLine"
|
48
|
+
"kErrorNewLine" => "This is the first line\\nthis is the second line"
|
49
49
|
}
|
50
50
|
})
|
51
51
|
end
|
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.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joaoffcosta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: safe_yaml
|
@@ -74,12 +74,14 @@ executables:
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
-
- ".gitignore"
|
78
77
|
- ".rspec"
|
78
|
+
- ".ruby-version"
|
79
|
+
- ".travis.yml"
|
79
80
|
- CHANGELOG.md
|
80
81
|
- Gemfile
|
81
82
|
- Gemfile.lock
|
82
83
|
- README.md
|
84
|
+
- README_explanation.png
|
83
85
|
- Rakefile
|
84
86
|
- bin/bisu
|
85
87
|
- bisu.gemspec
|
@@ -129,8 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
131
|
- !ruby/object:Gem::Version
|
130
132
|
version: '0'
|
131
133
|
requirements: []
|
132
|
-
|
133
|
-
rubygems_version: 2.5.1
|
134
|
+
rubygems_version: 3.1.6
|
134
135
|
signing_key:
|
135
136
|
specification_version: 4
|
136
137
|
summary: A localization automation service
|
data/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
.ruby-version
|