bisu 2.0.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 668059c0670a554d5a7ab95f88ab90133a0d367eaa7e08bba2c2c5a9d5ed36cb
4
- data.tar.gz: fb276b9ef26e4941fb3264a366fbe9cc8404d0c296441afe5b294df652444e6d
3
+ metadata.gz: 899c9d0280deaab7991aa96efb8826d43e257e065c0330cbfe1d09a4fa0958a9
4
+ data.tar.gz: c81b5482f9d18af6b208f6bb3b57555063a7f1089fb3c926e53746c1d40f944a
5
5
  SHA512:
6
- metadata.gz: 2250bd0fd198197e78a399be3c519c97ef0700564932feb4de4821573cf5a886fd056d5992180f9d18691145dbc55a9bbffc4bfc44993d1e9d34643954c2b529
7
- data.tar.gz: 81e01705e4a8a3e4144b2d64f11d6f04c60d0a75fc50d05b1781b43cfb15f87351c3dab66092ae0b51507760046677efee7bc67c2f9cd7087823884a802318aa
6
+ metadata.gz: 868664d115f452bb84ee3e4ac7be0b4da6347e502ca80369a2c358d4cdf5fb244e3be61b04491dc3388c1ac1cd80a61a6b1b9ece50180504283351fc392ec279
7
+ data.tar.gz: eb74b6d8c230c0d5a584a3af88234b3517b2ae442113ff81e71cfc6ff57058eb16dab631360051f8cc66d9daa28934fcb5d62404c30af0d6cdce06f21f3453f7
data/CHANGELOG.md CHANGED
@@ -4,7 +4,15 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## [2.2.0](https://github.com/hole19/bisu/releases/tag/v2.2.0)
7
8
 
