Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
80 lines
3.0 KiB
Go
80 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"go/format"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
)
|
|
|
|
// Relative times: [style][unit][slot], long, short and narrow, with five
|
|
// words for offsets -2 to 2, then past and future patterns by plural form.
|
|
var relativeUnits = []string{"second", "minute", "hour", "day", "week", "month", "quarter", "year"}
|
|
|
|
const relativeUnitSlots = 5 + 2*6
|
|
|
|
// writeRelativeTables keeps relative times in a blob of their own, so
|
|
// apps that format dates or numbers alone link none of it.
|
|
func writeRelativeTables(out string, records []*localeRecord, parents []int, dates map[string][]byte) error {
|
|
values := make(map[*localeRecord][]string, len(records))
|
|
for _, r := range records {
|
|
var doc struct {
|
|
Main map[string]struct {
|
|
Dates struct {
|
|
Fields map[string]map[string]json.RawMessage `json:"fields"`
|
|
} `json:"dates"`
|
|
} `json:"main"`
|
|
}
|
|
if err := json.Unmarshal(dates["main/"+r.tag+"/dateFields.json"], &doc); err != nil {
|
|
return fmt.Errorf("%s dateFields.json: %v", r.tag, err)
|
|
}
|
|
fields := doc.Main[r.tag].Dates.Fields
|
|
v := make([]string, 3*len(relativeUnits)*relativeUnitSlots)
|
|
for style, suffix := range []string{"", "-short", "-narrow"} {
|
|
for unit, name := range relativeUnits {
|
|
field := fields[name+suffix]
|
|
base := (style*len(relativeUnits) + unit) * relativeUnitSlots
|
|
for offset := -2; offset <= 2; offset++ {
|
|
if raw := field["relative-type-"+strconv.Itoa(offset)]; raw != nil {
|
|
if err := json.Unmarshal(raw, &v[base+offset+2]); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
for dir, key := range []string{"past", "future"} {
|
|
var forms map[string]string
|
|
if err := json.Unmarshal(field["relativeTime-type-"+key], &forms); err != nil {
|
|
return fmt.Errorf("%s %s%s %s: %v", r.tag, name, suffix, key, err)
|
|
}
|
|
if forms["relativeTimePattern-count-other"] == "" {
|
|
return fmt.Errorf("%s %s%s %s has no other pattern", r.tag, name, suffix, key)
|
|
}
|
|
for form, category := range currencyPluralForms {
|
|
pattern := forms["relativeTimePattern-count-"+category]
|
|
if pattern == "" {
|
|
pattern = forms["relativeTimePattern-count-other"]
|
|
}
|
|
v[base+5+dir*6+form] = pattern
|
|
}
|
|
}
|
|
}
|
|
}
|
|
values[r] = v
|
|
}
|
|
var b bytes.Buffer
|
|
fmt.Fprintf(&b, "// Code generated by go generate (i18n/internal/gen) from CLDR %s. DO NOT EDIT.\n\npackage i18n\n\n", cldrVersion)
|
|
fmt.Fprintf(&b, "// Relative times: [style][unit], five words then six past and six future forms.\nconst relativeUnitSlots = %d\nconst relativeSlotCount = %d\n\n", relativeUnitSlots, 3*len(relativeUnits)*relativeUnitSlots)
|
|
sections := recordSections(records, parents, 3*len(relativeUnits)*relativeUnitSlots, func(r *localeRecord) []string { return values[r] }, "Relative", "relative times")
|
|
if err := writePacked(&b, "fmtPackedRelative", "the relative times of the locales", sections); err != nil {
|
|
return err
|
|
}
|
|
src, err := format.Source(b.Bytes())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return os.WriteFile(filepath.Join(out, "relative_tables.go"), src, 0o644)
|
|
}
|