Class: HaveAPI::Tasks::I18nHealth
- Inherits:
-
Object
- Object
- HaveAPI::Tasks::I18nHealth
- Defined in:
- lib/haveapi/tasks/i18n.rb
Constant Summary collapse
- KEY_LITERAL_PATTERN =
/['"](haveapi\.[a-z0-9_.]+)['"]/- RAW_MESSAGE_PATTERNS =
[ /report_error\([^#\n]*,\s*['"]/, /error!\(\s*['"]/, /HaveAPI::ValidationError(?:\.new)?\(\s*['"]/, /raise\s+HaveAPI::ValidationError,\s*['"]/, /ret\[:message\]\s*=\s*['"]/, /\|\|\s*['"][^'"]+(?:failed|error|denied|not found|invalid|requires|unsupported|missing)/, /@message\s*=\s*take\(\s*:message\s*,\s*['"]/ ].freeze
- PARAMETER_METHODS =
%w[ bool custom datetime float id integer password resource string text ].freeze
- PARAMETER_CALL_PATTERN =
/\A\s*(?:#{PARAMETER_METHODS.join('|')})\b/- RAW_PARAMETER_METADATA_PATTERN =
/\b(?:label|desc):\s*['"]/
Instance Method Summary collapse
- #check! ⇒ Object
-
#initialize(root:) ⇒ I18nHealth
constructor
A new instance of I18nHealth.
- #normalize! ⇒ Object
Constructor Details
#initialize(root:) ⇒ I18nHealth
Returns a new instance of I18nHealth.
24 25 26 |
# File 'lib/haveapi/tasks/i18n.rb', line 24 def initialize(root:) @root = root end |
Instance Method Details
#check! ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/haveapi/tasks/i18n.rb', line 28 def check! errors = [] errors.concat(missing_key_errors) errors.concat(unused_key_errors) errors.concat() return true if errors.empty? raise "i18n health check failed:\n#{errors.join("\n")}" end |
#normalize! ⇒ Object
39 40 41 42 43 44 |
# File 'lib/haveapi/tasks/i18n.rb', line 39 def normalize! locale_data.each do |locale, data| file = File.join(locale_dir, "#{locale}.yml") File.write(file, YAML.dump(locale.to_s => deep_sort(data))) end end |