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

@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
// Airport code field with suggestions from the airport database.
// <div data-controller="airport-autocomplete" data-airport-autocomplete-url-value="/airports/search?aircraft_id=1">
@@ -108,7 +109,7 @@ export default class extends Controller {
const code = this.inputTarget.value.trim().toUpperCase()
const match = this.results.find((a) => a.code === code || (a.aka || []).includes(code))
if (match) this.setHint(this.describeAirport(match))
else if (code.length >= 2 && code.length <= 4 && !code.includes(" ")) this.setHint("Not in the airport database", true)
else if (code.length >= 2 && code.length <= 4 && !code.includes(" ")) this.setHint(t("airports.not_found"), true)
else this.setHint("")
}
@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
import { DirectUpload } from "@rails/activestorage"
// Bulk document upload. Picked files (or a whole folder) are listed with an
@@ -53,7 +54,7 @@ export default class extends Controller {
defaultName(item) {
const parts = item.path.split("/")
if (this.groupTarget.checked && parts.length > 1) return parts[parts.length - 2]
return parts[parts.length - 1].replace(/\.[^.]+$/, "").replace(/_/g, " ").replace(/\s+/g, " ").trim() || "Untitled"
return parts[parts.length - 1].replace(/\.[^.]+$/, "").replace(/_/g, " ").replace(/\s+/g, " ").trim() || t("bulk_upload.untitled")
}
render() {
@@ -72,7 +73,7 @@ export default class extends Controller {
name.type = "text"
name.className = "input"
name.value = item.name
name.setAttribute("aria-label", `Document name for ${item.path}`)
name.setAttribute("aria-label", t("bulk_upload.name_for", { path: item.path }))
name.disabled = this.uploading
name.addEventListener("input", () => { item.name = name.value; item.custom = true; this.updateSummary() })
@@ -90,7 +91,7 @@ export default class extends Controller {
remove.type = "button"
remove.className = "btn-secondary btn-sm"
remove.textContent = "✕"
remove.setAttribute("aria-label", `Remove ${item.path}`)
remove.setAttribute("aria-label", t("bulk_upload.remove", { path: item.path }))
remove.disabled = this.uploading
remove.addEventListener("click", () => { this.items.splice(index, 1); this.render() })
@@ -109,9 +110,9 @@ export default class extends Controller {
updateSummary() {
const files = this.items.length
const docs = new Set(this.items.map((item) => item.name.trim() || "Untitled")).size
const docs = new Set(this.items.map((item) => item.name.trim() || t("bulk_upload.untitled"))).size
this.summaryTarget.textContent = `${files} ${files === 1 ? "file" : "files"} → ${docs} ${docs === 1 ? "document" : "documents"}`
this.submitTarget.textContent = files ? `Upload ${docs} ${docs === 1 ? "document" : "documents"}` : "Upload"
this.submitTarget.textContent = files ? t("bulk_upload.upload_count", { count: docs }) : t("bulk_upload.upload")
}
size(bytes) {
@@ -124,9 +125,9 @@ export default class extends Controller {
if (this.ready) return
event.preventDefault()
if (this.uploading) return
if (this.items.length === 0) return this.say("Choose some files to upload.")
if (this.items.length === 0) return this.say(t("bulk_upload.choose_files"))
if (this.items.some((item) => item.file.size > this.maxBytesValue)) {
return this.say("Remove the files marked in red first.")
return this.say(t("bulk_upload.remove_red"))
}
this.items.forEach((item) => { if (item.state === "error") item.state = "pending" })
@@ -134,11 +135,11 @@ export default class extends Controller {
const queue = this.items.filter((item) => item.state === "pending")
const total = queue.length
let finished = 0
this.say(`Uploading 0 of ${total}…`)
this.say(t("bulk_upload.uploading", { done: 0, total }))
const worker = async () => {
for (let item = queue.shift(); item; item = queue.shift()) {
await this.upload(item)
this.say(`Uploading ${++finished} of ${total}…`)
this.say(t("bulk_upload.uploading", { done: ++finished, total }))
}
}
await Promise.all([ worker(), worker(), worker() ])
@@ -156,7 +157,7 @@ export default class extends Controller {
}
this.uploading = false
this.ready = true
this.say("Saving…")
this.say(t("bulk_upload.saving"))
// When nothing was left to upload this all ran inside the click's submit
// event, during which the browser ignores requestSubmit, so wait a tick.
setTimeout(() => this.element.requestSubmit())
@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
// Interactive viewer for engine monitor charts. Clicking a chart opens it large
// with higher-resolution data (fetched once, on first open): a crosshair shows
@@ -35,7 +36,7 @@ export default class extends Controller {
this.render()
} catch (error) {
this.statusTarget.hidden = false
this.statusTarget.textContent = `Couldn't load the engine data (${error.message}).`
this.statusTarget.textContent = t("engine.load_failed", { message: error.message })
}
}
@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
// Fills a new logbook entry from a template: the wording, and when the
// template sets them, the entry type, the logbook (which also picks the
@@ -9,7 +10,7 @@ export default class extends Controller {
apply() {
const option = this.templateTarget.selectedOptions[0]
if (!option?.dataset.text) return
if (this.textTarget.value.trim() && !confirm("Replace the entry text with this template?")) return
if (this.textTarget.value.trim() && !confirm(t("entry_template.confirm"))) return
const { text, entryType, logType, certificate } = option.dataset
this.textTarget.value = text
if (entryType && this.hasEntryTypeTarget) this.entryTypeTarget.value = entryType
@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
// Fills a textarea with suggested text (asks before replacing what's there).
export default class extends Controller {
@@ -8,7 +9,7 @@ export default class extends Controller {
insert(event) {
event.preventDefault()
const field = this.fieldTarget
if (field.value.trim() && !confirm("Replace what's in the box with the suggested text?")) return
if (field.value.trim() && !confirm(t("insert_text.confirm"))) return
field.value = this.textValue
field.focus()
field.setSelectionRange(0, 0)
@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
// Write / Preview tabs for a Markdown textarea. The preview is rendered by the
// server, with the same Markdown rules and sanitizing as the saved note.
@@ -17,7 +18,7 @@ export default class extends Controller {
async preview() {
this.select(true)
this.outputTarget.textContent = "Loading preview…"
this.outputTarget.textContent = t("markdown.loading")
const token = document.querySelector("meta[name=csrf-token]")?.content
try {
const response = await fetch(this.urlValue, {
@@ -29,7 +30,7 @@ export default class extends Controller {
if (!response.ok) throw new Error(`HTTP ${response.status}`)
this.outputTarget.innerHTML = await response.text() // sanitized server-side
} catch (error) {
this.outputTarget.textContent = `Couldn't load the preview (${error.message}).`
this.outputTarget.textContent = t("markdown.load_failed", { message: error.message })
}
}
@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
import { nextDue, describeDue } from "next_due"
// Live next-due preview (and prefill of an AD's next-due tach reading) from
@@ -40,12 +41,12 @@ export default class extends Controller {
if (!this.hasPreviewTarget) return
const rule = this.currentRule
let text
if (this.isPermanent) text = "Permanent compliance or not applicable: never due again."
if (this.isPermanent) text = t("next_due.permanent")
else if (!this.ruleTarget.value) text = ""
else if (!rule) text = "One-time: no recurring due date."
else if (!rule) text = t("next_due.one_time")
else {
if (this.hasDueHoursTarget && this.manual) due = { ...due, hours: parseFloat(this.dueHoursTarget.value) }
text = describeDue(due) ? `Next due: ${describeDue(due)}` : "Enter the date and hours to calculate the next due."
text = describeDue(due) ? t("next_due.next_due", { due: describeDue(due) }) : t("next_due.enter")
}
this.previewTarget.textContent = text
this.previewTarget.hidden = text === ""
@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
import { queue, formFields, newKey } from "controllers/offline_queue"
// The Log Flight form: with no connection, the flight is kept on this device
@@ -48,7 +49,7 @@ export default class extends Controller {
try {
await queue.add(item)
} catch (_) {
this.say("No connection, and this browser can't store the flight. Write it down and log it when you're back online.")
this.say(t("offline.no_storage"))
return
}
this.prefillFrom(item)
@@ -56,7 +57,7 @@ export default class extends Controller {
this.keyTarget.value = newKey()
this.pending = null
window.scrollTo({ top: 0 })
this.say("No connection: flight saved on this device. It's sent automatically when you're back online. Log the next leg below, or close the app.")
this.say(t("offline.saved_on_device"))
document.dispatchEvent(new CustomEvent("offline-queue:changed"))
}
@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
import { queue } from "controllers/offline_queue"
// On every page: sends flights logged offline once there's a connection, and
@@ -29,7 +30,7 @@ export default class extends Controller {
for (const item of items.filter((i) => !i.error)) {
const result = await this.send(item)
if (result === "sent") { await queue.remove(item.id); sent++ }
else if (result === "signin") { this.show("Sign in to send the flights logged offline."); return }
else if (result === "signin") { this.show(t("offline.sign_in")); return }
else if (result === "offline") break
else { item.error = result; await queue.put(item) }
}
@@ -52,15 +53,15 @@ export default class extends Controller {
const html = await response.text()
const doc = new DOMParser().parseFromString(html, "text/html")
const message = [ ...doc.querySelectorAll("[role=alert], .field-error") ].map((e) => e.textContent.trim()).filter(Boolean).join(" ")
return message || `Not accepted (${response.status}).`
return message || t("offline.not_accepted", { status: response.status })
}
status(items, sent = 0) {
const failed = items.filter((i) => i.error)
const waiting = items.length - failed.length
const parts = []
if (sent) parts.push(`Sent ${sent} flight${sent > 1 ? "s" : ""} logged offline.`)
if (waiting) parts.push(`${waiting} flight${waiting > 1 ? "s" : ""} logged offline waiting for a connection.`)
if (sent) parts.push(t("offline.sent", { count: sent }))
if (waiting) parts.push(t("offline.waiting", { count: waiting }))
this.show(parts.join(" "), failed)
}
@@ -72,7 +73,7 @@ export default class extends Controller {
const date = (item.fields.find(([ n ]) => n === "flight_log[date]") || [])[1] || ""
const row = document.createElement("p")
row.textContent = `${item.tail} flight ${date} logged offline wasn't accepted: ${item.error} `
const discard = Object.assign(document.createElement("button"), { type: "button", textContent: "Discard", className: "btn-secondary btn-sm ml-1" })
const discard = Object.assign(document.createElement("button"), { type: "button", textContent: t("offline.discard"), className: "btn-secondary btn-sm ml-1" })
discard.addEventListener("click", async () => { await queue.remove(item.id); this.sync() })
row.append(discard)
banner.append(row)
@@ -1,7 +1,7 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
const CHOICES = ["system", "light", "dark"]
const LABELS = { system: "System", light: "Light", dark: "Dark" }
// Light / dark / follow-the-OS theme toggle. The choice is kept in
// localStorage; the layout's inline script applies it before first paint.
@@ -40,7 +40,7 @@ export default class extends Controller {
this.element.querySelectorAll("[data-theme-icon]").forEach((icon) => {
icon.classList.toggle("hidden", icon.dataset.themeIcon !== choice)
})
const label = `Theme: ${LABELS[choice]}${choice === "system" ? ` (${theme})` : ""}`
const label = choice === "system" ? t("theme.system", { theme: t(`theme.${theme}`) }) : t("theme.label", { choice: t(`theme.${choice}`) })
this.element.title = label
this.element.setAttribute("aria-label", label)
if (changed) window.dispatchEvent(new CustomEvent("theme:change", { detail: { theme } }))
@@ -1,4 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { t } from "i18n"
// Loading calculator: takeoff and landing weight and CG from the empty
// weight & moment plus each station's load, checked against max gross weight,
@@ -42,19 +43,19 @@ export default class extends Controller {
this.show("landing", landing)
if (!loaded) {
this.messagesTarget.replaceChildren(Object.assign(document.createElement("li"), { className: "text-slate-500", textContent: "Enter the loading to check weight and CG." }))
this.messagesTarget.replaceChildren(Object.assign(document.createElement("li"), { className: "text-slate-500", textContent: t("wb.enter_loading") }))
this.draw(takeoff, landing)
return
}
if (this.maxGrossValue && takeoff.weight > this.maxGrossValue) {
messages.push([ "bad", `Takeoff weight is ${(takeoff.weight - this.maxGrossValue).toFixed(1)} lb over the maximum of ${this.maxGrossValue} lb.` ])
messages.push([ "bad", t("wb.over_gross", { over: (takeoff.weight - this.maxGrossValue).toFixed(1), max: this.maxGrossValue }) ])
}
if (this.envelopeValue.length >= 3) {
for (const [ name, point ] of [ [ "Takeoff", takeoff ], [ "Landing", landing ] ]) {
if (!this.inside(point)) messages.push([ "bad", `${name} CG ${point.cg.toFixed(2)} in at ${point.weight.toFixed(0)} lb is outside the envelope.` ])
for (const [ name, point ] of [ [ t("wb.takeoff"), takeoff ], [ t("wb.landing"), landing ] ]) {
if (!this.inside(point)) messages.push([ "bad", t("wb.outside", { name, cg: point.cg.toFixed(2), weight: point.weight.toFixed(0) }) ])
}
}
if (!messages.length) messages.push([ "ok", "Within the limits entered here." ])
if (!messages.length) messages.push([ "ok", t("wb.within_limits") ])
this.messagesTarget.replaceChildren(...messages.map(([ kind, text ]) => {
const li = document.createElement("li")
li.className = kind === "ok" ? "text-emerald-700" : "text-red-700"
+22
View File
@@ -0,0 +1,22 @@
// Strings for the page's scripts: the "js" keys of config/locales, which the
// layout puts in <script type="application/json" id="i18n">.
// t("bulk_upload.uploading", { done: 1, total: 4 })
// t("offline.sent", { count: 2 }) // one/other plurals pick by count
let strings
function load() {
if (!strings) {
try { strings = JSON.parse(document.getElementById("i18n")?.textContent || "{}") } catch { strings = {} }
}
return strings
}
export function t(key, vars = {}) {
let value = key.split(".").reduce((node, part) => node?.[part], load())
if (value && typeof value === "object") value = value[vars.count === 1 ? "one" : "other"]
if (typeof value !== "string") return key
return value.replace(/%\{(\w+)\}/g, (_, name) => vars[name] ?? "")
}
// The page's language, for number and date formatting.
export const locale = () => document.documentElement.lang || "en"
+5 -3
View File
@@ -1,3 +1,5 @@
import { t, locale } from "i18n"
// Next-due math, mirroring Compliance.next_due in app/services/compliance.rb:
// months land on the END of the month, then days are added; hours are added
// to the hours at completion. Dates are "YYYY-MM-DD" strings (no timezones).
@@ -24,11 +26,11 @@ export function nextDue(rule, dateStr, hours) {
export function describeDue(due) {
const parts = []
if (due.hours != null) parts.push(`${due.hours.toLocaleString("en-US", { minimumFractionDigits: 1, maximumFractionDigits: 1 })} tach`)
if (due.hours != null) parts.push(t("next_due.tach", { hours: due.hours.toLocaleString(locale(), { minimumFractionDigits: 1, maximumFractionDigits: 1 }) }))
if (due.date) {
const [y, mo, d] = due.date.split("-").map(Number)
parts.push(new Date(y, mo - 1, d).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" }))
parts.push(new Date(y, mo - 1, d).toLocaleDateString(locale(), { month: "short", day: "numeric", year: "numeric" }))
}
if (parts.length === 0) return ""
return parts.length > 1 ? `${parts.join(" or ")}, whichever comes first` : parts[0]
return parts.length > 1 ? t("next_due.either", { first: parts[0], second: parts[1] }) : parts[0]
}