ruby_native 0.15.0 → 0.15.3

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: e8d87be28530140900677b188eb358c7a1dedaa5966760494cd714d58f988017
4
- data.tar.gz: 6b2842f30c59244680a0b6a853d9c43617c33dda0cb1232089159fdc06fbf757
3
+ metadata.gz: 1be33272a96d8436b0384a2723f6661e349c873c8df954fadba80472bbfe565c
4
+ data.tar.gz: c547853c962c66b1c588185b54ca584ef2d9796fa735fcbe7ad560ba0644f159
5
5
  SHA512:
6
- metadata.gz: 79c71e7a97da93357aa8e927a41dbdd5742919dcfd9bdfddc7b2d0e215c37489bacfd6b3cdf77b2b1b86e13f0a081777830c732d0ebbacc52398a8026609ff05
7
- data.tar.gz: 1d5946a4083783f961363b05e61f3e3c62909d60c90108cc4e67594149a559fa62810507dd4720ea67fb9cb7e6c2a8c0e7198ed0593b0d7fdea140afc1145476
6
+ metadata.gz: 5dda4cf2375e87449b8e64e81c07fe02cf2d671fdea7182fafd7f34436674bb633ff7823a19c7e2efd7414ff888af17c7d646e9652437e807f0c67458dd97972
7
+ data.tar.gz: ba5e2c1ee978774a81e7292cf6cd7b8e96fba7f80820d81483f0c64721e478205afc4167de8a8bc7064d96fc908a194699f9ebe03a35c1c4bad9e1a9da1c2a8f
@@ -102,6 +102,23 @@ tabs:
102
102
 
103
103
  # Per-tab options (add to any tab above):
104
104
  #
105
+ # # Localize this tab's title. Put the copy in your app's own locale files
106
+ # # under `ruby_native.tabs.<key>.title`, the same way the error screen uses
107
+ # # `ruby_native.errors.*`, and the device's language picks the translation:
108
+ # #
109
+ # # # config/locales/it.yml
110
+ # # it:
111
+ # # ruby_native:
112
+ # # tabs:
113
+ # # home:
114
+ # # title: Casa
115
+ # #
116
+ # # `title:` above stays the fallback for a language you have not
117
+ # # translated. Once every tab has a key you can drop `title:` entirely and
118
+ # # keep all of your copy in the locale files.
119
+ # # https://rubynative.com/docs/tabs#localization
120
+ # key: home
121
+ #
105
122
  # # Load this tab on launch instead of lazily.
106
123
  # # Default: false.
107
124
  # eager: true
@@ -1,3 +1,3 @@
1
1
  module RubyNative
2
- VERSION = "0.15.0"
2
+ VERSION = "0.15.3"
3
3
  end
data/lib/ruby_native.rb CHANGED
@@ -62,6 +62,7 @@ module RubyNative
62
62
  normalize_linked_paths
63
63
  backfill_tab_icons
64
64
  backfill_error_icons
65
+ warn_on_duplicate_tab_keys
65
66
  end
66
67
 
67
68
  # config/ruby_native.yml is rendered as ERB before it is parsed, so a
@@ -95,6 +96,21 @@ module RubyNative
95
96
  end
96
97
  end
97
98
 
99
+ # A tab's `key` names its copy in the host app's locale files, so two tabs
100
+ # sharing one read the same translations and one of them is always
101
+ # mislabeled. Warn rather than raise: both tabs still render, and a typo in
102
+ # the config should never take down boot.
103
+ def self.warn_on_duplicate_tab_keys
104
+ keys = Array(self.config[:tabs]).filter_map { |tab| tab[:key] if tab.is_a?(Hash) }
105
+ duplicates = keys.tally.select { |_, count| count > 1 }.keys
106
+ return if duplicates.empty?
107
+
108
+ Rails.logger.warn(
109
+ "[RubyNative] Duplicate tab key(s) in config/ruby_native.yml " \
110
+ "(#{duplicates.join(", ")}). Each tab needs its own key, or they share a title."
111
+ )
112
+ end
113
+
98
114
  # Mirrors `backfill_tab_icons` for the error screen: fills a state's flat
99
115
  # `icon` from its per-platform `icons` (ios first, then android), so the iOS
100
116
  # app, which reads only the flat `icon`, still renders one. An explicit
@@ -131,6 +147,10 @@ module RubyNative
131
147
  return config if config.nil?
132
148
 
133
149
  payload = config.deep_dup
150
+ # Shipped app binaries have required the `appearance` key at decode; keep
151
+ # emitting it so they still boot when the YAML omits the block.
152
+ payload[:appearance] ||= {}
153
+ localize_tab_titles(payload[:tabs])
134
154
  errors = error_screen_config(payload[:errors])
