Repository navigation
feat(campaigns): localized strings as campaign messages - #354
Open
jeroenrinzema wants to merge 2 commits into
Open
jeroenrinzema wants to merge 2 commits into
jeroenrinzema wants to merge 2 commits into
Conversation
A campaign carries its strings by key and locale; templates read them for the recipient's locale.
A campaign keeps one template and its strings per key and locale. Sends resolve them along the locale chain (locale, base language, project default): React Email templates get t(key, vars), locale and messages; Liquid fields get {{ messages.<key> }}. Templates are chosen along the same chain.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A campaign keeps one template and its messages: the strings by key, then by locale. Translating stops meaning a copy of the whole template per locale.
{ "subject": { "en": "Tomorrow: DevPulse {campaign.title}", "nl": "Morgen: DevPulse {campaign.title}" }, "manage": { "en": "Your sign-ups, to change or cancel: {url}", "nl": "Je aanmeldingen, om te wijzigen of af te melden: {url}" } }Subject:
{{ messages.subject }}.How it's stored and defined
campaigns.messages JSONB NOT NULL DEFAULT '{}', on the campaign rather than the template, so every template of the campaign (and a per-locale override) shares one set. Exposed asCampaign.messages/UpdateCampaign.messages(CampaignMessages); an update replaces the map, leaving it out keeps it.{key: {locale: string}}). A key with its languages side by side is what you edit and review; a missing translation is a missing entry right there.^[a-z][a-z0-9_]*(\.[a-z0-9_]+)*$(dots group,footer.line), validated on update (400). Locales are the project's locale keys.{path}. Filled from the vars passed tot, else the render data ({campaign.title},{user.data.name}); missing →"". Whole sentences with placeholders, never glued fragments.Flow at send time
internal/render/messages.go:LocaleChain,ResolveLocale,ResolveMessages,FillPlaceholders,Localize(returns the React props and the Liquid data).campaigns_render.go: the one campaign render path (journeys, broadcasts, inbox, API sends) uses the chain for the template and the messages.renderer/compiler.ts:createTranslatorbuildstfromprops.messages; an element value (a<Link/>) comes back as parts JSX renders in place.SendTest: resolves messages like a real send (locale fromprops.locale,props.user.locale, else the template's) unless the props carry them.campaigns/localization.mdx; templates/create pages point to it.Templates without messages render as before; template choice gains only the base-language step.
Not in this PR (proposed next)
{count, plural, …}); v1 is plain placeholders.Console: #355 (data panel tab). luno: cloudproud/lunogram.studio#4 (
messages.yaml).Evidence
go test ./internal/render/(chain, resolution, placeholders, Liquid map),go test ./internal/store/management -run Campaign,go test ./internal/http/controllers/v1/management -run 'Campaign|SendTest',go test ./internal/pubsub/consumer -run 'Campaign|SelectTemplate|BuildRenderData': pass (Postgres via testcontainers).deno test --no-check --allow-envinrenderer/: 5 pass (--no-check:compiler.ts:89pixelBasedPresethas a type error on main already).nland campaign messages logged:Merge Danger
Door: two-way (an additive column; dropping it loses only messages written since)
Blast Radius: campaign-rendering
Every send now lists the project's locale keys once (one small query). Two templates with the same locale: the first now wins (before: the last).