Move all user-facing text into config/locales/en.yml for localization

- Views use lazy t(".key") lookups; sentences with values or links stay
  whole (interpolation, _html keys); counts use one/other plurals
- Stored-value labels (statuses, types, priorities...) are LabelSets read
  from labels: in the current locale; field names and validation messages
  under activerecord:; flash and activity text under flash:
- Services, models, helpers, mailer subjects, the logbook PDF, procedures
  templates, records package README and transcription warnings localized;
  the PDF reuses LogbookEntry#certification_statement instead of a copy
- Scripts read js: strings from a JSON tag via app/javascript/i18n.js
- Dates through I18n.l (app, weekday, month_year, long formats); html lang
  follows the locale
- APP_LOCALE picks the language (falls back to English); missing
  translations raise in development and tests
- README: Translating section and APP_LOCALE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-13 22:08:20 -05:00
1 parent 3f45b557c2
commit 89ed0a76f9
313 files changed
+6387 -2653

No files matched your search

+3 -9
View File
@@ -1,12 +1,7 @@
class AdCompliance < ApplicationRecord
include Versioned
# Method of compliance, recorded per 91.417(a)(2)(v).
METHODS = {
"inspection" => "Inspection",
"terminating" => "Terminating action (no further action)",
"amoc" => "Alternative method of compliance (AMOC)",
"not_applicable" => "Not applicable to this aircraft"
}.freeze
METHODS = LabelSet.new("ad_compliance.methods", %w[inspection terminating amoc not_applicable])
belongs_to :airworthiness_directive
belongs_to :aircraft, optional: true
@@ -18,7 +13,7 @@ class AdCompliance < ApplicationRecord
validates :compliance_method, inclusion: { in: METHODS.keys }
before_validation :apply_method
before_validation :fill_revision
validate { errors.add(:base, "Must belong to an aircraft or component") unless aircraft_id || component_id }
validate { errors.add(:base, :needs_owner) unless aircraft_id || component_id }
validate :next_due_is_a_future_reading
before_validation :fill_next_due, if: -> { next_due_at_time.to_d.zero? }
@@ -66,7 +61,6 @@ class AdCompliance < ApplicationRecord
return if closed? || due <= 0
base = aircraft_hours_at_compliance || aircraft&.current_hours
return unless base && due <= base
errors.add(:next_due_at_time, "must be a #{aircraft&.time_basis || 'tach'} reading after the compliance hours (#{base}). " \
"For “every 100 hours” enter #{base + 100}, not 100")
errors.add(:next_due_at_time, :not_future_reading, meter: Aircraft::TIME_BASES[aircraft&.time_basis || "tach"].downcase, base: base, example: base + 100)
end
end
+4 -9
View File
@@ -1,10 +1,5 @@
class Aircraft < ApplicationRecord
STATUSES = {
"AVAILABLE" => "Available",
"MX" => "In Maintenance",
"GROUND" => "Grounded",
"UNAVAILABLE" => "Unavailable"
}.freeze
STATUSES = LabelSet.new("aircraft.statuses", %w[AVAILABLE MX GROUND UNAVAILABLE])
has_one_attached :picture
@@ -33,12 +28,12 @@ class Aircraft < ApplicationRecord
# Which clock counts as time in service for maintenance (14 CFR 1.1 defines
# it as takeoff to landing; many owners use tach, some Hobbs).
TIME_BASES = { "tach" => "Tach", "hobbs" => "Hobbs" }.freeze
TIME_BASES = LabelSet.new("aircraft.time_bases", %w[tach hobbs])
validates :tail_number, presence: true
validates :time_basis, inclusion: { in: TIME_BASES.keys }
validates :status, inclusion: { in: STATUSES.keys }
validates :icao_type, format: { with: /\A[A-Z0-9]{1,4}\z/, message: "must be an ICAO type designator like C150" }, allow_blank: true
validates :icao_type, format: { with: /\A[A-Z0-9]{1,4}\z/, message: :icao_type }, allow_blank: true
normalizes :icao_type, with: ->(t) { t.strip.upcase.presence }
validate :picture_is_image
@@ -86,7 +81,7 @@ class Aircraft < ApplicationRecord
def picture_is_image
if picture.attached? && !picture.content_type.to_s.start_with?("image/")
errors.add(:picture, "must be an image")
errors.add(:picture, :not_image)
end
end
end
+1 -7
View File
@@ -1,11 +1,5 @@
class AircraftEvent < ApplicationRecord
CATEGORIES = {
"hours" => "Hours Update", "flight" => "Flight", "component" => "Component",
"squawk" => "Squawk", "note" => "Note", "oil" => "Oil", "fuel" => "Fuel",
"logbook" => "Logbook", "ad" => "Airworthiness Directive", "inspection" => "Inspection",
"document" => "Document", "aircraft" => "Aircraft", "role" => "Role",
"major_record" => "Major Repair/Alteration", "oil_analysis" => "Oil Analysis"
}.freeze
CATEGORIES = LabelSet.new("aircraft_event.categories", %w[hours flight component squawk note oil fuel logbook ad inspection document aircraft role major_record oil_analysis])
belongs_to :aircraft
belongs_to :user, optional: true
+1 -1
View File
@@ -14,6 +14,6 @@ class AircraftImport < ApplicationRecord
# "12 components, 140 logbook entries, …" for whatever was imported.
def summary
counts.select { |_, n| n.to_i.positive? }.map { |key, n| "#{n} #{key.to_s.humanize(capitalize: false).then { n == 1 ? _1.singularize : _1 }}" }.to_sentence
counts.select { |_, n| n.to_i.positive? }.map { |key, n| I18n.t(key, scope: "models.aircraft_import.counts", count: n.to_i) }.to_sentence
end
end
+1 -1
View File
@@ -1,5 +1,5 @@
class AircraftRole < ApplicationRecord
ROLES = { "owner" => "Owner", "pilot" => "Pilot" }.freeze
ROLES = LabelSet.new("aircraft_role.roles", %w[owner pilot])
belongs_to :aircraft
belongs_to :user
+1 -1
View File
@@ -4,7 +4,7 @@ class Airport < ApplicationRecord
KINDS = %w[small_airport medium_airport large_airport seaplane_base heliport balloonport closed].freeze
KIND_RANK = { "large_airport" => 0, "medium_airport" => 1, "small_airport" => 2, "seaplane_base" => 3,
"heliport" => 4, "balloonport" => 5, "closed" => 9 }.freeze
KIND_LABELS = { "seaplane_base" => "seaplane base", "heliport" => "heliport", "balloonport" => "balloonport", "closed" => "closed" }.freeze
KIND_LABELS = LabelSet.new("airport.kinds", %w[seaplane_base heliport balloonport closed])
# Custom airports (admin-added) use their identifier as the AirTrail code.
before_validation(if: :custom?) { self.airtrail_code = ident }
+1 -1
View File
@@ -12,6 +12,6 @@ class AirportUpdate < ApplicationRecord
def in_progress? = status.in?(%w[queued running])
def summary
"#{created_count} added, #{updated_count} updated, #{removed_count} removed"
I18n.t("models.airport_update.summary", added: created_count, updated: updated_count, removed: removed_count)
end
end
+4 -7
View File
@@ -1,10 +1,7 @@
class AirworthinessDirective < ApplicationRecord
COMPLIANCE_TYPES = { "standard" => "Standard", "conditional" => "Conditional" }.freeze
BULLETIN_TYPES = {
"ad" => "Airworthiness Directive", "saib" => "Special Airworthiness Information Bulletin",
"sb" => "Service Bulletin", "alert" => "Airworthiness Alert", "other" => "Other"
}.freeze
BULLETIN_LABELS = { "ad" => "AD", "saib" => "SAIB", "sb" => "SB", "alert" => "Alert", "other" => "Bulletin" }.freeze
COMPLIANCE_TYPES = LabelSet.new("airworthiness_directive.compliance_types", %w[standard conditional])
BULLETIN_TYPES = LabelSet.new("airworthiness_directive.bulletin_types", %w[ad saib sb alert other])
BULLETIN_LABELS = LabelSet.new("airworthiness_directive.bulletin_labels", %w[ad saib sb alert other])
include CalendarInterval
calendar_interval :recurring, days: :recurring_days, months: :recurring_months, blank: 0
@@ -36,7 +33,7 @@ class AirworthinessDirective < ApplicationRecord
# exports carry one per AD; it can also be pasted in). DRS links use an
# internal document id, so they can't be derived from the AD number.
def reference_link
[ document_url, "View AD" ] if document_url.present?
[ document_url, I18n.t("models.airworthiness_directive.view") ] if document_url.present?
end
def conditional? = compliance_type == "conditional"
+5 -5
View File
@@ -1,9 +1,9 @@
class Component < ApplicationRecord
include Versioned
include CalendarInterval
STATUSES = { "SPARE" => "Spare Part", "IN-USE" => "In Service", "DISPOSED" => "Disposed" }.freeze
STATUSES = LabelSet.new("component.statuses", %w[SPARE IN-USE DISPOSED])
# What "since overhaul" counts from, and how logbooks abbreviate it.
OVERHAUL_KINDS = { "major" => "Major overhaul", "factory_overhaul" => "Factory overhaul", "factory_new" => "Factory new or rebuilt (zero time)" }.freeze
OVERHAUL_KINDS = LabelSet.new("component.overhaul_kinds", %w[major factory_overhaul factory_new])
OVERHAUL_ABBREVIATIONS = { "major" => "SMOH", "factory_overhaul" => "SFOH", "factory_new" => "SNEW" }.freeze
calendar_interval :replacement, days: :replacement_days, months: :replacement_months
@@ -41,7 +41,7 @@ class Component < ApplicationRecord
# SMOH / SFOH / SNEW when the overhaul type is known; engines and
# propellers otherwise "TSO", and other parts (filters…) "since service".
def since_overhaul_abbreviation
OVERHAUL_ABBREVIATIONS.fetch(overhaul_kind) { engine? || propeller? ? "TSO" : "Since service" }
OVERHAUL_ABBREVIATIONS.fetch(overhaul_kind) { engine? || propeller? ? "TSO" : I18n.t("models.component.since_service") }
end
# Its sub-components, and theirs.
@@ -132,7 +132,7 @@ class Component < ApplicationRecord
def parent_on_same_aircraft
return unless parent_component
errors.add(:parent_component, "can't be itself") if parent_component_id == id && id
errors.add(:parent_component, "must be on the same aircraft") if parent_component.aircraft_id != aircraft_id
errors.add(:parent_component, :itself) if parent_component_id == id && id
errors.add(:parent_component, :other_aircraft) if parent_component.aircraft_id != aircraft_id
end
end
+3 -3
View File
@@ -9,7 +9,7 @@
module CalendarInterval
extend ActiveSupport::Concern
UNITS = { "days" => "days", "months" => "months", "years" => "years" }.freeze
UNITS = LabelSet.new("calendar_interval.units", %w[days months years])
# [count, unit] for display, from the stored columns.
def self.split(days, months)
@@ -22,7 +22,7 @@ module CalendarInterval
def self.label(days, months)
count, unit = split(days, months)
count && "#{count} #{count == 1 ? unit.singularize : unit}"
count && I18n.t("models.calendar_interval.counts.#{unit}", count: count)
end
class_methods do
@@ -70,7 +70,7 @@ module CalendarInterval
next unless instance_variable_defined?(every_ivar)
raw = instance_variable_get(every_ivar).to_s.strip
next if raw.empty? || Integer(raw, 10, exception: false)&.positive?
errors.add(:"#{name}_every", "must be a whole number more than 0")
errors.add(:"#{name}_every", :positive_whole_number)
end
end
end
+2 -2
View File
@@ -18,10 +18,10 @@ module UploadValidation
Array(public_send(name).attachments).each do |att|
next unless att.blob
unless ALLOWED_CONTENT_TYPES.include?(att.blob.content_type)
errors.add(name, "#{att.filename} is not an allowed file type")
errors.add(name, :file_type, file: att.filename.to_s)
end
limit = UploadValidation.max_size
errors.add(name, "#{att.filename} is over the #{limit / 1.megabyte} MB upload limit") if att.blob.byte_size > limit
errors.add(name, :file_size, file: att.filename.to_s, limit: limit / 1.megabyte) if att.blob.byte_size > limit
end
end
end
+1 -1
View File
@@ -1,5 +1,5 @@
class ConsumableRecord < ApplicationRecord
TYPES = { "oil" => "Oil", "fuel" => "Fuel" }.freeze
TYPES = LabelSet.new("consumable_record.types", %w[oil fuel])
UNITS = { "oil" => "qt", "fuel" => "gal" }.freeze
belongs_to :aircraft
+1 -7
View File
@@ -2,13 +2,7 @@ class Document < ApplicationRecord
include Versioned
include UploadValidation
TYPES = {
"LOG" => "Logbook", "ALTER" => "Alteration Record", "REPORT" => "Report",
"ESTIMATE" => "Estimate", "DISC" => "Discrepancy List", "INVOICE" => "Receipt / Invoice",
"AIRCRAFT" => "Aircraft Record", "REGISTRATION" => "Registration Certificate",
"AIRWORTHINESS_CERT" => "Airworthiness Certificate", "INSURANCE" => "Insurance Policy",
"RADIO" => "Radio Station License", "OTHER" => "Other"
}.freeze
TYPES = LabelSet.new("document.types", %w[LOG ALTER REPORT ESTIMATE DISC INVOICE AIRCRAFT REGISTRATION AIRWORTHINESS_CERT INSURANCE RADIO OTHER])
# An expired registration means the aircraft may not be flown (14 CFR
# 91.203(a)(2)); renewal takes a while, so warn earlier.
GROUNDING_EXPIRY_TYPES = %w[REGISTRATION].freeze
+1 -1
View File
@@ -1,5 +1,5 @@
class DocumentCollection < ApplicationRecord
VISIBILITIES = { "private" => "Private", "status" => "All share links", "maintenance" => "Maintenance only" }.freeze
VISIBILITIES = LabelSet.new("document_collection.visibilities", %w[private status maintenance])
belongs_to :aircraft
has_many :documents, dependent: :destroy
+3 -4
View File
@@ -7,10 +7,9 @@
# by this server, so the signature record can't be altered unnoticed either.
class EntrySignature < ApplicationRecord
include Versioned
AUTH_METHODS = { "password" => "password re-entered", "password_totp" => "password and authenticator code re-entered",
"sso" => "single sign-on, signed in again" }.freeze
AUTH_METHODS = LabelSet.new("entry_signature.auth_methods", %w[password password_totp sso])
# "Certified by" conveys the intent to sign (2.2.2).
LABEL = "Certified by".freeze
def self.label = I18n.t("labels.entry_signature.certified_by")
belongs_to :logbook_entry
belongs_to :user, optional: true
@@ -43,6 +42,6 @@ class EntrySignature < ApplicationRecord
end
def status_label
{ valid: "Valid", superseded: "Superseded by a correction", altered: "Altered since signing" }[status]
I18n.t(status, scope: "models.entry_signature.statuses")
end
end
+1 -1
View File
@@ -7,7 +7,7 @@ class InspectionRecord < ApplicationRecord
has_many :ad_compliances, dependent: :nullify
validates :date, presence: true
validate { errors.add(:base, "Must belong to an aircraft or component") unless aircraft_id || component_id }
validate { errors.add(:base, :needs_owner) unless aircraft_id || component_id }
scope :recent_first, -> { order(date: :desc, created_at: :desc) }
+9 -15
View File
@@ -1,16 +1,10 @@
class InspectionType < ApplicationRecord
# What it means for the aircraft when this inspection is overdue.
EFFECTS = {
"grounds" => "Grounds the aircraft",
"no_ifr" => "No IFR flight (e.g. pitot-static, 91.411)",
"no_transponder" => "Transponder can't be used (91.413)",
"advisory" => "Advisory only"
}.freeze
EFFECTS = LabelSet.new("inspection_type.effects", %w[grounds no_ifr no_transponder advisory])
# In a sentence: "Overdue: no IFR."
EFFECT_SUMMARIES = { "grounds" => "grounds the aircraft", "no_ifr" => "no IFR", "no_transponder" => "transponder can't be used",
"advisory" => "advisory only" }.freeze
EFFECT_SUMMARIES = LabelSet.new("inspection_type.effect_summaries", %w[grounds no_ifr no_transponder advisory])
# Short form for the airworthiness status ("VFR only").
LIMITATIONS = { "no_ifr" => "VFR only", "no_transponder" => "No transponder" }.freeze
LIMITATIONS = LabelSet.new("inspection_type.limitations", %w[no_ifr no_transponder])
include CalendarInterval
calendar_interval :recurring, days: :recurring_days, months: :recurring_months, blank: 0
@@ -22,7 +16,7 @@ class InspectionType < ApplicationRecord
validates :name, presence: true
validates :effect, inclusion: { in: EFFECTS.keys }
validates :hours_tolerance, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 }
validate { errors.add(:satisfies, "can't be the inspection itself") if satisfies_id.present? && satisfies_id == id }
validate { errors.add(:satisfies, :itself) if satisfies_id.present? && satisfies_id == id }
# `required` mirrors effect, for archives shared with the original app.
before_validation { self.required = effect != "advisory" }
@@ -43,12 +37,12 @@ class InspectionType < ApplicationRecord
end
def interval_description
return "One-time" unless recurring?
return I18n.t("models.inspection_type.one_time") unless recurring?
parts = []
parts << "#{recurring_hours.to_s.sub(/\.0\z/, '')} hrs" if recurring_hours.to_f > 0
parts << I18n.t("models.inspection_type.hours", hours: recurring_hours.to_s.sub(/\.0\z/, "")) if recurring_hours.to_f > 0
parts << recurring_interval_label if recurring_months > 0 && recurring_days.zero?
parts << "#{recurring_months} months" if recurring_months > 0 && recurring_days > 0
parts << "#{recurring_days} days" if recurring_days > 0
parts.any? ? "Every #{parts.join(' / ')}" : "Recurring"
parts << CalendarInterval.label(0, recurring_months) if recurring_months > 0 && recurring_days > 0
parts << CalendarInterval.label(recurring_days, 0) if recurring_days > 0
parts.any? ? I18n.t("models.inspection_type.every", interval: parts.join(" / ")) : I18n.t("models.inspection_type.recurring")
end
end
+30
View File
@@ -0,0 +1,30 @@
# Display labels for stored values, from the locale file and in the current
# locale: LabelSet.new("aircraft.statuses", %w[AVAILABLE MX]) reads
# labels.aircraft.statuses.AVAILABLE. It answers like the hash it replaces
# ({ "AVAILABLE" => "Available", ... }): [], fetch, keys, key?, invert, each…
class LabelSet
include Enumerable
attr_reader :keys
def initialize(scope, keys)
@scope = "labels.#{scope}"
@keys = keys.freeze
freeze
end
def [](key) = (I18n.t(key.to_s, scope: @scope) if key?(key))
def fetch(key, *default) = key?(key) ? self[key] : (default.any? ? default.first : yield(key))
def key?(key) = @keys.include?(key)
def to_h = @keys.index_with { self[_1] }
def each(&) = to_h.each(&)
def each_key(&) = @keys.each(&)
def values = to_h.values
def invert = to_h.invert
def key(label) = to_h.key(label)
def except(*drop) = to_h.except(*drop)
def slice(*keep) = to_h.slice(*keep)
def size = @keys.size
alias include? key?
end
+6 -6
View File
@@ -8,7 +8,7 @@ class LoadingSetup
Station = Data.define(:name, :arm, :max, :fuel)
ENVELOPE_UNITS = { "cg" => "CG (inches aft of datum)", "moment" => "Moment (lb-in / 1000)" }.freeze
ENVELOPE_UNITS = LabelSet.new("loading_setup.envelope_units", %w[cg moment])
attr_accessor :stations, :envelope, :fuel_lb_per_gal
attr_writer :envelope_unit
@@ -55,11 +55,11 @@ class LoadingSetup
validate do
raw_s = @raw_stations || []
raw_e = @raw_envelope || []
errors.add(:base, "Every station needs a name and a numeric arm (inches)") if raw_s.size != stations.size || stations.any? { _1.name.blank? }
errors.add(:base, "Every envelope point needs a numeric weight and CG") if raw_e.size != envelope.size
errors.add(:base, "The CG envelope needs at least 3 points, or none") if envelope.size.between?(1, 2)
errors.add(:base, "Envelope weights must be more than 0") if envelope.any? { |w, _| !w.positive? }
errors.add(:base, "Fuel weight per gallon must be between 4 and 9 lb") unless fuel_lb_per_gal.to_d.between?(4, 9)
errors.add(:base, :stations) if raw_s.size != stations.size || stations.any? { _1.name.blank? }
errors.add(:base, :envelope_points) if raw_e.size != envelope.size
errors.add(:base, :envelope_size) if envelope.size.between?(1, 2)
errors.add(:base, :envelope_weights) if envelope.any? { |w, _| !w.positive? }
errors.add(:base, :fuel_weight) unless fuel_lb_per_gal.to_d.between?(4, 9)
end
def stations_json
+29 -40
View File
@@ -1,22 +1,12 @@
class LogbookEntry < ApplicationRecord
include Versioned
LOG_TYPES = { "AC" => "Aircraft", "ENG" => "Engine", "PROP" => "Propeller", "OTHER" => "Other" }.freeze
ENTRY_TYPES = {
"MAINTENANCE" => "Maintenance", "INSPECTION" => "Inspection", "FLIGHT" => "Flight",
"HOURS_UPDATE" => "Hours Update", "OTHER" => "Other"
}.freeze
LOG_TYPES = LabelSet.new("logbook_entry.log_types", %w[AC ENG PROP OTHER])
ENTRY_TYPES = LabelSet.new("logbook_entry.entry_types", %w[MAINTENANCE INSPECTION FLIGHT HOURS_UPDATE OTHER])
# Kind of certificate of the person approving return to service (43.9(a)(4)).
CERTIFICATE_TYPES = {
"AP" => "A&P mechanic", "IA" => "A&P with Inspection Authorization", "A" => "Mechanic, airframe only",
"P" => "Mechanic, powerplant only", "REPAIR_STATION" => "Repair station", "REPAIRMAN" => "Repairman",
"PILOT" => "Pilot (preventive maintenance)", "OTHER" => "Other"
}.freeze
CERTIFICATE_TYPES = LabelSet.new("logbook_entry.certificate_types", %w[AP IA A P REPAIR_STATION REPAIRMAN PILOT OTHER])
# An inspection entry ends with one of these (43.11(a)(5)).
INSPECTION_RESULTS = {
"approved" => "Airworthy, approved for return to service",
"discrepancies" => "Not approved: discrepancy list given to the owner"
}.freeze
INSPECTION_RESULTS = LabelSet.new("logbook_entry.inspection_results", %w[approved discrepancies])
# Entries that 43.9 / 43.11 set requirements for.
RECORD_TYPES = %w[MAINTENANCE INSPECTION].freeze
@@ -60,7 +50,7 @@ class LogbookEntry < ApplicationRecord
where("text LIKE :t OR signoff_person LIKE :t OR signoff_location LIKE :t", t: term)
end
def to_s = "#{date} — #{LOG_TYPES[log_type]}"
def to_s = "#{date && I18n.l(date, format: :app)} — #{LOG_TYPES[log_type]}"
def signed? = signature.present?
def superseded? = superseded_at.present?
@@ -103,45 +93,44 @@ class LogbookEntry < ApplicationRecord
name = inspection_records.first&.inspection_type&.name.to_s.sub(/\s*\(.*\)\z/, "").sub(/\s*inspection\z/i, "").strip.downcase
name = "annual" if name.empty? && text.to_s.match?(/annual/i)
name = "100-hour" if name.empty? && text.to_s.match?(/100[- ]?h(ou)?r/i)
return "a ______________" if name.empty?
"#{name.match?(/\A[aeiou]/) ? 'an' : 'a'} #{name}"
return I18n.t("models.logbook_entry.inspection_blank") if name.empty?
I18n.t(name.match?(/\A[aeiou]/) ? "models.logbook_entry.inspection_an" : "models.logbook_entry.inspection_a", name: name)
end
# What the signer certifies, by the kind of entry and certificate.
def certification_statement(certificate_kind)
if entry_type == "INSPECTION"
if inspection_result == "discrepancies"
"I certify that this aircraft has been inspected in accordance with #{inspection_kind_phrase} inspection and a list of discrepancies " \
"and unairworthy items dated #{date&.strftime('%b %-d, %Y')} has been provided for the aircraft owner or operator."
I18n.t("models.logbook_entry.statements.discrepancies", inspection: inspection_kind_phrase, date: date && I18n.l(date, format: :app))
else
"I certify that this aircraft has been inspected in accordance with #{inspection_kind_phrase} inspection and was determined to be in airworthy condition."
I18n.t("models.logbook_entry.statements.airworthy", inspection: inspection_kind_phrase)
end
elsif certificate_kind == "PILOT"
"I certify that the preventive maintenance described in this entry was performed in accordance with 14 CFR Part 43, and I approve it for return to service."
I18n.t("models.logbook_entry.statements.preventive")
elsif entry_type == "MAINTENANCE"
"I certify that the work described in this entry was performed in accordance with 14 CFR Part 43, and I approve it for return to service with respect to that work."
I18n.t("models.logbook_entry.statements.maintenance")
else
"I certify that this entry is correct."
I18n.t("models.logbook_entry.statements.other")
end
end
# Why this certificate can't sign this entry ([] if it can).
def signing_problems(certificate)
problems = []
problems << "it's already signed" if signed?
problems << "it has been superseded by a correction" if superseded?
problems << "it has no description" if text.blank?
problems << "it has no date" if date.blank?
problems << I18n.t("models.logbook_entry.signing_problems.already_signed") if signed?
problems << I18n.t("models.logbook_entry.signing_problems.superseded") if superseded?
problems << I18n.t("models.logbook_entry.signing_problems.no_description") if text.blank?
problems << I18n.t("models.logbook_entry.signing_problems.no_date") if date.blank?
if entry_type == "INSPECTION"
problems << "an inspection entry needs its result (airworthy, or discrepancy list)" if inspection_result.blank?
problems << "an inspection entry needs the aircraft's total time" if aircraft_hours_at_entry.blank?
problems << I18n.t("models.logbook_entry.signing_problems.no_result") if inspection_result.blank?
problems << I18n.t("models.logbook_entry.signing_problems.no_total_time") if aircraft_hours_at_entry.blank?
end
if certificate
problems << "that certificate has expired" if certificate.expired?
problems << "a pilot certificate can sign preventive maintenance only" if certificate.kind == "PILOT" && entry_type != "MAINTENANCE"
problems << "\"Other\" certificates can't sign maintenance or inspections" if certificate.kind == "OTHER" && RECORD_TYPES.include?(entry_type)
problems << I18n.t("models.logbook_entry.signing_problems.certificate_expired") if certificate.expired?
problems << I18n.t("models.logbook_entry.signing_problems.pilot_preventive_only") if certificate.kind == "PILOT" && entry_type != "MAINTENANCE"
problems << I18n.t("models.logbook_entry.signing_problems.other_certificate") if certificate.kind == "OTHER" && RECORD_TYPES.include?(entry_type)
else
problems << "choose a certificate to sign with"
problems << I18n.t("models.logbook_entry.signing_problems.choose_certificate")
end
problems
end
@@ -166,13 +155,13 @@ class LogbookEntry < ApplicationRecord
def missing_record_items
return [] unless RECORD_TYPES.include?(entry_type)
missing = []
missing << "description of the work" if text.blank?
missing << "signer's name" if signoff_person.blank?
missing << "kind of certificate" if signoff_certificate_type.blank?
missing << "certificate number" if signoff_certificate_number.blank?
missing << I18n.t("models.logbook_entry.missing.description") if text.blank?
missing << I18n.t("models.logbook_entry.missing.signer") if signoff_person.blank?
missing << I18n.t("models.logbook_entry.missing.certificate_kind") if signoff_certificate_type.blank?
missing << I18n.t("models.logbook_entry.missing.certificate_number") if signoff_certificate_number.blank?
if entry_type == "INSPECTION"
missing << "aircraft time in service" if aircraft_hours_at_entry.blank?
missing << "airworthiness result" if inspection_result.blank?
missing << I18n.t("models.logbook_entry.missing.time_in_service") if aircraft_hours_at_entry.blank?
missing << I18n.t("models.logbook_entry.missing.result") if inspection_result.blank?
end
missing
end
@@ -183,7 +172,7 @@ class LogbookEntry < ApplicationRecord
return unless signed? && signature.persisted?
locked = changed - UNSIGNED_FIELDS
return if locked.empty?
errors.add(:base, "This entry is signed, so it can't be changed. Make a correction entry instead")
errors.add(:base, :signed_locked)
throw :abort
end
end
+6 -5
View File
@@ -10,14 +10,15 @@ module MailSettings
def summary
method = ActionMailer::Base.delivery_method
rows = { "Delivery" => configured? ? method.to_s.upcase : "not configured (set SMTP_ADDRESS)" }
t = ->(key, **opts) { I18n.t(key, scope: "models.mail_settings", **opts) }
rows = { t.(:delivery) => configured? ? method.to_s.upcase : t.(:not_configured) }
if method == :smtp && configured?
s = ActionMailer::Base.smtp_settings
rows["Server"] = "#{s[:address]}:#{s[:port]}"
rows["Encryption"] = s[:tls] ? "TLS" : "STARTTLS when offered"
rows["Signs in as"] = s[:user_name].presence || "no login"
rows[t.(:server)] = "#{s[:address]}:#{s[:port]}"
rows[t.(:encryption)] = s[:tls] ? "TLS" : t.(:starttls)
rows[t.(:signs_in_as)] = s[:user_name].presence || t.(:no_login)
end
rows["From"] = ApplicationMailer.default[:from]
rows[t.(:from)] = ApplicationMailer.default[:from]
rows
end
end
+1 -1
View File
@@ -1,6 +1,6 @@
class MajorRecord < ApplicationRecord
include Versioned
RECORD_TYPES = { "repair" => "Major Repair", "alteration" => "Major Alteration" }.freeze
RECORD_TYPES = LabelSet.new("major_record.record_types", %w[repair alteration])
belongs_to :aircraft
belongs_to :component, optional: true
+22 -40
View File
@@ -7,44 +7,26 @@
class OilAnalysis < ApplicationRecord
include UploadValidation
# Element → [label, what it usually indicates]. The first twelve are the
# wear-metal set every lab reports; the rest are mostly oil additives.
ELEMENTS = {
"iron" => [ "Iron", "Cylinders, cam, lifters, gears" ],
"copper" => [ "Copper", "Bearings, bushings, oil cooler" ],
"nickel" => [ "Nickel", "Valve guides, cylinder plating" ],
"chromium" => [ "Chromium", "Rings, chromed cylinders" ],
"silver" => [ "Silver", "Bearing plating" ],
"magnesium" => [ "Magnesium", "Accessory case, additive" ],
"aluminum" => [ "Aluminum", "Pistons, case" ],
"lead" => [ "Lead", "Fuel (100LL) blow-by" ],
"silicon" => [ "Silicon", "Dirt (air filter), sealant" ],
"titanium" => [ "Titanium", "Hardened parts" ],
"tin" => [ "Tin", "Bearings, piston pin bushings" ],
"molybdenum" => [ "Moly", "Rings, additive" ],
"manganese" => [ "Manganese", "Steel alloys (valves, gears)" ],
"potassium" => [ "Potassium", "Coolant, additive" ],
"boron" => [ "Boron", "Additive" ],
"sodium" => [ "Sodium", "Additive, dirt" ],
"calcium" => [ "Calcium", "Detergent additive" ],
"phosphorus" => [ "Phosphorus", "Anti-wear additive" ],
"zinc" => [ "Zinc", "Anti-wear additive, brass" ],
"barium" => [ "Barium", "Additive" ]
}.freeze
# Elements (labels.oil_analysis.elements) and what each usually indicates
# (element_sources). The first twelve are the wear-metal set every lab
# reports; the rest are mostly oil additives.
ELEMENTS = LabelSet.new("oil_analysis.elements", %w[iron copper nickel chromium silver magnesium aluminum lead silicon titanium tin molybdenum manganese potassium boron sodium calcium phosphorus zinc barium])
ELEMENT_SOURCES = LabelSet.new("oil_analysis.element_sources", ELEMENTS.keys)
COMMON_ELEMENTS = ELEMENTS.keys.first(12).freeze
# Property → [label, unit].
PROPERTIES = {
"viscosity_sus_210f" => [ "Viscosity @ 210°F", "SUS" ],
"viscosity_cst_100c" => [ "Viscosity @ 100°C", "cSt" ],
"flashpoint_f" => [ "Flash point", "°F" ],
"fuel_percent" => [ "Fuel", "%" ],
"antifreeze_percent" => [ "Antifreeze", "%" ],
"water_percent" => [ "Water", "%" ],
"insolubles_percent" => [ "Insolubles", "%" ],
"total_base_number" => [ "TBN", "" ],
"total_acid_number" => [ "TAN", "" ]
# Oil properties (labels.oil_analysis.properties) and their units.
PROPERTIES = LabelSet.new("oil_analysis.properties", %w[viscosity_sus_210f viscosity_cst_100c flashpoint_f fuel_percent antifreeze_percent water_percent insolubles_percent total_base_number total_acid_number])
PROPERTY_UNITS = {
"viscosity_sus_210f" => "SUS",
"viscosity_cst_100c" => "cSt",
"flashpoint_f" => "°F",
"fuel_percent" => "%",
"antifreeze_percent" => "%",
"water_percent" => "%",
"insolubles_percent" => "%",
"total_base_number" => "",
"total_acid_number" => ""
}.freeze
STATUSES = { "normal" => "Normal", "monitor" => "Monitor", "action_required" => "Action required" }.freeze
STATUSES = LabelSet.new("oil_analysis.statuses", %w[normal monitor action_required])
# A reading this far above the lab's average for similar engines gets flagged.
FLAG_RATIO = 1.5
# Wear metals worth charting together (lead is on its own scale: it comes from fuel).
@@ -66,7 +48,7 @@ class OilAnalysis < ApplicationRecord
scope :recent_first, -> { order(sample_date: :desc, created_at: :desc) }
def self.element_label(el) = ELEMENTS.fetch(el)[0]
def self.element_label(el) = ELEMENTS.fetch(el)
# Elements any of these samples has a reading for, in display order.
def self.elements_in(analyses) = ELEMENTS.keys.select { |el| analyses.any? { _1.value(el) } }
@@ -121,12 +103,12 @@ class OilAnalysis < ApplicationRecord
def results_are_numbers
(@invalid_results || {}).each do |attribute, keys|
labels = keys.map { (ELEMENTS[_1] || PROPERTIES[_1]).first }
errors.add(attribute, "must be numbers of 0 or more (#{labels.to_sentence})") if keys.any?
labels = keys.map { ELEMENTS[_1] || PROPERTIES[_1] }
errors.add(attribute, :not_numbers, fields: labels.to_sentence) if keys.any?
end
end
def component_belongs_to_aircraft
errors.add(:component, "must be on this aircraft") if component && component.aircraft_id != aircraft_id
errors.add(:component, :other_aircraft) if component && component.aircraft_id != aircraft_id
end
end
+3 -4
View File
@@ -9,14 +9,13 @@ class RecordkeepingPolicy < ApplicationRecord
def complete? = [ operator_name, responsible_name, hosting_description ].all?(&:present?) && offsite_backup? && unfilled_fields.empty?
FILLABLE = { hosting_description: "Hosting and network", offsite_backup_description: "Off-site backup",
additional_procedures: "Additional procedures", operator_name: "Owner / operator",
responsible_name: "Responsible person", responsible_title: "Their role" }.freeze
FILLABLE = LabelSet.new("recordkeeping_policy.fillable", %w[hosting_description offsite_backup_description additional_procedures
operator_name responsible_name responsible_title])
# A [bracketed] blank left from the suggested text (not a Markdown link).
BLANK = /\[[^\]\n]+\](?!\()/
# Labels of the fields that still have a blank to fill in.
def unfilled_fields = FILLABLE.select { |attr, _| self[attr].to_s.match?(BLANK) }.values
def unfilled_fields = FILLABLE.keys.select { self[_1].to_s.match?(BLANK) }.map { FILLABLE[_1] }
# Off-site backup is described, or done by the app to Google Drive.
def offsite_backup? = offsite_backup_description.present? || OffsiteConnection.connected?
+7 -6
View File
@@ -6,12 +6,13 @@
# Setting.max_upload_bytes # => 52428800
class Setting < ApplicationRecord
INTEGERS = {
"max_upload_mb" => { default: 50, in: 1..1024, label: "Maximum upload size (MB)" },
"backups_kept" => { default: 14, in: 1..365, label: "Database backups kept" },
"offsite_backups_kept" => { default: 30, in: 1..365, label: "Database copies kept in Google Drive" },
"documents_claude_text" => { default: 0, in: 0..1, label: "Read scanned documents with Claude" },
"logbook_templates_seeded" => { default: 0, in: 0..1, label: "Built-in logbook templates added" } # internal flag
"max_upload_mb" => { default: 50, in: 1..1024 },
"backups_kept" => { default: 14, in: 1..365 },
"offsite_backups_kept" => { default: 30, in: 1..365 },
"documents_claude_text" => { default: 0, in: 0..1 },
"logbook_templates_seeded" => { default: 0, in: 0..1 } # internal flag
}.freeze
LABELS = LabelSet.new("setting.keys", INTEGERS.keys)
validates :key, presence: true, uniqueness: true, inclusion: { in: INTEGERS.keys }
validate :value_in_range
@@ -41,7 +42,7 @@ class Setting < ApplicationRecord
def value_in_range
definition = INTEGERS[key] or return
unless value.to_s.match?(/\A\d+\z/) && definition[:in].cover?(value.to_i)
errors.add(:base, "#{definition[:label]} must be a whole number from #{definition[:in].min} to #{definition[:in].max}")
errors.add(:base, :out_of_range, setting: LABELS[key], min: definition[:in].min, max: definition[:in].max)
end
end
end
+2 -2
View File
@@ -1,5 +1,5 @@
class ShareToken < ApplicationRecord
PRIVILEGES = { "status" => "Current Status", "maintenance" => "Maintenance Detail" }.freeze
PRIVILEGES = LabelSet.new("share_token.privileges", %w[status maintenance])
MAX_PER_AIRCRAFT = 10
belongs_to :aircraft
@@ -22,7 +22,7 @@ class ShareToken < ApplicationRecord
def within_limit
if aircraft && aircraft.share_tokens.count >= MAX_PER_AIRCRAFT
errors.add(:base, "An aircraft can have at most #{MAX_PER_AIRCRAFT} share links")
errors.add(:base, :too_many, max: MAX_PER_AIRCRAFT)
end
end
end
+6 -13
View File
@@ -2,7 +2,7 @@ class Squawk < ApplicationRecord
include Versioned
include UploadValidation
PRIORITIES = { 0 => "Ground Aircraft", 1 => "Fix Soon", 2 => "Fix at Next Inspection", 3 => "Fix Eventually" }.freeze
PRIORITIES = LabelSet.new("squawk.priorities", [ 0, 1, 2, 3 ])
PRIORITY_COLORS = { 0 => "red", 1 => "orange", 2 => "blue", 3 => "gray" }.freeze
belongs_to :aircraft
@@ -21,17 +21,10 @@ class Squawk < ApplicationRecord
# Deferring inoperative equipment without an MEL, 14 CFR 91.213(d): what
# was done with the item and who decided it isn't a hazard.
DEFERRAL_ACTIONS = { "deactivated" => "Deactivated and placarded \"Inoperative\"",
"removed" => "Removed, cockpit control placarded \"Inoperative\"" }.freeze
DEFERRAL_ROLES = { "pilot" => "Pilot", "mechanic" => "Certificated mechanic" }.freeze
DEFERRAL_ACTIONS = LabelSet.new("squawk.deferral_actions", %w[deactivated removed])
DEFERRAL_ROLES = LabelSet.new("squawk.deferral_roles", %w[pilot mechanic])
# Each must be confirmed to defer (91.213(d)(2)(i)–(iv) and (d)(3)–(4)).
DEFERRAL_CHECKS = {
"not_required_by_type" => "Not part of the VFR-day type certification instruments and equipment, nor on the aircraft's equipment list or kinds of operations equipment list",
"not_required_by_rules" => "Not required by 91.205 or any other rule for the kind of flight planned",
"not_required_by_ad" => "Not required by an airworthiness directive",
"placarded" => "Removed or deactivated, and placarded \"Inoperative\"",
"no_hazard" => "A pilot or certificated mechanic has determined it isn't a hazard to the aircraft"
}.freeze
DEFERRAL_CHECKS = LabelSet.new("squawk.deferral_checks", %w[not_required_by_type not_required_by_rules not_required_by_ad placarded no_hazard])
scope :deferred, -> { active.where.not(deferred_at: nil) }
@@ -39,7 +32,7 @@ class Squawk < ApplicationRecord
validates :deferred_by_role, inclusion: { in: DEFERRAL_ROLES.keys }, if: :deferred?
validates :deferred_by_name, presence: true, if: :deferred?
def priority_label = deferred? ? "Deferred (91.213(d))" : PRIORITIES[priority]
def priority_label = deferred? ? I18n.t("models.squawk.deferred") : PRIORITIES[priority]
def priority_color = deferred? ? "blue" : PRIORITY_COLORS[priority]
def deferred? = deferred_at.present? && !resolved?
def grounding? = priority.zero? && !resolved? && !deferred?
@@ -50,7 +43,7 @@ class Squawk < ApplicationRecord
missing = DEFERRAL_CHECKS.keys - Array(checks).map(&:to_s)
assign_attributes(deferred_at: Time.current, deferred_by_name: name.to_s.strip.presence, deferred_by_role: role,
deferral_action: action, deferral_notes: notes.to_s.strip.presence)
missing.each { errors.add(:base, "Confirm: #{DEFERRAL_CHECKS[_1]}") }
missing.each { errors.add(:base, :confirm, check: DEFERRAL_CHECKS[_1]) }
return false if missing.any? || !valid?
save
end
+17 -14
View File
@@ -10,7 +10,7 @@ class SystemInfo
# Where the source lives; APP_REPOSITORY_URL overrides it for a fork.
REPOSITORY_URL = ENV["APP_REPOSITORY_URL"].presence || "https://github.com/rickbarrette/simple-aircraft-manager-rails"
DATABASES = { "Main" => :primary, "Cache" => :cache, "Jobs" => :queue }.freeze
DATABASES = %i[primary cache queue].freeze
# The release version, YYYY.MM.N (the repository's VERSION file).
def version
@@ -18,7 +18,7 @@ class SystemInfo
end
# "2026.11.0 (build 87e3094)"
def version_label = "#{version} (build #{revision})"
def version_label = t(:version_label, version: version, revision: revision)
# The build: the commit it was made from. Set by the Docker build (see
# Dockerfile); in development, read from git.
@@ -47,12 +47,12 @@ class SystemInfo
def runtime
{
"Ruby" => "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})",
"YJIT" => defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled? ? "on" : "off",
"YJIT" => t(defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled? ? :on : :off),
"Rails" => Rails.version,
"SQLite" => SQLite3::SQLITE_VERSION,
"Bundler" => Bundler::VERSION,
"Environment" => Rails.env,
"Time zone" => Time.zone.name
t(:environment) => Rails.env,
t(:time_zone) => Time.zone.name
}
end
@@ -65,17 +65,18 @@ class SystemInfo
# Configured or not; secret values are never read out.
def features
{
"Single sign-on" => Sso.enabled? ? "#{Sso.label}#{', password sign-in off' unless Sso.password_login?}" : "not configured",
"AI logbook transcription" => ENV["ANTHROPIC_API_KEY"].present? ? "on (#{LogbookTranscriber::MODEL})" : "no API key",
"Email" => MailSettings.configured? ? ActionMailer::Base.delivery_method.to_s.upcase : "not configured",
"Upload limit" => "#{Setting.max_upload_mb} MB per file",
"HTTPS enforced" => Rails.application.config.force_ssl ? "yes" : "no",
"File storage" => ActiveStorage::Blob.service.class.name.demodulize.delete_suffix("Service")
t(:sso) => Sso.enabled? ? (Sso.password_login? ? Sso.label : t(:sso_only, provider: Sso.label)) : t(:not_configured),
t(:transcription) => ENV["ANTHROPIC_API_KEY"].present? ? t(:on_with, detail: LogbookTranscriber::MODEL) : t(:no_api_key),
t(:email) => MailSettings.configured? ? ActionMailer::Base.delivery_method.to_s.upcase : t(:not_configured),
t(:upload_limit) => t(:upload_limit_value, mb: Setting.max_upload_mb),
t(:https) => t(Rails.application.config.force_ssl ? :yes : :no),
t(:file_storage) => ActiveStorage::Blob.service.class.name.demodulize.delete_suffix("Service")
}
end
def databases
DATABASES.filter_map do |label, name|
DATABASES.filter_map do |name|
label = I18n.t(name, scope: "models.system_info.databases")
config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: name.to_s)
next unless config
path = Rails.root.join(config.database.to_s)
@@ -84,8 +85,8 @@ class SystemInfo
end
def record_counts
{ "Users" => User.count, "Aircraft" => Aircraft.count, "Documents" => Document.count,
"Logbook entries" => LogbookEntry.count, "Flights" => FlightLog.count, "Squawks" => Squawk.count }
{ t(:users) => User.count, t(:aircraft) => Aircraft.count, t(:documents) => Document.count,
t(:logbook_entries) => LogbookEntry.count, t(:flights) => FlightLog.count, t(:squawks) => Squawk.count }
end
# Bytes saved by storing identical files once, estimated from checksums.
@@ -110,6 +111,8 @@ class SystemInfo
private
def t(key, **opts) = I18n.t(key, scope: "models.system_info", **opts)
def specs = Gem.loaded_specs
def free_disk_bytes
+1 -1
View File
@@ -125,6 +125,6 @@ class User < ApplicationRecord
def password_not_breached
return if password.blank? || errors.include?(:password)
errors.add(:password, "has appeared in a data breach (Have I Been Pwned); choose a different one") if PwnedPasswords.breached?(password)
errors.add(:password, :breached) if PwnedPasswords.breached?(password)
end
end
+1 -2
View File
@@ -4,8 +4,7 @@
class UserCertificate < ApplicationRecord
KINDS = LogbookEntry::CERTIFICATE_TYPES
MECHANIC_KINDS = %w[AP IA A P REPAIR_STATION REPAIRMAN].freeze
SHORT_LABELS = { "AP" => "A&P", "IA" => "IA", "A" => "Airframe", "P" => "Powerplant", "REPAIR_STATION" => "Repair station",
"REPAIRMAN" => "Repairman", "PILOT" => "Pilot", "OTHER" => "Other" }.freeze
SHORT_LABELS = LabelSet.new("user_certificate.short_labels", %w[AP IA A P REPAIR_STATION REPAIRMAN PILOT OTHER])
EXPIRY_WARNING_DAYS = 60
belongs_to :user
+1 -1
View File
@@ -11,7 +11,7 @@ class WeightBalanceRecord < ApplicationRecord
validates :empty_weight, numericality: { greater_than: 0 }
validates :empty_arm, numericality: true
validates :max_gross_weight, numericality: { greater_than: 0 }, allow_nil: true
validate { errors.add(:max_gross_weight, "must be more than the empty weight") if max_gross_weight && empty_weight && max_gross_weight <= empty_weight }
validate { errors.add(:max_gross_weight, :below_empty) if max_gross_weight && empty_weight && max_gross_weight <= empty_weight }
scope :recent_first, -> { order(date: :desc, created_at: :desc) }