9
+ #### Fixed
10
+ - Escape double quotes (") on Android localization
11
+
12
+ ## [2.1.0](https://github.com/hole19/bisu/releases/tag/v2.1.0)
13
+
14
+ #### Fixed
15
+ - Fixes handling of % character on iOS localization
8
16
 
9
17
  ## [2.0.0](https://github.com/hole19/bisu/releases/tag/v2.0.0)
10
18
  Released on 2023/12/07
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bisu (1.10.2)
4
+ bisu (2.2.0)
5
5
  colorize
6
6
  rubyzip (>= 2.0.0)
7
7
  safe_yaml (>= 1.0.0)
data/README.md CHANGED
@@ -105,7 +105,7 @@ Setup your configuration file
105
105
  file_name: <ONE-SKY-FILE-NAME>
106
106
  ```
107
107
 
108
- Create translation templates
108
+ Create translatable file templates
109
109
  -----
110
110
 
111
111
  Create a \*.translatable version for your platform specific localization files:
@@ -114,19 +114,10 @@ Create a \*.translatable version for your platform specific localization files:
114
114
  *example: Localizable.strings.translatable*
115
115
 
116
116
  ```
117
- // $specialKComment1$
118
- // $specialKComment2$
119
-
120
- // Locale: $specialKLocale$; Language used: $specialKLanguage$
121
-
122
- /***********
123
- * General
124
- ************/
125
-
126
- "klGeneral_Delete" = "$kDelete$";
127
- "klGeneral_Cancel" = "$kCancel$";
128
- "klGeneral_Close" = "$kClose$";
129
- "klRequestName" = "$kRequestName{user_name: %@}$";
117
+ "delete" = "$general.delete$";
118
+ "cancel" = "$general.cancel$";
119
+ "close" = "$general.close$";
120
+ "requestName" = "$request.name{user_name: %@}$";
130
121
  ```
131
122
 
132
123
  ##### Android
@@ -135,15 +126,11 @@ Create a \*.translatable version for your platform specific localization files:
135
126
  ```
136
127
  <?xml version="1.0" encoding="utf-8"?>
137
128
 
138
- <!-- $specialKComment1$ -->
139
- <!-- $specialKComment2$ -->
140
- <!-- Locale: $specialKLocale$; Language used: $specialKLanguage$ -->
141
-
142
129
  <resources>
143
- <string name="delete">$kDelete$</string>
144
- <string name="cancel">$kCancel$</string>
145
- <string name="close">$kClose$</string>
146
- <string name="request_name">$kRequestName{user_name: %s}$</string>
130
+ <string name="delete">$general.delete$</string>
131
+ <string name="cancel">$general.cancel$</string>
132
+ <string name="close">$general.close$</string>
133
+ <string name="request_name">$request.name{user_name: %s}$</string>
147
134
  </resources>
148
135
  ```
149
136
 
@@ -153,9 +140,37 @@ Create a \*.translatable version for your platform specific localization files:
153
140
  ```
154
141
  $specialKLocale$:
155
142
  resources:
156
- delete: $kDelete$
157
- cancel: $kCancel$
158
- close: $kClose$
143
+ delete: $general.delete$
144
+ cancel: $general.cancel$
145
+ close: $general.close$
159
146
  messages:
160
- request_name: $kRequestName$
147
+ request_name: $request.name$
161
148
  ```
149
+
150
+ ### Translatable options
151
+
152
+ #### Parameters
153
+
154
+ Given a key with params such as "Missing ${attribute} value"
155
+ - `$some-key-with-params{param: %s}$`: `Missing $s value`
156
+ - `$some-key-with-params//ignore-params$`: `Missing ${attribute} value`
157
+
158
+ #### Formated strings (special characters)
159
+
160
+ ##### "%" character (iOS only)
161
+
162
+ When it should be localized as given such as "Perfect: 100 (%)"
163
+ - `$some-key-with-percentage$`: `Perfect: 100%`
164
+
165
+ When it should be localized as a formated string such as "Perfect: %{percentage} (%)"
166
+ - `$some-key-with-percentage{percentage: %d}//formatted-string$`: `Perfect: %d (%%)` (note the double `%`)
167
+
168
+ #### Locale (useful for Rails localization files)
169
+
170
+ - `$specialKLocale$`: the respective locale of this file
171
+ - `$specialKLanguage$`: the respective language on the translation platform
172
+
173
+ #### Special comments
174
+
175
+ - `$specialKComment1$`: `This file was automatically generated based on a translation template.`
176
+ - `$specialKComment2$`: `Remember to CHANGE THE TEMPLATE and not this file!`
@@ -19,7 +19,7 @@ module Bisu
19
19
 
20
20
  to_localize(t).map do |l|
21
21
  if localized = localize_key(l[:key], [language] + fallback_languages)
22
- localized = process(localized)
22
+ localized = process(localized, l[:is_formatted_string])
23
23
 
24
24
  l[:params].each do |param, value|
25
25
  if localized.match("%{#{param}}")
@@ -33,8 +33,8 @@ module Bisu
33
33
  Logger.warn("Could not find translation for #{l[:match]} in #{language}")
34
34
  end
35
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}") }
36
+ unless @type.eql?(:ror) || l[:ignore_params] == true
37
+ localized.scan(/%{[^}]+}/) { |match| Logger.error("Could not find translation param for #{match} for #{l[:key]} in #{language}") }
38
38
  end
39
39
  else
40
40
  Logger.warn("Could not find translation for #{l[:match]} in #{language}")
@@ -57,7 +57,7 @@ module Bisu
57
57
  private
58
58
 
59
59
  def to_localize(text)