135
155
  if errors.empty?
136
156
  payload.delete(:errors)
@@ -140,6 +160,51 @@ module RubyNative
140
160
  payload
141
161
  end
142
162
 
163
+ # Fills each tab's `titles` from `ruby_native.tabs.<key>.title` in the host
164
+ # app's locale files, mirroring the `ruby_native.errors.*` namespace. The map
165
+ # is emitted beside the flat `title` rather than replacing it, the same
166
+ # additive shape as `icon`/`icons`: both platforms decode `title` as a plain
167
+ # String, so an app that does not read `titles` yet keeps rendering the YAML
168
+ # copy. Tabs without a `key` are left exactly as authored.
169
+ #
170
+ # `title:` is optional in the YAML so a localized app can keep all of its copy
171
+ # in locale files, but it is never optional on the wire: both platforms decode
172
+ # it as a required, non-optional String, so a tab missing one fails the whole
173
+ # config decode and drops the user on the error screen. Fill it from the
174
+ # default locale, then from any locale that was translated.
175
+ def self.localize_tab_titles(tabs)
176
+ Array(tabs).each do |tab|
177
+ next unless tab.is_a?(Hash)
178
+
179
+ key = tab[:key].to_s
180
+ titles = key.empty? ? {} : translations_for("tabs.#{key}.title")
181
+ tab[:titles] = titles unless titles.empty?
182
+ next unless tab[:title].to_s.empty?
183
+
184
+ tab[:title] = titles[I18n.default_locale] || titles.values.first || fallback_tab_title(key)
185
+ end
186
+ end
187
+
188
+ # Reached only when a tab has no `title:` and no translation in any locale,
189
+ # which would otherwise serve a payload that cannot decode. Names the tab
190
+ # after its key ("order_history" -> "Order history") so the bar still renders
191
+ # something recognizable, and says so, since the copy is missing everywhere.
192
+ def self.fallback_tab_title(key)
193
+ if key.empty?
194
+ Rails.logger.warn(
195
+ "[RubyNative] A tab in config/ruby_native.yml has no `title:`. Give it one, or a `key:` " \
196
+ "with copy under `ruby_native.tabs.<key>.title` in your locale files."
197
+ )
198
+ return "Untitled"
199
+ end
200
+
201
+ Rails.logger.warn(
202
+ "[RubyNative] Tab #{key.inspect} in config/ruby_native.yml has no `title:` and no " \
203
+ "`ruby_native.tabs.#{key}.title` translation in any locale. Falling back to a title from the key."
204
+ )
205
+ key.humanize
206
+ end
207
+
143
208
  # Merges per-state error-screen icons (from YAML) with localized copy (from
144
209
  # I18n) into the shape the native apps decode. Omits any state with neither an
145
210
  # icon nor copy, so an untouched app sends no `errors` block at all.
@@ -152,7 +217,7 @@ module RubyNative
152
217
  entry[:icons] = state_config[:icons] if state_config[:icons]
153
218
  end
154
219
  ERROR_SCREEN_COPY_KEYS.each do |key|
155
- translations = error_screen_translations("#{state}.#{key}")
220
+ translations = translations_for("errors.#{state}.#{key}")
156
221
  entry[key] = translations unless translations.empty?
157
222
  end
158
223
  result[state] = entry unless entry.empty?
@@ -160,17 +225,17 @@ module RubyNative
160
225
 
161
226
  # The Retry button label is shared by both states, so it sits at the top of
162
227
  # the block rather than under a state.
163
- retry_label = error_screen_translations("retry")
228
+ retry_label = translations_for("errors.retry")
164
229
  config[:retry] = retry_label unless retry_label.empty?
165
230
  config
166
231
  end
167
232
 
168
- # Reads `ruby_native.errors.<subkey>` for every available locale, keeping only
169
- # the locales the developer actually translated. Copy lives in the host app's
170
- # own locale files; the gem ships none.
171
- def self.error_screen_translations(subkey)
233
+ # Reads `ruby_native.<subkey>` for every available locale, keeping only the
234
+ # locales the developer actually translated. Copy lives in the host app's own
235
+ # locale files; the gem ships none.
236
+ def self.translations_for(subkey)
172
237
  I18n.available_locales.each_with_object({}) do |locale, result|
173
- value = I18n.t("ruby_native.errors.#{subkey}", locale: locale, default: nil)
238
+ value = I18n.t("ruby_native.#{subkey}", locale: locale, default: nil)
174
239
  result[locale] = value unless value.nil?
175
240
  end
176
241
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Masilotti