@@ -55,12 +55,12 @@ class StringsdictHelper
5555 #
5656 # @param [String] path The path to the `.stringsdict` file.
5757 # @return [Hash] The parsed plist dictionary.
58- # @raise [RuntimeError ] If the file is missing or is not a plist dictionary.
58+ # @raise [FastlaneCore::Interface::FastlaneError ] If the file is missing or is not a plist dictionary.
5959 def self . read ( path :)
60- raise "Stringsdict file not found: #{ path } " unless File . exist? ( path )
60+ UI . user_error! ( "Stringsdict file not found: #{ path } " ) unless File . exist? ( path )
6161
6262 data = Plist . parse_xml ( path )
63- raise "Invalid stringsdict file (expected a plist dictionary at the root): #{ path } " unless data . is_a? ( Hash )
63+ UI . user_error! ( "Invalid stringsdict file (expected a plist dictionary at the root): #{ path } " ) unless data . is_a? ( Hash )
6464
6565 data
6666 end
@@ -84,7 +84,7 @@ def self.write(data:, path:)
8484 # source `.stringsdict` files.
8585 # @param [String] output_path The `.pot` file to write.
8686 # @return [Integer] The number of plural entries written.
87- # @raise [RuntimeError ] If two entries would produce the same `msgctxt`.
87+ # @raise [FastlaneCore::Interface::FastlaneError ] If two entries would produce the same `msgctxt`.
8888 def self . generate_pot ( stringsdict_paths :, output_path :)
8989 po = GetText ::PO . new
9090 po . order = :none
@@ -99,8 +99,8 @@ def self.generate_pot(stringsdict_paths:, output_path:)
9999 variables . each do |var_name , var_dict |
100100 context = context_for ( key : key , variable : var_name , single_variable : single )
101101 if seen_contexts . key? ( context )
102- raise "Duplicate translation context '#{ context } ' generated from `#{ path } ` (also produced by " \
103- "`#{ seen_contexts [ context ] } `). Stringsdict keys must be unique across the files being converted."
102+ UI . user_error! ( "Duplicate translation context '#{ context } ' generated from `#{ path } ` (also produced by " \
103+ "`#{ seen_contexts [ context ] } `). Stringsdict keys must be unique across the files being converted." )
104104 end
105105 seen_contexts [ context ] = path
106106 entries << build_pot_entry ( context : context , var_dict : var_dict , key : key , variable : var_name )
@@ -130,8 +130,8 @@ def self.generate_pot(stringsdict_paths:, output_path:)
130130 # @return [Array<String>] Contexts present in the template for which the
131131 # `.po` had no usable translation (filled from English as fallback).
132132 # @raise [PluralRules::UnknownLocaleError] If the locale has no mapping.
133- # @raise [RuntimeError ] If a translated entry's form count doesn't match
134- # the locale's expected plural-category count.
133+ # @raise [FastlaneCore::Interface::FastlaneError ] If a translated entry's form count
134+ # doesn't match the locale's expected plural-category count.
135135 def self . generate_stringsdict_from_po ( po_path :, template_path :, locale :, output_path :)
136136 template = read ( path : template_path )
137137 po = parse_po ( po_path )
@@ -205,8 +205,8 @@ def self.build_pot_entry(context:, var_dict:, key:, variable:)
205205 singular = var_dict [ 'one' ] || var_dict [ 'other' ]
206206 plural = var_dict [ 'other' ]
207207 if singular . nil? || plural . nil?
208- raise "Stringsdict entry '#{ key } ' is missing a required plural form " \
209- "(needs at least 'other'; 'one' recommended for the singular)."
208+ UI . user_error! ( "Stringsdict entry '#{ key } ' is missing a required plural form " \
209+ "(needs at least 'other'; 'one' recommended for the singular)." )
210210 end
211211
212212 warn_dropped_categories ( key : key , variable : variable , var_dict : var_dict )
@@ -256,9 +256,9 @@ def self.translated_forms(parsed_po:, context:, source_var:)
256256 def self . validate_form_count! ( forms :, categories :, context :, locale :)
257257 return if forms . size == categories . size
258258
259- raise "Translation for '#{ context } ' has #{ forms . size } plural form(s) but locale '#{ locale } ' " \
260- "expects #{ categories . size } (#{ categories . join ( ', ' ) } ). The translation system's plural " \
261- 'configuration for this locale does not match the expected CLDR categories.'
259+ UI . user_error! ( "Translation for '#{ context } ' has #{ forms . size } plural form(s) but locale '#{ locale } ' " \
260+ "expects #{ categories . size } (#{ categories . join ( ', ' ) } ). The translation system's plural " \
261+ 'configuration for this locale does not match the expected CLDR categories.' )
262262 end
263263
264264 # A translated entry that has some — but not all — of its plural forms
@@ -313,7 +313,7 @@ def self.english_variable(source_var)
313313 end
314314
315315 def self . parse_po ( path )
316- raise "PO file not found: #{ path } " unless File . exist? ( path )
316+ UI . user_error! ( "PO file not found: #{ path } " ) unless File . exist? ( path )
317317
318318 po = GetText ::PO . new
319319 GetText ::POParser . new . parse ( File . read ( path ) , po )
@@ -339,10 +339,10 @@ def self.guard_po_plural_count!(po_path:, locale:, categories:)
339339 declared = declared_nplurals ( po_path )
340340 return if declared . nil? || declared == categories . size
341341
342- raise "Locale '#{ locale } ': the .po declares nplurals=#{ declared } , but the expected plural mapping has " \
343- "#{ categories . size } categor#{ categories . size == 1 ? 'y' : 'ies' } (#{ categories . join ( ', ' ) } ). " \
344- "GlotPress's plural rule for this locale no longer matches the PluralRules table — regenerate it " \
345- '(rakelib/generate_ios_plural_rules.rb).'
342+ UI . user_error! ( "Locale '#{ locale } ': the .po declares nplurals=#{ declared } , but the expected plural mapping has " \
343+ "#{ categories . size } categor#{ categories . size == 1 ? 'y' : 'ies' } (#{ categories . join ( ', ' ) } ). " \
344+ "GlotPress's plural rule for this locale no longer matches the PluralRules table — regenerate it " \
345+ '(rakelib/generate_ios_plural_rules.rb).' )
346346 end
347347
348348 def self . add_header ( po_data )
0 commit comments