Documentation
¶
Overview ¶
Package languages implements content languages (design expansion M17): the workspace's languages with its default and fallback, the language versions of campaigns, automation emails and transactional templates (statuses, block tracking, compare), which version each recipient gets, the Languages group of Send Readiness and results per language.
Other packages build on it through a small API:
- Lookup, Normalize and Base work with language codes ("Spanish", "es_MX" and "ES" normalize to es and es-MX).
- Service.Settings returns a workspace's languages, default and fallback; Settings.Offers says whether a contact's language is one of them.
- Service.SetPageCopy records the status of a language's page copy (forms and public pages own the copy itself).
- Chooser picks the version a contact gets.
Index ¶
- Constants
- Variables
- func Align(before, after []AlignKey) []int
- func Base(code string) string
- func Compare(source []Block, keys []SourceBlock, version []Block, links Links, draft bool, ...) ([]Row, Progress)
- func HashText(s string) string
- func NameIn(l i18n.Lang, code string) string
- func NameOf(code string) string
- func Normalize(raw string) (string, bool)
- func Register(h huma.API, s *Service)
- func Suggest(raw string) string
- type AddLanguageInput
- type AddWorkspaceLanguage
- type AgentEdit
- type AgentSaved
- type AlignKey
- type ApplyInput
- type ApplyResult
- type AutomationEmailLanguage
- type AutomationEmailLanguagePath
- type AutomationEmailPath
- type AutomationEmailState
- type AutomationLanguageMark
- type AutomationLanguageSave
- type AutomationLanguageSaved
- type Block
- type BlockChange
- type BlockInput
- type BlockLink
- type BlockRef
- type BlockSegment
- type BlockSnapshot
- type CampaignLanguagePath
- type CampaignPath
- type Campaigns
- func (c Campaigns) Choose(ctx context.Context, ws *store.Workspace, id uuid.UUID, contactLanguage string) (string, string, error)
- func (c Campaigns) Content(ctx context.Context, ws *store.Workspace, id uuid.UUID, lang string) (campaigns.TranslationContent, error)
- func (c Campaigns) Ready(ctx context.Context, ws *store.Workspace, id uuid.UUID) ([]string, error)
- func (c Campaigns) Save(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (campaigns.ComposerSavedContent, error)
- func (c Campaigns) SourceLanguage(ctx context.Context, ws *store.Workspace, id uuid.UUID) (string, error)
- type CatalogLanguage
- type Choice
- type Chooser
- type CompareBlock
- type CompareRow
- type CompareText
- type EmailLanguage
- type EmailLanguages
- type FallbackImpact
- type HoldInput
- type ImportedVersion
- type KeepUpToDateInput
- type Language
- type LanguageCatalogList
- type LanguageCompare
- type LanguageDefaults
- type LanguagePageCopy
- type LanguageRemoval
- type LanguageSourceChange
- type Link
- type Links
- type MarkInput
- type Owner
- type PreviewContact
- type PreviewContactList
- type Progress
- type ReadinessFacts
- type ReadinessLanguage
- type ReadinessVersion
- type RemovalItem
- type ReportLanguageCount
- type ReportLanguageDraft
- type ReportLanguageFallback
- type ReportLanguageOption
- type ReportLanguageRow
- type ReportLanguages
- type Row
- type SaveInput
- type Saved
- type SendSet
- type SendVersion
- type Service
- func (s *Service) AddCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (EmailLanguages, error)
- func (s *Service) AddLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, code string) (WorkspaceLanguages, error)
- func (s *Service) AddTemplateLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref string, ...) (EmailLanguages, error)
- func (s *Service) AgentSaveCampaign(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (AgentSaved, error)
- func (s *Service) ApplyCampaignChange(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (ApplyResult, error)
- func (s *Service) AutomationEmailLanguageContent(ctx context.Context, ws *store.Workspace, id uuid.UUID, version int, ...) (AutomationEmailLanguage, error)
- func (s *Service) AutomationEmailLanguages(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (EmailLanguages, error)
- func (s *Service) AutomationEmailStates(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID, ...) ([]AutomationEmailState, error)
- func (s *Service) AutomationSendSet(ctx context.Context, wsID, emailID uuid.UUID, version int) (SendSet, error)
- func (s *Service) CampaignDigest(ctx context.Context, q *store.Queries, wsID, campaignID uuid.UUID) string
- func (s *Service) CampaignHistory(ctx context.Context, ws *store.Workspace, id uuid.UUID, lang string, limit int) (campaigns.ComposerVersionList, error)
- func (s *Service) CampaignLanguages(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (EmailLanguages, error)
- func (s *Service) CampaignPreviewContacts(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (PreviewContactList, error)
- func (s *Service) CampaignReadiness(ctx context.Context, ws *store.Workspace, id uuid.UUID, ...) (ReadinessFacts, error)
- func (s *Service) CampaignResults(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID, ...) (*ReportLanguages, error)
- func (s *Service) CampaignSendSet(ctx context.Context, wsID, campaignID uuid.UUID) (SendSet, error)
- func (s *Service) CampaignSnapshot(ctx context.Context, q *store.Queries, campaignID uuid.UUID) ([]VersionSnapshot, error)
- func (s *Service) CampaignVersionAt(ctx context.Context, campaignID uuid.UUID, lang string, version int) (VersionContent, error)
- func (s *Service) ClickMapVersion(ctx context.Context, campaignID uuid.UUID, lang string) (html string, from, to int, ok bool)
- func (s *Service) CompareCampaign(ctx context.Context, ws *store.Workspace, id uuid.UUID, lang string) (LanguageCompare, error)
- func (s *Service) CopyBlockToCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (LanguageCompare, error)
- func (s *Service) CopyForward(ctx context.Context, q *store.Queries, wsID, id uuid.UUID, from, to int) error
- func (s *Service) FallbackPreview(ctx context.Context, ws *store.Workspace, code string) (FallbackImpact, error)
- func (s *Service) HoldCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (EmailLanguages, error)
- func (s *Service) ImportVersion(ctx context.Context, q *store.Queries, in ImportedVersion) error
- func (s *Service) KeepCampaignUpToDate(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (EmailLanguages, error)
- func (s *Service) LanguageCatalog(ctx context.Context, ws *store.Workspace, query string) ([]CatalogLanguage, error)
- func (s *Service) List(ctx context.Context, ws *store.Workspace, p *authz.Principal) (WorkspaceLanguages, error)
- func (s *Service) MarkAutomationEmailLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (AutomationLanguageSaved, error)
- func (s *Service) MarkCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (EmailLanguages, error)
- func (s *Service) MarkTemplateLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref, lang string, ...) (EmailLanguages, error)
- func (s *Service) Removal(ctx context.Context, ws *store.Workspace, code string) (LanguageRemoval, error)
- func (s *Service) RemoveAutomationEmailLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (AutomationLanguageSaved, error)
- func (s *Service) RemoveBlockFromCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (LanguageCompare, error)
- func (s *Service) RemoveCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (EmailLanguages, error)
- func (s *Service) RemoveLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, code string) (WorkspaceLanguages, error)
- func (s *Service) RemoveTemplateLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref, lang string) (EmailLanguages, error)
- func (s *Service) SaveAutomationEmailLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (AutomationLanguageSaved, error)
- func (s *Service) SetCampaignSource(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (EmailLanguages, error)
- func (s *Service) SetDefaults(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (WorkspaceLanguages, error)
- func (s *Service) SetPageCopy(ctx context.Context, q *store.Queries, wsID uuid.UUID, code, status string, ...) error
- func (s *Service) Settings(ctx context.Context, q *store.Queries, wsID uuid.UUID) (Settings, error)
- func (s *Service) TemplateLanguages(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref string) (EmailLanguages, error)
- type Settings
- type Source
- type SourceBlock
- type SourceInput
- type TemplateLanguagePath
- type TemplatePath
- type Transactional
- func (t Transactional) Changes(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID, ...) ([]transactional.TransactionalLanguageChange, error)
- func (t Transactional) Choose(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID, ...) (transactional.LanguageChoice, error)
- func (t Transactional) Draft(ctx context.Context, ws *store.Workspace, id uuid.UUID, lang string) (transactional.TranslationDraft, error)
- func (t Transactional) Publish(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID, ...) error
- func (t Transactional) Publishing(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID) ([]transactional.TransactionalPublishLanguage, error)
- func (t Transactional) Record(ctx context.Context, q *store.Queries, messageID uuid.UUID, ...) error
- func (t Transactional) SaveDraft(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (transactional.TransactionalDraftSaved, error)
- func (t Transactional) SourceLanguage(ctx context.Context, ws *store.Workspace, id uuid.UUID) (string, error)
- type VersionChange
- type VersionChangeDetail
- type VersionContent
- type VersionSnapshot
- type VersionState
- type WorkspaceLanguage
- type WorkspaceLanguages
Constants ¶
const ( // ReasonMatch: the version in their language. ReasonMatch = "match" // ReasonNoLanguage: the contact has no language. ReasonNoLanguage = "no_language" // ReasonNotOffered: the workspace doesn't offer their language. ReasonNotOffered = "not_offered" // ReasonMissing: the email has no version in their language. ReasonMissing = "missing" // ReasonDraft: the version in their language is a draft. ReasonDraft = "draft" // ReasonHeld: the version is held ("Send English to them instead"). ReasonHeld = "held" // ReasonRequested: the API asked for a language (transactional sends). ReasonRequested = "requested" )
Reasons a reader gets the version they get (messages.language_reason).
const ( StatusSource = "source" StatusUpToDate = "up_to_date" StatusOutdated = "outdated" StatusDraft = "draft" StatusMissing = "missing" )
Translation statuses of a language version.
const ( RowUpToDate = "up_to_date" RowChanged = "changed" RowStill = "still" RowNew = "new" RowRemoved = "removed" RowOnly = "only" )
Row states of the compare view.
const ( OwnerCampaign = "campaign" OwnerAutomationEmail = "automation_email" OwnerTransactional = "transactional_template" )
Owner kinds: what a language version belongs to.
const ( StartCopy = "copy" StartLayout = "layout" )
LanguageStart is what a new language version starts from.
Variables ¶
var BuiltinLabels = map[string]bool{"en": true, "de": true, "es": true, "fr": true, "vi": true}
BuiltinLabels lists the languages ReputeCast's own page labels (buttons, field labels, messages, the confirmation email) ship in: the languages the app is translated into.
Functions ¶
func Align ¶
Align matches the blocks of an earlier version of a document to a later one, so a block keeps its identity while it is edited or moved. Blocks are matched in three passes:
- identical blocks, in order (the longest common subsequence of the exact fingerprints), then identical blocks that moved;
- between two matched neighbours, blocks whose translatable text is the same (a style or link change);
- what is left between the same neighbours, in order: a block edited in place.
It returns, for each later block, the index of the earlier block it continues, or -1 for a new block. Earlier blocks no later block continues were removed.
func Base ¶
Base returns the base language of a code: "es-MX" and "es_mx" give "es". It returns "" for an empty code.
func Compare ¶
func Compare(source []Block, keys []SourceBlock, version []Block, links Links, draft bool, subjectHash, preheaderHash string) ([]Row, Progress)
Compare lines a version up with its source block by block and computes its status. source and keys describe the current source (same length); version are the version's blocks and links what they were translated from.
func NameIn ¶
NameIn names a language in a reader's language, as a label: "Spanish", "Tiếng Tây Ban Nha". English readers (and the pseudo-locale) get the catalog's English name, NameOf. Other readers get the names the app uses elsewhere (accessibility.LanguageNameIn), else CLDR's, as browsers name languages; a code the catalog doesn't have is named by its code.
func Normalize ¶
Normalize turns what a form, an import or the API sends into a BCP 47 code: "Spanish", "español", "es_MX", "ES" and "es-mx" become "es" or "es-MX". Regional and script subtags are kept ("zh-Hant-TW"). It reports false for values it can't read as a language; an empty value is valid and stays empty (the contact has no language).
Types ¶
type AddLanguageInput ¶
type AddLanguageInput struct {
Language string `json:"language" pattern:"^[a-z]{2,3}$" doc:"A workspace language"`
// Start is "copy" (the source's layout and text) or "layout" (text
// blocks start empty).
Start string `json:"start,omitempty" enum:"copy,layout" default:"copy"`
}
AddLanguageInput adds a language version to an email.
type AddWorkspaceLanguage ¶
type AddWorkspaceLanguage struct {
Code string `json:"code" pattern:"^[a-z]{2,3}$" doc:"A base language code, such as fr"`
}
AddWorkspaceLanguage adds a language to the workspace.
type AgentEdit ¶
AgentEdit is an MCP agent's change to a language version: fields left nil stay as they are.
type AgentSaved ¶
type AgentSaved struct {
Language string
Version int
Subject string
// Before are the subject and preheader before the change.
BeforeSubject string
BeforePreheader string
BeforeVersion int
}
AgentSaved is what an agent's change produced.
type ApplyInput ¶
type ApplyInput struct {
Kind string `json:"kind" enum:"link,image"`
From string `json:"from" minLength:"1" maxLength:"4000"`
To string `json:"to" minLength:"1" maxLength:"4000"`
// Block is the source block's key; empty applies it anywhere it appears.
Block string `json:"block,omitempty" maxLength:"32"`
}
ApplyInput copies a link or image change of the source into the language versions ("Apply to all languages").
type ApplyResult ¶
ApplyResult says which versions changed.
type AutomationEmailLanguage ¶
type AutomationEmailLanguage struct {
Language string `json:"language"`
Name string `json:"name"`
Status string `json:"status" enum:"up_to_date,outdated,draft"`
Version int `json:"version"`
Subject string `json:"subject"`
Preheader string `json:"preheader"`
HTML string `json:"html"`
}
AutomationEmailLanguage is one language version of an automation email version, to edit.
type AutomationEmailLanguagePath ¶
type AutomationEmailLanguagePath struct {
AutomationEmailPath
Language string `path:"language" pattern:"^[a-z]{2,3}$"`
}
AutomationEmailLanguagePath adds a {language}.
type AutomationEmailPath ¶
type AutomationEmailPath struct {
api.WorkspaceInput
EmailID string `path:"id" format:"uuid"`
}
AutomationEmailPath is {workspace}/automation-emails/{id}.
type AutomationEmailState ¶
type AutomationEmailState struct {
Language string
Name string
Status string // up_to_date, outdated, draft
// Attention counts the blocks to look at when it's outdated.
Attention int
By string
Held bool
}
AutomationEmailState is a language version of an automation email version, as the publish dialog names it.
type AutomationLanguageMark ¶
type AutomationLanguageMark struct {
Version int `json:"version" minimum:"1"`
}
AutomationLanguageMark names the email version whose language version is marked.
type AutomationLanguageSave ¶
type AutomationLanguageSave struct {
// Version is the email version the step sends; saving makes the next.
Version int `json:"version" minimum:"1"`
Subject string `json:"subject" minLength:"1" maxLength:"998"`
Preheader string `json:"preheader,omitempty" maxLength:"500"`
HTML string `json:"html" minLength:"1" maxLength:"524288"`
// Translated marks it translated, so it is sent.
Translated bool `json:"translated,omitempty"`
}
AutomationLanguageSave is a language version written in the flow editor.
type AutomationLanguageSaved ¶
type AutomationLanguageSaved struct {
Version int `json:"version"`
Languages EmailLanguages `json:"languages"`
}
AutomationLanguageSaved is the email's new version and its languages.
type Block ¶
type Block struct {
Index int `json:"index"`
// Tag is the MJML element ("mj-section").
Tag string `json:"tag"`
// Label is how the layer tree names it ("header", "2 columns", "text").
Label string `json:"label"`
// Name says what it is in the compare view ("Header · logo and links",
// "Hero image", "Two cards").
Name string `json:"name"`
// Heading is the highest heading level inside (1–3), 0 without one.
Heading int `json:"heading"`
Segments []BlockSegment `json:"segments"`
// Hash fingerprints what is translated (texts, labels, alt texts):
// style and link changes don't make a translation outdated.
Hash string `json:"-"`
// Raw fingerprints the block's whole source, to match blocks between
// versions.
Raw string `json:"-"`
// Text is a readable summary of the block, columns on their own lines.
Text string `json:"text"`
// Start and End are the block's byte range in the source.
Start int `json:"-"`
End int `json:"-"`
// contains filtered or unexported fields
}
Block is one top-level block of an email: a section of <mj-body>, the unit translations are tracked by. A block of an HTML-only email is the whole email.
type BlockChange ¶
type BlockChange struct {
Version int `json:"version"`
By string `json:"by"`
At time.Time `json:"at"`
}
BlockChange says which source version changed a block, who and when.
type BlockInput ¶
type BlockInput struct {
// Key is the source block's key (Copy into …).
Key string `json:"key,omitempty" maxLength:"32"`
// Index is the language version's block position (Remove from …).
Index *int `json:"index,omitempty" minimum:"0"`
}
BlockInput names a block of the compare view.
type BlockLink ¶
type BlockLink struct {
// Src is the source block's key; empty for a block only this version has.
Src string `json:"src,omitempty"`
Hash string `json:"hash,omitempty"`
Text string `json:"text,omitempty"`
Version int `json:"version,omitempty"`
// Own and OwnRaw fingerprint the version's own block, to keep the link
// when the version is saved again.
Own string `json:"own"`
OwnRaw string `json:"ownRaw"`
}
BlockLink ties a block of a language version to its source block.
type BlockRef ¶
type BlockRef struct {
Kind string `json:"kind"`
Count int `json:"count,omitempty"`
Words string `json:"words,omitempty"`
Label string `json:"label,omitempty"`
Heading int `json:"heading,omitempty"`
}
BlockRef says what a block is, so it can be named in any language: its kind (header, headerLinks, footer, raw, social, cards, columns, hero, image, heroImage, button, headline, intro, text, email, other) and what its name needs: a column count, the first words of its text, the MJML label of an unusual block, its highest heading.
type BlockSegment ¶
type BlockSegment struct {
// Path is the element index path from the block element.
Path []int `json:"path"`
// Kind is text, button, image, social, nav, raw or table.
Kind string `json:"kind"`
// Text is the plain text, Liquid kept ("Hi {{ first_name | default: "there" }}").
Text string `json:"text"`
// HTML is the inner HTML of a text, to edit it with its links.
HTML string `json:"html,omitempty"`
// Strong marks a title (bold or a heading) shown in bold in the compare view.
Strong bool `json:"strong"`
// Column is the column the segment sits in (columns are shown on their own lines).
Column int `json:"column"`
Heading int `json:"heading"`
URL string `json:"url,omitempty"`
Alt string `json:"alt,omitempty"`
}
BlockSegment is one piece of a block a translator reads or writes: a text, a button label, an image's alt text.
type BlockSnapshot ¶
type BlockSnapshot struct {
Name string `json:"name"`
Hash string `json:"hash"`
Raw string `json:"raw"`
// Ref says what the block is, to name it in any language; snapshots
// taken before it was kept have none (their English Name is used).
Ref *BlockRef `json:"ref,omitempty"`
}
BlockSnapshot is one block of a version at approval time.
type CampaignLanguagePath ¶
type CampaignLanguagePath struct {
CampaignPath
Language string `path:"language" pattern:"^[a-z]{2,3}$"`
}
CampaignLanguagePath adds a {language}.
type CampaignPath ¶
type CampaignPath struct {
api.WorkspaceInput
CampaignID string `path:"campaignId" format:"uuid"`
}
CampaignPath is {workspace}/campaigns/{campaignId}. Inputs embed it, so it is exported: Huma binds no path field promoted through an unexported embedded struct.
type Campaigns ¶
type Campaigns struct{ S *Service }
Campaigns adapts the service to the campaigns domain's Translations.
func (Campaigns) Choose ¶
func (c Campaigns) Choose(ctx context.Context, ws *store.Workspace, id uuid.UUID, contactLanguage string) (string, string, error)
Choose picks the version a reader with this contact language gets.
func (Campaigns) Content ¶
func (c Campaigns) Content(ctx context.Context, ws *store.Workspace, id uuid.UUID, lang string) (campaigns.TranslationContent, error)
Content returns a language version's content.
type CatalogLanguage ¶
type CatalogLanguage struct {
Code string `json:"code"`
Name string `json:"name"`
Native string `json:"native"`
RTL bool `json:"rtl"`
Regions []string `json:"regions"`
// Contacts already have it; ContactCodes are their codes ("pt-BR").
Contacts int64 `json:"contacts"`
ContactCodes []string `json:"contactCodes"`
BuiltinLabels bool `json:"builtinLabels"`
// Added is true for the workspace's languages.
Added bool `json:"added"`
}
CatalogLanguage is a language that can be added, with the contacts who already have it.
type Choice ¶
type Choice struct {
// Language is the version's language.
Language string
Reason string
// Contact is the reader's base language ("" when they have none).
Contact string
}
Choice is the version one reader gets and why.
type Chooser ¶
type Chooser struct {
// Source is the language the email is written in.
Source string
// Fallback is the workspace's fallback language.
Fallback string
// contains filtered or unexported fields
}
Chooser picks the version each reader gets: the version in their language when it is ready (Up to date or Outdated), otherwise the fallback language's version when it is ready, otherwise the source.
func NewChooser ¶
func NewChooser(source string, st Settings, versions []VersionState) Chooser
NewChooser builds a chooser for an email: its source language, the workspace's settings and the email's language versions. Versions in a language the workspace no longer offers are never sent.
type CompareBlock ¶
type CompareBlock struct {
Index int `json:"index"`
Name string `json:"name"`
Text string `json:"text"`
Segments []BlockSegment `json:"segments"`
}
CompareBlock is one side of a row.
type CompareRow ¶
type CompareRow struct {
// Number is the source block's position (1-based); 0 for a block removed
// from the source or only in the language version.
Number int `json:"number"`
Key string `json:"key"`
State string `json:"state" enum:"up_to_date,changed,still,new,removed,only"`
// Source is the source block now; nil when it was removed or never existed.
Source *CompareBlock `json:"source,omitempty"`
// Version is the language version's block; nil for a block new in the source.
Version *CompareBlock `json:"version,omitempty"`
// Before is the source text the version was translated from (the diff's
// old side), from source version FromVersion.
Before string `json:"before"`
FromVersion int `json:"fromVersion"`
Changed *BlockChange `json:"changed,omitempty"`
}
CompareRow is one block of the compare view.
type CompareText ¶
type CompareText struct {
Source string `json:"source"`
Version string `json:"version"`
State string `json:"state" enum:"up_to_date,changed"`
// Before is the source text the version was translated from.
Before string `json:"before"`
}
CompareText is the subject or preheader row.
type EmailLanguage ¶
type EmailLanguage struct {
Language string `json:"language"`
Name string `json:"name"`
Native string `json:"native"`
Status string `json:"status" enum:"source,up_to_date,outdated,draft,missing"`
// Offered is false for a version in a language the workspace removed:
// it is kept but not sent.
Offered bool `json:"offered"`
// Held: its readers get the fallback instead ("Send English to them").
Held bool `json:"held"`
// Attention counts what is outdated: blocks changed in, new in or
// removed from the source, and a changed subject or preheader.
Attention int `json:"attention"`
Changed int `json:"changed"`
Blocks int `json:"blocks"`
UpToDate int `json:"upToDate"`
Translated int `json:"translated"`
Still int `json:"still"`
SubjectChanged bool `json:"subjectChanged"`
PreheaderChanged bool `json:"preheaderChanged"`
// Readers are the recipients whose language this is, plus, on the
// version the others get, those with no language (NoLanguage) or a
// language the workspace doesn't offer (NotOffered).
Readers *int64 `json:"readers,omitempty"`
NoLanguage int64 `json:"noLanguage"`
NotOffered int64 `json:"notOffered"`
// Gets is the version its readers get: itself, or the fallback.
Gets string `json:"gets"`
TranslatedBy string `json:"translatedBy"`
TranslatedAt *time.Time `json:"translatedAt,omitempty"`
TranslatedFrom int `json:"translatedFrom"`
Version int `json:"version"`
UpdatedBy string `json:"updatedBy"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
Subject string `json:"subject"`
Preheader string `json:"preheader"`
// ChangedBlocks names the source blocks changed since translation, and
// LastChange is the latest of those changes.
ChangedBlocks []string `json:"changedBlocks"`
LastChange *BlockChange `json:"lastChange,omitempty"`
// StillBlocks are the indexes of a draft's blocks that still say what
// the source says; ChangedIndexes the version's blocks changed in the
// source (both for the canvas tags).
StillIndexes []int `json:"stillIndexes"`
ChangedIndexes []int `json:"changedIndexes"`
// contains filtered or unexported fields
}
EmailLanguage is one language of the workspace for an email: its version and status, or Missing.
type EmailLanguages ¶
type EmailLanguages struct {
// Source is the language the email is written in; SourceVersion its
// current content version.
Source string `json:"source"`
SourceVersion int `json:"sourceVersion"`
// CanChangeSource: the source language can change while the email has
// only one version.
CanChangeSource bool `json:"canChangeSource"`
Default string `json:"default"`
Fallback string `json:"fallback"`
// Blocks counts the source's blocks.
Blocks int `json:"blocks"`
Versions []EmailLanguage `json:"versions"`
// Readers counts the recipients, when the audience is known.
Readers *int64 `json:"readers,omitempty"`
// SourceChange is the latest source save that changed blocks: the
// toast after a source edit offers to keep the versions up to date.
SourceChange *LanguageSourceChange `json:"sourceChange,omitempty"`
CanEdit bool `json:"canEdit"`
EditHelpers []string `json:"editHelpers"`
// CanManageWorkspace is workspace:manage (Add a workspace language).
CanManageWorkspace bool `json:"canManageWorkspace"`
WorkspaceHelpers []string `json:"workspaceHelpers"`
}
EmailLanguages is an email's language versions: what the composer's language switcher lists.
type FallbackImpact ¶
type FallbackImpact struct {
Fallback string `json:"fallback"`
// Moved counts the contacts who'd get the new fallback where an email has
// a version in it: those with no language and those whose language
// isn't offered.
Moved int64 `json:"moved"`
NoLanguage int64 `json:"noLanguage"`
NotOffered int64 `json:"notOffered"`
}
FallbackImpact is what changing the fallback does.
type HoldInput ¶
type HoldInput struct {
Held bool `json:"held"`
}
HoldInput sends the fallback to a language's readers instead.
type ImportedVersion ¶
type ImportedVersion struct {
Owner Owner
// Source is the owner's source as it is now, written in SourceLanguage.
Source Source
SourceLanguage string
Language string
// Translated versions are sent; the others are Drafts.
Translated bool
Subject, Preheader, MJML, HTML string
// AB is the version's A/B test, as campaigns store it.
AB json.RawMessage
By *uuid.UUID
At time.Time
// From is the source version it was translated from. FromMJML,
// FromSubject and FromPreheader are the source as it was then (empty:
// as it is now); blocks that changed since are Outdated.
From int
FromMJML, FromSubject, FromPreheader string
// Changes says who changed the source's blocks after From, by source
// block index ("v6 → v9 · Sofia Rossi, 15 Oct 09:12").
Changes map[int]BlockChange
// Label names the save in the version's history.
Label string
}
ImportedVersion is a language version written elsewhere, such as the demo's sample translations: its content, who translated it and from which source version.
type KeepUpToDateInput ¶
type KeepUpToDateInput struct {
// Blocks are the source block keys the edit changed.
Blocks []string `json:"blocks" minItems:"1" maxItems:"200"`
}
KeepUpToDateInput keeps versions up to date after a source edit that needs no translating ("Keep them up to date").
type Language ¶
type Language struct {
// Code is the base BCP 47 code ("es").
Code string `json:"code"`
// Name is the English name ("Spanish").
Name string `json:"name"`
// Native is the language's own name ("Español").
Native string `json:"native"`
// RTL marks right-to-left scripts, which aren't supported yet.
RTL bool `json:"rtl"`
// Regions lists common regional codes, for display ("es-MX", "es-ES").
Regions []string `json:"regions"`
}
Language is one language of the catalog.
type LanguageCatalogList ¶
type LanguageCatalogList struct {
Items []CatalogLanguage `json:"items"`
}
LanguageCatalogList is the languages that can be added.
type LanguageCompare ¶
type LanguageCompare struct {
Source string `json:"source"`
Language string `json:"language"`
// SourceVersion is the source's current version; TranslatedFrom the
// source version the language version was translated from.
SourceVersion int `json:"sourceVersion"`
TranslatedFrom int `json:"translatedFrom"`
TranslatedBy string `json:"translatedBy"`
TranslatedAt *time.Time `json:"translatedAt,omitempty"`
Status string `json:"status" enum:"up_to_date,outdated,draft"`
Blocks int `json:"blocks"`
UpToDate int `json:"upToDate"`
Attention int `json:"attention"`
Translated int `json:"translated"`
Version int `json:"version"`
Subject CompareText `json:"subject"`
Preheader CompareText `json:"preheader"`
Rows []CompareRow `json:"rows"`
}
LanguageCompare is the compare view: the source and one language version side by side, block by block, with the subject and preheader first.
type LanguageDefaults ¶
type LanguageDefaults struct {
Default string `json:"default" pattern:"^[a-z]{2,3}$"`
Fallback string `json:"fallback" pattern:"^[a-z]{2,3}$"`
}
LanguageDefaults are the default and fallback languages.
type LanguagePageCopy ¶
type LanguagePageCopy struct {
Status string `json:"status" enum:"live,incomplete,not_set_up"`
// Missing counts the strings still to write when Incomplete.
Missing int `json:"missing"`
By string `json:"by"`
At *time.Time `json:"at,omitempty"`
// BuiltinLabels is true when ReputeCast's own labels (buttons, field
// labels, messages) ship in this language.
BuiltinLabels bool `json:"builtinLabels"`
}
LanguagePageCopy is the state of a language's public page copy.
type LanguageRemoval ¶
type LanguageRemoval struct {
Code string `json:"code"`
Name string `json:"name"`
Has []RemovalItem `json:"has"`
// Readers are the contacts with this language: they get the fallback.
Readers int64 `json:"readers"`
Fallback string `json:"fallback"`
// Refusal is set when it can't be removed (the default or the fallback).
Refusal string `json:"refusal,omitempty"`
}
LanguageRemoval is what removing a language affects.
type LanguageSourceChange ¶
type LanguageSourceChange struct {
Version int `json:"version"`
By string `json:"by"`
At time.Time `json:"at"`
// Blocks are the keys of the blocks it changed; Outdated the languages
// it made outdated.
Blocks []string `json:"blocks"`
Outdated []string `json:"outdated"`
}
LanguageSourceChange is a source save that made versions outdated.
type Link ¶
type Link struct {
Hash string `json:"hash"`
Text string `json:"text"`
Version int `json:"version"`
}
Link is the subject or preheader a version was translated from.
type Links ¶
type Links struct {
Subject *Link `json:"subject,omitempty"`
Preheader *Link `json:"preheader,omitempty"`
Blocks []BlockLink `json:"blocks"`
}
Links are what a language version was translated from: per block, the source block, its fingerprint and text then, and the source version.
func FreshLinks ¶
func FreshLinks(source []Block, keys []SourceBlock, version []Block, subject, preheader string, sourceVersion int) Links
FreshLinks links every block of a version made from the source as it is now: a new version copied from the source, or one marked up to date.
func MarkUpToDate ¶
func MarkUpToDate(l Links, source []Block, sourceKeys []SourceBlock, subject, preheader string, sourceVersion int, only []string) Links
MarkUpToDate points links at the current source: every block when keys is empty, otherwise the blocks with those source keys. The subject and preheader are refreshed with every block.
type MarkInput ¶
type MarkInput struct {
// Blocks limits "Mark as up to date" to some source blocks (their keys,
// or "subject" and "preheader"); empty marks the whole version.
Blocks []string `json:"blocks,omitempty" maxItems:"200"`
}
MarkInput marks a language version translated or up to date.
type Owner ¶
type Owner struct {
Kind string
ID uuid.UUID
// Version is the automation email or template version; 0 for campaigns.
Version int32
WorkspaceID uuid.UUID
// Name names it in the audit log.
Name string
}
Owner is an email with language versions: a campaign, a version of an automation email or of a transactional template.
type PreviewContact ¶
type PreviewContact struct {
ID string `json:"id" format:"uuid"`
Name string `json:"name"`
Email string `json:"email"`
// Language is the contact's language code as stored; Gets the version
// they get, their own or the fallback.
Language string `json:"language"`
Gets string `json:"gets"`
// Offered is false for a language the workspace doesn't offer.
Offered bool `json:"offered"`
}
PreviewContact is a contact to preview an email as ("Preview as" on the composer's canvas), with the version they get.
type PreviewContactList ¶
type PreviewContactList struct {
Items []PreviewContact `json:"items"`
}
PreviewContactList is one contact per workspace language found in the audience, in the workspace's order, then one whose language the workspace doesn't offer.
type Progress ¶
type Progress struct {
Status string
// Attention counts what needs a look: blocks changed in, new in or
// removed from the source, and a changed subject or preheader.
Attention int
// Blocks is the number of source blocks; UpToDate of them are.
Blocks int
UpToDate int
// Changed counts blocks changed in the source since translation.
Changed int
// Still counts blocks of a draft that still say what the source says;
// Translated the others.
Still int
Translated int
SubjectChanged bool
PreheaderChanged bool
}
Progress counts a version's blocks against the source.
type ReadinessFacts ¶
type ReadinessFacts struct {
// Applies is false for a workspace with one language and an email
// without versions: the Languages group isn't shown.
Applies bool
Source string
SourceVersion int
Fallback string
// Languages are the workspace's languages (and versions in removed
// ones), the source first.
Languages []ReadinessLanguage
// NoLanguage and NotOffered count the recipients with no language and
// with a language the workspace doesn't offer; NotOfferedCodes are those
// codes.
NoLanguage int64
NotOffered int64
NotOfferedCodes []string
// OthersGet is the version readers with no language (or one the
// workspace doesn't offer) get.
OthersGet string
// Recipients is the audience's total.
Recipients int64
// Versions are the versions that are sent besides the source, with their
// content (Send Readiness checks every version).
Versions []ReadinessVersion
}
ReadinessFacts is what Send Readiness checks about an email's languages.
type ReadinessLanguage ¶
type ReadinessLanguage struct {
Language string
Name string
Status string // source, up_to_date, outdated, draft, missing
Held bool
Offered bool
// Readers are the recipients with this language; Gets is the version
// they get.
Readers int64
Gets string
// Attention counts outdated blocks; Changed names the source blocks
// that changed since translation.
Attention int
Changed []string
// ChangedRefs say what the Changed blocks are, to name them in any
// language (BlockRef.Name).
ChangedRefs []BlockRef
SubjectChanged bool
TranslatedFrom int
Blocks int
Translated int
PageCopy string // live, incomplete, not_set_up
}
ReadinessLanguage is one language's state for a send.
type ReadinessVersion ¶
type ReadinessVersion struct {
Language string
Subject string
Preheader string
MJML string
HTML string
}
ReadinessVersion is the content of a version that is sent.
type RemovalItem ¶
type RemovalItem struct {
Kind string `json:"kind" enum:"campaign,automation_email,transactional_template"`
ID string `json:"id"`
Name string `json:"name"`
// State is a campaign's: a draft, scheduled, waiting to send (approval)
// or sending.
State string `json:"state,omitempty" enum:"draft,scheduled,waiting,sending"`
// Status is where a campaign's version stands, with the blocks that
// changed in the source when it's outdated ("Campaign draft · German is
// outdated").
Status string `json:"status,omitempty" enum:"up_to_date,outdated,draft,held"`
Changed int `json:"changed,omitempty"`
// LiveVersion and Languages are a transactional template's live
// version and the languages it sends ("v4 live in English, Spanish
// and German").
LiveVersion int `json:"liveVersion,omitempty"`
Languages []string `json:"languages,omitempty"`
}
RemovalItem is something with a version in a language being removed.
type ReportLanguageCount ¶
type ReportLanguageCount struct {
Language string `json:"language"`
Name string `json:"name"`
Count int64 `json:"count"`
}
ReportLanguageCount is a version's share of the send.
type ReportLanguageDraft ¶
ReportLanguageDraft names a campaign.
type ReportLanguageFallback ¶
type ReportLanguageFallback struct {
// Readers are the languages whose readers got the fallback ("vi").
Readers []string `json:"readers"`
Got string `json:"got"`
// Gap is how many points their human-open rate is below the version's
// own readers' (negative when above).
Gap *float64 `json:"gap,omitempty"`
// Draft is the newest unsent campaign to the same audience, to add a
// version in their language to.
Draft *ReportLanguageDraft `json:"draft,omitempty"`
}
ReportLanguageFallback is the note under the table.
type ReportLanguageOption ¶
ReportLanguageOption is one version of the click map's language picker.
type ReportLanguageRow ¶
type ReportLanguageRow struct {
Language string `json:"language"`
Name string `json:"name"`
// Fallback marks readers who got this version because theirs wasn't
// ready; Missing is their language.
Fallback bool `json:"fallback"`
Reason string `json:"reason,omitempty" enum:"missing,draft,held"`
Missing string `json:"missing,omitempty"`
// Readers names who got it: their languages, "no language" and "other
// languages" (Kinds holds the same as codes: a language code,
// "no_language" or "not_offered").
Readers []string `json:"readers"`
Kinds []string `json:"kinds"`
Source bool `json:"source"`
// TranslatedFrom is the source version the version was translated from.
TranslatedFrom int `json:"translatedFrom,omitempty"`
Sent int64 `json:"sent"`
Delivered int64 `json:"delivered"`
DeliveredRate *float64 `json:"deliveredRate,omitempty"`
HumanOpens int64 `json:"humanOpens"`
HumanOpenRate *float64 `json:"humanOpenRate,omitempty"`
Clicks int64 `json:"clicks"`
ClickRate *float64 `json:"clickRate,omitempty"`
Unsubscribes int64 `json:"unsubscribes"`
UnsubscribeRate *float64 `json:"unsubscribeRate,omitempty"`
Complaints int64 `json:"complaints"`
ComplaintRate *float64 `json:"complaintRate,omitempty"`
}
ReportLanguageRow is one version and who got it.
type ReportLanguages ¶
type ReportLanguages struct {
// Languages counts the languages sent; Versions the rows (readers who
// got the fallback have their own).
Languages int `json:"languages"`
Versions int `json:"versions"`
Rows []ReportLanguageRow `json:"rows"`
// Sent is the headline's breakdown by version ("English 27,396 ·
// Spanish 2,740 · German 1,468").
Sent []ReportLanguageCount `json:"sent"`
// Fallback compares the readers who got the fallback with the version's
// own readers ("their human-open rate is 8.3 points below").
Fallback *ReportLanguageFallback `json:"fallback,omitempty"`
// ClickMaps are the versions the click map can show, the source first.
ClickMaps []ReportLanguageOption `json:"clickMaps"`
}
ReportLanguages is "Results per language" of a campaign sent in more than one language. It holds aggregate numbers only (the report is shared read-only).
type Row ¶
type Row struct {
// Number is the source block's position (1-based); 0 for a block the
// source no longer has or never had.
Number int
Key string
Source *Block
Version *Block
// VersionIndex is the version block's position, -1 when it has none.
VersionIndex int
State string
// Before is the source text the version was translated from (the diff's
// old side), and FromVersion the source version then.
Before string
FromVersion int
Changed *BlockChange
}
Row is one row of the compare view: a source block and the version's block made from it.
type SaveInput ¶
type SaveInput struct {
BaseVersion int
Subject string
Preheader string
MJML string
HTML string
ABTest json.RawMessage
Label string
// LabelText is Label's message, kept for readers of other languages.
LabelText i18n.Text
Source string
Force bool
Minify bool
// Audited is set when the caller writes the audit entry (MCP agents).
Audited bool
}
SaveInput is a save of a language version.
type Saved ¶
type Saved struct {
Version int
SavedAt time.Time
ContentHash string
SizeBytes int
PlainText string
HTML string
}
Saved is the result of a language version save.
type SendSet ¶
type SendSet struct {
Source string
Default string
Fallback string
Offered []string
Versions []SendVersion
}
SendSet is what a send needs to give each reader their version: the source's language, the workspace's languages and the email's versions.
type SendVersion ¶
type SendVersion struct {
Language string
Status string
Held bool
Subject string
Preheader string
HTML string
Text string
ABTest json.RawMessage
TranslatedFrom int
Version int
}
SendVersion is one language version at send start. Content is only set for versions that can be sent (translated, not held, offered).
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Q *store.Queries
Audit *audit.Logger
Now func() time.Time
// AudienceLanguages counts the final recipients of a stored audience
// definition per contact language code, as Send Readiness counts them,
// and returns their total.
AudienceLanguages func(ctx context.Context, ws *store.Workspace, audience json.RawMessage) (map[string]int64, int64, error)
// Changed is told when a campaign's language versions changed (the
// approvals domain re-checks open approvals).
Changed func(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID)
}
Service holds the content-languages domain.
func (*Service) AddCampaignLanguage ¶
func (s *Service) AddCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, in AddLanguageInput) (EmailLanguages, error)
AddCampaignLanguage adds a Draft language version to a campaign.
func (*Service) AddLanguage ¶
func (s *Service) AddLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, code string) (WorkspaceLanguages, error)
AddLanguage adds a language to the workspace.
func (*Service) AddTemplateLanguage ¶
func (s *Service) AddTemplateLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref string, in AddLanguageInput) (EmailLanguages, error)
AddTemplateLanguage adds a Draft language version to a template's draft.
func (*Service) AgentSaveCampaign ¶
func (s *Service) AgentSaveCampaign(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string, in AgentEdit) (AgentSaved, error)
AgentSaveCampaign changes a draft campaign's language version for an MCP agent. Agents only change drafts; the MCP server writes the audit entry.
func (*Service) ApplyCampaignChange ¶
func (s *Service) ApplyCampaignChange(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, in ApplyInput) (ApplyResult, error)
ApplyCampaignChange applies a source link or image change to every language version.
func (*Service) AutomationEmailLanguageContent ¶
func (s *Service) AutomationEmailLanguageContent(ctx context.Context, ws *store.Workspace, id uuid.UUID, version int, lang string) (AutomationEmailLanguage, error)
AutomationEmailLanguageContent returns a language version's content.
func (*Service) AutomationEmailLanguages ¶
func (s *Service) AutomationEmailLanguages(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, version int) (EmailLanguages, error)
AutomationEmailLanguages lists the language versions of an automation email version (the step panel's Languages).
func (*Service) AutomationEmailStates ¶
func (s *Service) AutomationEmailStates(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID, version int) ([]AutomationEmailState, error)
AutomationEmailStates lists an automation email version's language versions (the publish dialog's diff and checks), read with q.
func (*Service) AutomationSendSet ¶
func (s *Service) AutomationSendSet(ctx context.Context, wsID, emailID uuid.UUID, version int) (SendSet, error)
AutomationSendSet returns the languages of an automation email version.
func (*Service) CampaignDigest ¶
func (s *Service) CampaignDigest(ctx context.Context, q *store.Queries, wsID, campaignID uuid.UUID) string
CampaignDigest fingerprints what a campaign's language versions add to its content: each version's content, status and hold, and the workspace's languages. It is empty for a campaign without versions, so fingerprints of single-language campaigns don't change.
func (*Service) CampaignHistory ¶
func (s *Service) CampaignHistory(ctx context.Context, ws *store.Workspace, id uuid.UUID, lang string, limit int) (campaigns.ComposerVersionList, error)
CampaignHistory lists the saves of a campaign's language version.
func (*Service) CampaignLanguages ¶
func (s *Service) CampaignLanguages(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (EmailLanguages, error)
CampaignLanguages lists a campaign's language versions for the switcher.
func (*Service) CampaignPreviewContacts ¶
func (s *Service) CampaignPreviewContacts(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (PreviewContactList, error)
CampaignPreviewContacts picks the contacts to preview a campaign as: one per workspace language among its audience's lists (people with a first name first), then one whose language isn't offered.
func (*Service) CampaignReadiness ¶
func (s *Service) CampaignReadiness(ctx context.Context, ws *store.Workspace, id uuid.UUID, recipients map[string]int64) (ReadinessFacts, error)
CampaignReadiness returns the language facts of a campaign for Send Readiness. recipients counts the final audience per contact language code.
func (*Service) CampaignResults ¶
func (s *Service) CampaignResults(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID, audience json.RawMessage) (*ReportLanguages, error)
CampaignResults returns a sent campaign's results per language, or nil when it went out in one language.
func (*Service) CampaignSendSet ¶
CampaignSendSet returns a campaign's languages for a send.
func (*Service) CampaignSnapshot ¶
func (s *Service) CampaignSnapshot(ctx context.Context, q *store.Queries, campaignID uuid.UUID) ([]VersionSnapshot, error)
CampaignSnapshot returns what an approval covers of a campaign's language versions (nil without versions).
func (*Service) CampaignVersionAt ¶
func (s *Service) CampaignVersionAt(ctx context.Context, campaignID uuid.UUID, lang string, version int) (VersionContent, error)
CampaignVersionAt returns a campaign's language version as it was at a saved version (the version an approval covers); 0, or a version no longer kept, gives the version as it is now.
func (*Service) ClickMapVersion ¶
func (s *Service) ClickMapVersion(ctx context.Context, campaignID uuid.UUID, lang string) (html string, from, to int, ok bool)
ClickMapVersion returns the HTML a language version was sent with and the range of its link positions in campaign_links (from, to); ok is false when the send didn't capture that version.
func (*Service) CompareCampaign ¶
func (s *Service) CompareCampaign(ctx context.Context, ws *store.Workspace, id uuid.UUID, lang string) (LanguageCompare, error)
CompareCampaign returns the compare view of a campaign's language version.
func (*Service) CopyBlockToCampaignLanguage ¶
func (s *Service) CopyBlockToCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string, in BlockInput) (LanguageCompare, error)
CopyBlockToCampaignLanguage copies a source block into a language version ("Copy into German"), after the block that precedes it in the source.
func (*Service) CopyForward ¶
func (s *Service) CopyForward(ctx context.Context, q *store.Queries, wsID, id uuid.UUID, from, to int) error
CopyForward carries an automation email version's language versions to its next version, when its source is edited: the blocks the edit changed are Outdated there.
func (*Service) FallbackPreview ¶
func (s *Service) FallbackPreview(ctx context.Context, ws *store.Workspace, code string) (FallbackImpact, error)
FallbackPreview says how many contacts a new fallback moves.
func (*Service) HoldCampaignLanguage ¶
func (s *Service) HoldCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string, in HoldInput) (EmailLanguages, error)
HoldCampaignLanguage holds (or releases) a language version.
func (*Service) ImportVersion ¶
ImportVersion stores a language version written elsewhere, linked to the source as it stood when it was translated. Call it in a transaction.
func (*Service) KeepCampaignUpToDate ¶
func (s *Service) KeepCampaignUpToDate(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, in KeepUpToDateInput) (EmailLanguages, error)
KeepCampaignUpToDate marks the given source blocks up to date in every translated version.
func (*Service) LanguageCatalog ¶
func (s *Service) LanguageCatalog(ctx context.Context, ws *store.Workspace, query string) ([]CatalogLanguage, error)
LanguageCatalog lists the languages to add: those the workspace's contacts already have first, then the rest by name. A query matches the English name, the language's own name or its code.
func (*Service) List ¶
func (s *Service) List(ctx context.Context, ws *store.Workspace, p *authz.Principal) (WorkspaceLanguages, error)
List returns the workspace's languages with their contacts and page copy.
func (*Service) MarkAutomationEmailLanguage ¶
func (s *Service) MarkAutomationEmailLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string, from int, translated bool) (AutomationLanguageSaved, error)
MarkAutomationEmailLanguage marks a language version up to date (or a Draft translated) in the email's next version.
func (*Service) MarkCampaignLanguage ¶
func (s *Service) MarkCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string, translated bool, in MarkInput) (EmailLanguages, error)
MarkCampaignLanguage marks a Draft translated, or an Outdated version (or some of its blocks) up to date.
func (*Service) MarkTemplateLanguage ¶
func (s *Service) MarkTemplateLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref, lang string, translated bool, in MarkInput) (EmailLanguages, error)
MarkTemplateLanguage marks a Draft translated, or an Outdated version up to date.
func (*Service) Removal ¶
func (s *Service) Removal(ctx context.Context, ws *store.Workspace, code string) (LanguageRemoval, error)
Removal says what removing a language affects.
func (*Service) RemoveAutomationEmailLanguage ¶
func (s *Service) RemoveAutomationEmailLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string, from int) (AutomationLanguageSaved, error)
RemoveAutomationEmailLanguage removes a language version in the email's next version.
func (*Service) RemoveBlockFromCampaignLanguage ¶
func (s *Service) RemoveBlockFromCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string, in BlockInput) (LanguageCompare, error)
RemoveBlockFromCampaignLanguage removes a block from a language version ("Remove from German"), for blocks removed from the source.
func (*Service) RemoveCampaignLanguage ¶
func (s *Service) RemoveCampaignLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string) (EmailLanguages, error)
RemoveCampaignLanguage deletes a campaign's language version.
func (*Service) RemoveLanguage ¶
func (s *Service) RemoveLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, code string) (WorkspaceLanguages, error)
RemoveLanguage takes a language out of the workspace. Its versions and page copy are kept, but no longer used; its contacts get the fallback.
func (*Service) RemoveTemplateLanguage ¶
func (s *Service) RemoveTemplateLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref, lang string) (EmailLanguages, error)
RemoveTemplateLanguage deletes a language version of a template's draft. Published versions keep theirs.
func (*Service) SaveAutomationEmailLanguage ¶
func (s *Service) SaveAutomationEmailLanguage(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string, in AutomationLanguageSave) (AutomationLanguageSaved, error)
SaveAutomationEmailLanguage writes a language version of an automation email, adding it when the email has none, as the email's next version.
func (*Service) SetCampaignSource ¶
func (s *Service) SetCampaignSource(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, in SourceInput) (EmailLanguages, error)
SetCampaignSource changes the source language while the campaign has no language versions.
func (*Service) SetDefaults ¶
func (s *Service) SetDefaults(ctx context.Context, ws *store.Workspace, p *authz.Principal, in LanguageDefaults) (WorkspaceLanguages, error)
SetDefaults changes the default and fallback languages.
func (*Service) SetPageCopy ¶
func (s *Service) SetPageCopy(ctx context.Context, q *store.Queries, wsID uuid.UUID, code, status string, missing int, by *uuid.UUID, at time.Time) error
SetPageCopy records the status of a language's page copy. The forms and public pages domain calls it when page copy changes; it doesn't audit (the page copy change is audited where it happens).
type Settings ¶
type Settings struct {
Default string
Fallback string
// Languages are the active languages, the default first.
Languages []string
// contains filtered or unexported fields
}
Settings are a workspace's languages: what it writes in, its default and its fallback.
func NewSettings ¶
NewSettings builds workspace settings from their parts (the sending engine keeps them in a send's snapshot).
type Source ¶
type Source struct {
Subject string
Preheader string
MJML string
HTML string
// Version is the source's content version: blocks are compared again
// when it changes.
Version int
// By and At are who saved that version and when.
By string
At time.Time
}
Source is an email's source content as it is now.
type SourceBlock ¶
type SourceBlock struct {
Key string `json:"key"`
Raw string `json:"raw"`
Hash string `json:"hash"`
Text string `json:"text"`
// Changed is the source save that last changed what is translated.
Changed *BlockChange `json:"changed,omitempty"`
}
SourceBlock is a block of the source with its key: what the source looks like now, and when it last changed.
func SyncSource ¶
func SyncSource(stored []SourceBlock, current []Block, nextKey int, change BlockChange) ([]SourceBlock, int, []string)
SyncSource brings stored source blocks up to the current source: blocks keep their keys through edits and moves, new blocks get new keys, and a block whose translatable text changed records the change.
type SourceInput ¶
type SourceInput struct {
Language string `json:"language" pattern:"^[a-z]{2,3}$"`
}
SourceInput changes the language an email is written in.
type TemplateLanguagePath ¶
type TemplateLanguagePath struct {
TemplatePath
Language string `path:"language" pattern:"^[a-z]{2,3}$"`
}
TemplateLanguagePath adds a {language}.
type TemplatePath ¶
type TemplatePath struct {
api.WorkspaceInput
Template string `path:"template" maxLength:"64" doc:"The template's ID, such as password-reset, or its UUID" example:"password-reset"`
}
TemplatePath names a transactional template by its ID (password-reset) or its UUID.
type Transactional ¶
type Transactional struct{ S *Service }
Transactional adapts the service to the transactional domain's Translations.
func (Transactional) Changes ¶
func (t Transactional) Changes(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID, version int) ([]transactional.TransactionalLanguageChange, error)
Changes lists the language versions the draft adds, changes (its content, or marked translated) or removes since a published version.
func (Transactional) Choose ¶
func (t Transactional) Choose(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID, version int, requested string, contactID *uuid.UUID) (transactional.LanguageChoice, error)
Choose picks the language version of a published template version a message uses: the language asked for, else the linked contact's, else the fallback (the source when the fallback has no version).
func (Transactional) Draft ¶
func (t Transactional) Draft(ctx context.Context, ws *store.Workspace, id uuid.UUID, lang string) (transactional.TranslationDraft, error)
Draft is a language version of a template's draft.
func (Transactional) Publish ¶
func (t Transactional) Publish(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID, version int) error
Publish publishes the draft's language versions with a new version of the template: the draft's source and versions are copied to it.
func (Transactional) Publishing ¶
func (t Transactional) Publishing(ctx context.Context, q *store.Queries, ws *store.Workspace, id uuid.UUID) ([]transactional.TransactionalPublishLanguage, error)
Publishing lists the language versions publishing the draft publishes, the source first: the publish dialog's "Publishes English, Spanish and German together".
func (Transactional) Record ¶
func (t Transactional) Record(ctx context.Context, q *store.Queries, messageID uuid.UUID, ch transactional.LanguageChoice) error
Record stores the language a message was sent in.
func (Transactional) SaveDraft ¶
func (t Transactional) SaveDraft(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string, in transactional.TransactionalDraftSave) (transactional.TransactionalDraftSaved, error)
SaveDraft stores a new version of a language version of the draft. Only its subject, preheader and content belong to it: variables, test data, sender and tracking are the template's, saved with the draft.
type VersionChange ¶
type VersionChange struct {
Language string
// Name is the language's name ("German").
Name string
// Before and After are "v3" and "v4 · intro changed".
Before string
After string
// What is the change in a few words ("intro changed", "added").
What string
// Detail is the change as data, to keep with an approval and write in
// each reader's language later (VersionChangeDetail.Texts).
Detail VersionChangeDetail
}
VersionChange is a language version that changed after approval.
func DiffVersions ¶
func DiffVersions(before, after []VersionSnapshot) []VersionChange
DiffVersions compares the versions an approval covered with the versions now: added, removed, edited (naming the blocks), marked translated or held. It writes in English; DiffVersionsIn writes for a reader, and each change's Detail writes it for later readers.
func DiffVersionsIn ¶
func DiffVersionsIn(l i18n.Lang, before, after []VersionSnapshot) []VersionChange
DiffVersionsIn is DiffVersions in a reader's language: the language names and what changed read in l.
type VersionChangeDetail ¶
type VersionChangeDetail struct {
Language string `json:"language"`
// Change is added, edited, status (marked translated or back to
// draft), held (held or sent again) or removed.
Change string `json:"change"`
// Prev and Version are the version numbers before and after.
Prev int `json:"prev,omitempty"`
Version int `json:"version,omitempty"`
// PrevStatus and Status are the stored statuses (draft, translated);
// PrevHeld and Held whether the version was held.
PrevStatus string `json:"prevStatus,omitempty"`
Status string `json:"status,omitempty"`
PrevHeld bool `json:"prevHeld,omitempty"`
Held bool `json:"held,omitempty"`
// What an edit changed: the subject, how many blocks (one of them named
// by Block, or by its English BlockName for snapshots without refs),
// and whether a block was removed.
Subject bool `json:"subject,omitempty"`
Blocks int `json:"blocks,omitempty"`
Block *BlockRef `json:"block,omitempty"`
BlockName string `json:"blockName,omitempty"`
Removed bool `json:"removed,omitempty"`
}
VersionChangeDetail is what changed in a language version after approval, as data: an approval stores it and writes it in each reader's language when it's read (Texts).
type VersionContent ¶
VersionContent is a language version's content at one of its versions.
type VersionSnapshot ¶
type VersionSnapshot struct {
Language string `json:"language"`
Status string `json:"status"`
Held bool `json:"held,omitempty"`
Version int `json:"version"`
Hash string `json:"hash"`
Subject string `json:"subject"`
// Blocks fingerprint the version's blocks, to name what changed.
Blocks []BlockSnapshot `json:"blocks"`
}
VersionSnapshot is what an approval covers of one language version.
type VersionState ¶
type VersionState struct {
Language string
// Status is the stored status: draft or translated.
Status string
Held bool
}
VersionState is what a chooser needs to know about one language version.
type WorkspaceLanguage ¶
type WorkspaceLanguage struct {
Code string `json:"code" example:"es"`
Name string `json:"name" example:"Spanish"`
Native string `json:"native" example:"Español"`
// Codes are the codes its contacts have, most common first ("es",
// "es-MX", "es-ES"); MoreCodes says there are others.
Codes []string `json:"codes"`
MoreCodes bool `json:"moreCodes"`
// Contacts get this language: its own contacts (Own), plus, for the
// fallback, contacts with no language or one the workspace doesn't offer.
Contacts int64 `json:"contacts"`
Own int64 `json:"own"`
IsDefault bool `json:"isDefault"`
IsFallback bool `json:"isFallback"`
PageCopy LanguagePageCopy `json:"pageCopy"`
// AddedBy is empty for the language the workspace started with.
AddedBy string `json:"addedBy"`
AddedAt *time.Time `json:"addedAt,omitempty"`
}
WorkspaceLanguage is one language of the workspace.
type WorkspaceLanguages ¶
type WorkspaceLanguages struct {
Languages []WorkspaceLanguage `json:"languages"`
Default string `json:"default"`
Fallback string `json:"fallback"`
TotalContacts int64 `json:"totalContacts"`
NoLanguage int64 `json:"noLanguage"`
// NotOffered counts contacts with a language the workspace doesn't
// offer; NotOfferedCodes lists those codes, most common first.
NotOffered int64 `json:"notOffered"`
NotOfferedCodes []string `json:"notOfferedCodes"`
// CanManage is workspace:manage; Helpers hold it.
CanManage bool `json:"canManage"`
Helpers []string `json:"helpers"`
}
WorkspaceLanguages is Settings › General › Languages.