60
- all_matches = text.to_enum(:scan, /\$([^\$\{\/]+)(?:\{(.+)\})?(\/\/ignore-params)?\$/).map { Regexp.last_match }
60
+ all_matches = text.to_enum(:scan, /\$([^\$\{\/]+)(?:\{(.+)\})?(\/\/[A-Za-z-]+)*\$/).map { Regexp.last_match }
61
61
  all_matches.map do |match|
62
62
  params = if match[2]
63
63
  params = match[2].split(",").map(&:strip).map do |param|
@@ -71,16 +71,18 @@ module Bisu
71
71
  match: match[0],
72
72
  key: match[1],
73
73
  params: params || {},
74
- ignore_param_warn: text.include?("//ignore-params")
74
+ ignore_params: text.include?("//ignore-params"),
75
+ is_formatted_string: text.include?("//formatted-string"),
75
76
  }
76
77
  end
77
78
  end
78
79
 
79
- def process(text)
80
+ def process(text, is_formatted_string)
80
81
  text = text.gsub("\n", "\\n")
81
82
 
82
83
  if @type.eql?(:android)
83
84
  text = text.gsub(/[']/, "\\\\\\\\'")
85
+ text = text.gsub(/\"/, "\\\\\"")
84
86
  text = text.gsub("...", "…")
85
87
  text = text.gsub("& ", "&amp; ")
86
88
  text = text.gsub("@", "\\\\@")
@@ -88,7 +90,7 @@ module Bisu
88
90
 
89
91
  elsif @type.eql?(:ios)
90
92
  text = text.gsub(/\"/, "\\\\\"")
91
- text = text.gsub(/%(?!{)/, "%%")
93
+ text = text.gsub(/%(?!{)/, "%%") if is_formatted_string
92
94
  end
93
95
 
94
96
  text
data/lib/bisu/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bisu
2
- VERSION = '2.0.0'
3
- VERSION_UPDATED_AT = '2023-12-07'
2
+ VERSION = '2.2.0'
3
+ VERSION_UPDATED_AT = '2024-02-23'
4
4
  end
@@ -66,10 +66,11 @@ describe Bisu::Localizer do
66
66
 
67
67
  it { translates("$kDoubleQuoted$", to: expected[:double_quoted]) }
68
68
  it { translates("$kSingleQuoted$", to: expected[:single_quoted]) }
69
- it { translates("$kEllipsis$", to: expected[:ellipsis]) }
70
- it { translates("$kAmpersand$", to: expected[:ampersand]) }
71
- it { translates("$kAtSign$", to: expected[:at_sign]) }
72
- it { translates("$kPercentage$", to: expected[:percentage]) }
69
+ it { translates("$kEllipsis$", to: expected[:ellipsis]) }
70
+ it { translates("$kAmpersand$", to: expected[:ampersand]) }
71
+ it { translates("$kAtSign$", to: expected[:at_sign]) }
72
+ it { translates("$kPercentage$", to: expected[:percentage]) }
73
+ it { translates("$kPercentage//formatted-string$", to: expected[:percentage_formatted]) }
73
74
 
74
75
  # error handling
75
76
 
@@ -130,10 +131,11 @@ describe Bisu::Localizer do
130
131
  let(:type_dependent_defaults) { {
131
132
  double_quoted: keys[language]["kDoubleQuoted"],
132
133
  single_quoted: keys[language]["kSingleQuoted"],
133
- ellipsis: keys[language]["kEllipsis"],
134
- ampersand: keys[language]["kAmpersand"],
135
- at_sign: keys[language]["kAtSign"],
136
- percentage: keys[language]["kPercentage"]
134
+ ellipsis: keys[language]["kEllipsis"],
135
+ ampersand: keys[language]["kAmpersand"],
136
+ at_sign: keys[language]["kAtSign"],
137
+ percentage: keys[language]["kPercentage"],
138
+ percentage_formatted: keys[language]["kPercentage"],
137
139
  } }
138
140
 
139
141
  describe "of type iOS" do
@@ -141,7 +143,8 @@ describe Bisu::Localizer do
141
143
 
142
144
  let(:expected) { type_dependent_defaults.merge(
143
145
  double_quoted: "Não sabes nada \\\"João das Neves\\\"",
144
- percentage: "Sabes 0%% João das Neves."
146
+ percentage: "Sabes 0% João das Neves.",
147
+ percentage_formatted: "Sabes 0%% João das Neves.",
145
148
  ) }
146
149
 
147
150
  it_behaves_like "a localizer"
@@ -179,10 +182,12 @@ describe Bisu::Localizer do
179
182
 
180
183
  let(:expected) { type_dependent_defaults.merge(
181
184
  single_quoted: "Não sabes nada \\'João das Neves\\'",
185
+ double_quoted: "Não sabes nada \\\"João das Neves\\\"",
182
186
  ellipsis: "Não sabes nada João das Neves…",
183
187
  ampersand: "Não sabes nada João das Neves &amp; Pícaros",
184
188
  at_sign: "\\@johnsnow sabes alguma coisa?",
185
- percentage: "Sabes 0\\%% João das Neves."
189
+ percentage: "Sabes 0\\%% João das Neves.",
190
+ percentage_formatted: "Sabes 0\\%% João das Neves.",
186
191
  ) }
187
192
 
188
193
  it_behaves_like "a localizer"
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: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - joaoffcosta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2024-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safe_yaml