Add i18n framework with English and Chinese support

Introduce an embedded-locale i18n package exposing a T() template
function. UI strings across all templates and catalog category/item
names are now translatable via locale JSON files, selectable through
the new server.language config option. Falls back to English when a
locale is missing or fails to load.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
lucioandClaude Opus 4.6 committed 2026-05-21 21:30:56 -07:00
1 parent 5e82e32491
commit ff1d1fc490
16 files changed
+1161 -318

No files matched your search

+34 -34
View File
@@ -1,10 +1,10 @@
{{define "title"}}Solis | Locations{{end}}
{{define "title"}}{{T "app.title.locations"}}{{end}}
{{define "content"}}
<div class="page-header">
<div class="page-title">
<h1>Locations</h1>
<p>Define physical areas and hierarchical storage places (e.g., House > Kitchen > Drawer A)</p>
<h1>{{T "locations.title"}}</h1>
<p>{{T "locations.subtitle"}}</p>
</div>
</div>
@@ -14,7 +14,7 @@
{{end}}
<label style="display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; font-weight: 500; cursor: pointer; white-space: nowrap;">
<input type="checkbox" name="show_removed" value="1" {{if .ShowRemoved}}checked{{end}} onchange="this.form.submit()">
Show removed locations
{{T "locations.show_removed"}}
</label>
</form>
@@ -27,10 +27,10 @@
<table class="data-table">
<thead>
<tr>
<th>Name</th>
<th>Parent Path</th>
<th>Description</th>
<th style="width: 120px; text-align: right;">Actions</th>
<th>{{T "locations.col.name"}}</th>
<th>{{T "locations.col.parent"}}</th>
<th>{{T "common.description"}}</th>
<th style="width: 120px; text-align: right;">{{T "common.actions"}}</th>
</tr>
</thead>
<tbody>
@@ -40,7 +40,7 @@
<td style="font-weight: 600;">
<a href="/{{.Slug}}" style="color: var(--color-brand-primary); text-decoration: none;">{{.Name}}</a>
{{if eq .LifecycleState "archived"}}
<span class="status-pill archived" style="margin-left: 0.5rem; font-size: 0.7rem; padding: 0.1rem 0.4rem;">Archived</span>
<span class="status-pill archived" style="margin-left: 0.5rem; font-size: 0.7rem; padding: 0.1rem 0.4rem;">{{T "common.archived"}}</span>
{{end}}
</td>
<td>
@@ -49,52 +49,52 @@
{{.ParentName.String}} &rarr;
</span>
{{else}}
<span style="color: var(--color-text-light); font-size: 0.85rem;">Root</span>
<span style="color: var(--color-text-light); font-size: 0.85rem;">{{T "common.root"}}</span>
{{end}}
</td>
<td style="color: var(--color-text-muted); font-size: 0.9rem;">{{.Description}}</td>
<td class="actions-cell" style="text-align: right;">
<div style="display: inline-flex; gap: 0.5rem; align-items: center;">
{{if eq .ID 1}}
<span style="color: var(--color-text-light); font-size: 0.8rem; font-style: italic; padding: 0.35rem 0.65rem;">Locked</span>
<span style="color: var(--color-text-light); font-size: 0.8rem; font-style: italic; padding: 0.35rem 0.65rem;">{{T "common.locked"}}</span>
{{else if eq .LifecycleState "removed"}}
<!-- Soft removed actions -->
<form action="/admin/locations/restore/{{.ID}}" method="POST" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; border-color: #10b981; color: #10b981;">
Restore
{{T "common.restore"}}
</button>
</form>
<form action="/admin/locations/permanent-delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to permanently delete this location? Associated sub-locations and assets will be detached.')" style="margin: 0;">
<form action="/admin/locations/permanent-delete/{{.ID}}" method="POST" onsubmit="return confirm('{{T "locations.confirm_delete"}}')" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
Delete Forever
{{T "common.delete_forever"}}
</button>
</form>
{{else}}
<!-- Active / Archived actions -->
{{if ne .LifecycleState "archived"}}
<a href="/admin/locations?edit={{.ID}}&show_removed={{if $.ShowRemoved}}1{{else}}0{{end}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
Edit
{{T "common.edit"}}
</a>
{{end}}
<div class="actions-dropdown">
<button class="btn btn-danger" onclick="toggleActionsDropdown(this, event)" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 0.25rem;">
Delete <span style="font-size: 0.65rem;">▼</span>
{{T "common.delete"}} <span style="font-size: 0.65rem;">▼</span>
</button>
<div class="actions-dropdown-menu">
<form action="/admin/locations/remove/{{.ID}}" method="POST" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="actions-dropdown-item text-danger">
🗑 Remove
🗑 {{T "common.remove"}}
</button>
</form>
{{if ne .LifecycleState "archived"}}
<form action="/admin/locations/archive/{{.ID}}" method="POST" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="actions-dropdown-item text-warning">
📦 Archive
📦 {{T "common.archive"}}
</button>
</form>
{{end}}
@@ -108,7 +108,7 @@
{{else}}
<tr>
<td colspan="4" style="text-align: center; color: var(--color-text-light); padding: 3rem 1rem;">
No locations defined yet. Add one on the right to get started!
{{T "locations.empty"}}
</td>
</tr>
{{end}}
@@ -122,19 +122,19 @@
<div class="detail-sidebar">
<div class="card">
{{if .EditingLocation}}
<h3 style="font-weight: 700; margin-bottom: 1.25rem;">Edit Location</h3>
<h3 style="font-weight: 700; margin-bottom: 1.25rem;">{{T "locations.edit_location"}}</h3>
<form action="/admin/locations/edit/{{.EditingLocation.ID}}" method="POST">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<div class="form-group">
<label for="name" class="form-label">Location Name</label>
<label for="name" class="form-label">{{T "locations.location_name"}}</label>
<input type="text" id="name" name="name" class="form-control" value="{{.EditingLocation.Name}}" {{if eq .EditingLocation.ID 1}}readonly style="background-color: var(--color-bg-base); cursor: not-allowed;"{{end}} required>
</div>
<div class="form-group">
<label for="parent_id" class="form-label">Parent Location (Optional)</label>
<label for="parent_id" class="form-label">{{T "locations.parent_location"}}</label>
<select id="parent_id" name="parent_id" class="form-control">
<option value="">-- None (Root Location) --</option>
<option value="">{{T "locations.none_root"}}</option>
{{range $.Locations}}
{{if ne .ID $.EditingLocation.ID}}
<option value="{{.ID}}" {{if $.EditingLocation.ParentID.Valid}}{{if eq .ID $.EditingLocation.ParentID.Int64}}selected{{end}}{{end}}>
@@ -146,29 +146,29 @@
</div>
<div class="form-group" style="margin-bottom: 1.75rem;">
<label for="description" class="form-label">Description</label>
<label for="description" class="form-label">{{T "common.description"}}</label>
<textarea id="description" name="description" class="form-control" rows="3" placeholder="e.g. Red plastic storage box on shelf 2">{{.EditingLocation.Description}}</textarea>
</div>
<div style="display: flex; gap: 0.5rem;">
<button type="submit" class="btn btn-primary" style="flex-grow: 1;">Save Changes</button>
<a href="/admin/locations" class="btn btn-secondary">Cancel</a>
<button type="submit" class="btn btn-primary" style="flex-grow: 1;">{{T "common.save"}}</button>
<a href="/admin/locations" class="btn btn-secondary">{{T "common.cancel"}}</a>
</div>
</form>
{{else}}
<h3 style="font-weight: 700; margin-bottom: 1.25rem;">Create Location</h3>
<h3 style="font-weight: 700; margin-bottom: 1.25rem;">{{T "locations.create_location"}}</h3>
<form action="/admin/locations/new" method="POST">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<div class="form-group">
<label for="name" class="form-label">Location Name</label>
<label for="name" class="form-label">{{T "locations.location_name"}}</label>
<input type="text" id="name" name="name" class="form-control" placeholder="e.g. Living Room, Drawer B" required>
</div>
<div class="form-group">
<label for="parent_id" class="form-label">Parent Location (Optional)</label>
<label for="parent_id" class="form-label">{{T "locations.parent_location"}}</label>
<select id="parent_id" name="parent_id" class="form-control">
<option value="">-- None (Root Location) --</option>
<option value="">{{T "locations.none_root"}}</option>
{{range .Locations}}
<option value="{{.ID}}">{{.Name}}</option>
{{end}}
@@ -176,11 +176,11 @@
</div>
<div class="form-group" style="margin-bottom: 1.75rem;">
<label for="description" class="form-label">Description</label>
<label for="description" class="form-label">{{T "common.description"}}</label>
<textarea id="description" name="description" class="form-control" rows="3" placeholder="e.g. First floor living room cupboard"></textarea>
</div>
<button type="submit" class="btn btn-primary" style="width: 100%;">Add Location</button>
<button type="submit" class="btn btn-primary" style="width: 100%;">{{T "locations.add_location"}}</button>
</form>
{{end}}
</div>