fix(i18n): multi-syllable verb doubling and template caching
1. Add stressed-final-syllable verbs to irregularVerbs: - submit, permit, admit, omit, commit, transmit - prefer, refer, transfer, defer, confer, infer - occur, recur, incur, deter, control, patrol - compel, expel, propel, repel, rebel, excel 2. Add UK English -l doubling (cancel→cancelled, travel→travelled) 3. Add template caching to applyTemplate() matching executeIntentTemplate() for consistent performance. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
002f8c7813
commit
b4ed8a09f1
2 changed files with 44 additions and 5 deletions
|
|
@ -233,6 +233,37 @@ var irregularVerbs = map[string]VerbForms{
|
|||
"overwrite": {Past: "overwritten", Gerund: "overwriting"},
|
||||
"reset": {Past: "reset", Gerund: "resetting"},
|
||||
"reboot": {Past: "rebooted", Gerund: "rebooting"},
|
||||
|
||||
// Multi-syllable verbs with stressed final syllables (double consonant)
|
||||
"submit": {Past: "submitted", Gerund: "submitting"},
|
||||
"permit": {Past: "permitted", Gerund: "permitting"},
|
||||
"admit": {Past: "admitted", Gerund: "admitting"},
|
||||
"omit": {Past: "omitted", Gerund: "omitting"},
|
||||
"commit": {Past: "committed", Gerund: "committing"},
|
||||
"transmit": {Past: "transmitted", Gerund: "transmitting"},
|
||||
"prefer": {Past: "preferred", Gerund: "preferring"},
|
||||
"refer": {Past: "referred", Gerund: "referring"},
|
||||
"transfer": {Past: "transferred", Gerund: "transferring"},
|
||||
"defer": {Past: "deferred", Gerund: "deferring"},
|
||||
"confer": {Past: "conferred", Gerund: "conferring"},
|
||||
"infer": {Past: "inferred", Gerund: "inferring"},
|
||||
"occur": {Past: "occurred", Gerund: "occurring"},
|
||||
"recur": {Past: "recurred", Gerund: "recurring"},
|
||||
"incur": {Past: "incurred", Gerund: "incurring"},
|
||||
"deter": {Past: "deterred", Gerund: "deterring"},
|
||||
"control": {Past: "controlled", Gerund: "controlling"},
|
||||
"patrol": {Past: "patrolled", Gerund: "patrolling"},
|
||||
"compel": {Past: "compelled", Gerund: "compelling"},
|
||||
"expel": {Past: "expelled", Gerund: "expelling"},
|
||||
"propel": {Past: "propelled", Gerund: "propelling"},
|
||||
"repel": {Past: "repelled", Gerund: "repelling"},
|
||||
"rebel": {Past: "rebelled", Gerund: "rebelling"},
|
||||
"excel": {Past: "excelled", Gerund: "excelling"},
|
||||
"cancel": {Past: "cancelled", Gerund: "cancelling"}, // UK spelling
|
||||
"travel": {Past: "travelled", Gerund: "travelling"}, // UK spelling
|
||||
"label": {Past: "labelled", Gerund: "labelling"}, // UK spelling
|
||||
"model": {Past: "modelled", Gerund: "modelling"}, // UK spelling
|
||||
"level": {Past: "levelled", Gerund: "levelling"}, // UK spelling
|
||||
}
|
||||
|
||||
// PastTense returns the past tense of a verb.
|
||||
|
|
@ -298,6 +329,7 @@ func applyRegularPastTense(verb string) string {
|
|||
}
|
||||
|
||||
// noDoubleConsonant contains multi-syllable verbs that don't double the final consonant.
|
||||
// Note: UK English doubles -l (travelled, cancelled) - those are in irregularVerbs.
|
||||
var noDoubleConsonant = map[string]bool{
|
||||
"open": true,
|
||||
"listen": true,
|
||||
|
|
@ -314,11 +346,6 @@ var noDoubleConsonant = map[string]bool{
|
|||
"edit": true,
|
||||
"credit": true,
|
||||
"orbit": true,
|
||||
"cancel": true,
|
||||
"model": true,
|
||||
"travel": true,
|
||||
"label": true,
|
||||
"level": true,
|
||||
"total": true,
|
||||
"target": true,
|
||||
"budget": true,
|
||||
|
|
|
|||
|
|
@ -106,11 +106,23 @@ func applyTemplate(text string, data any) string {
|
|||
return text
|
||||
}
|
||||
|
||||
// Check cache first
|
||||
if cached, ok := templateCache.Load(text); ok {
|
||||
var buf bytes.Buffer
|
||||
if err := cached.(*template.Template).Execute(&buf, data); err != nil {
|
||||
return text
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// Parse and cache
|
||||
tmpl, err := template.New("").Parse(text)
|
||||
if err != nil {
|
||||
return text
|
||||
}
|
||||
|
||||
templateCache.Store(text, tmpl)
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := tmpl.Execute(&buf, data); err != nil {
|
||||
return text
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue