blocks-localization-implementation
Skill42 starsChanged 12 days agoMITView on GitHub
Consume SELISE Blocks localization at runtime in a scaffolded frontend, entirely through the `@seliseblocks/client` SDK's `localization` namespace — never raw fetch/curl. Use for making a Blocks web app multilingual on the client: language/module discovery, loading dictionaries, the built-in `t()` lookup, and a language switcher that reloads and re-renders. Frontend consumption only — authoring/pushing translation content is the sibling skill blocks-localization-configuration.
In this repository27 other files it gives its agents.
- AGENTS.mdAGENTS.md
- bootstrap/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- blocks-bootstrapSkill
- blocks-captchaSkill
- blocks-data-gateway-configurationSkill
- blocks-data-gateway-crudSkill
- blocks-data-storageSkill
- blocks-frontend-local-httpsSkill
- blocks-functionsSkill
- blocks-iam-access-controlSkill
- blocks-iam-accountSkill
- blocks-iam-mfaSkill
- blocks-iam-organizationsSkill
- blocks-iam-sso-oidc-configurationSkill
- blocks-iam-sso-oidc-implementationSkill
- blocks-iam-usersSkill
- blocks-localization-configurationSkill
- blocks-mailSkill
- blocks-notificationSkill
- blocks-notifierSkill
- blocks-proxySkill
- blocks-release-deploymentSkill
- blocks-secretsSkill
- blocksSkill
- blocks-storage-configurationSkill
- blocks-workflowSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 6
When invoking a project-scoped blocks command, either use the resolved account's saved selection or pass --project <tenantId> for that one …
- Distinctive: line 20
Every method has a matching pair — one public, one tenant/session-scoped:
- Very specific: line 47
If you pass moduleName, t() does an exact
${language}:${moduleName}cache lookup — deterministic.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When invoking a project-scoped blocks command, either use the resolved account's saved selection or pass --project <tenantId> for that one command without changing saved state. --project applies to CLI commands only, never SDK calls.
Blocks Localization — Implementation (frontend)
Make a scaffolded Blocks web app render its UI in the user's language, using only the localization namespace on the SDK client — createBlocksClient(...).localization. No fetch, no manual query strings, no hand-rolled caching: the SDK client already does all of that.
The translations themselves (keys, modules, per-language values) are authored and pushed with the blocks-localization-configuration skill (uses blocks localization *). This skill only covers loading and rendering them in the app.
The client and its cache
localization is a BlocksLocalizationClient instance created once inside createBlocksClient(). It holds its dictionary cache as instance state — a Map keyed by `${language}:${moduleName}` plus an activeLanguage. That cache is only as shared as the client instance is: the canonical scaffold creates one blocksClient singleton (src/lib/blocks/client.ts, from createBlocksClient()) and imports it everywhere, so every t() call sees every dictionary loaded anywhere in the app. If you instantiate a second createBlocksClient() somewhere, it gets its own empty cache — don't do that; import the one singleton.
Public vs. authenticated methods
Every method has a matching pair — one public, one tenant/session-scoped:
| Public (no token sent) | Authenticated (sends token when configured) |
languages() | languagesForCurrentTenant() |
modules() | modulesForCurrentTenant() |
translations(moduleName, language) | cloudTranslations(moduleName, language) |
load(language, modules[]) | loadCloud(language, modules[]) |
languages()/modules()/translations()/load()are explicitly public — all tenant-supported cultures and translation bundles, usable pre-login for a language picker or startup locale selection.languagesForCurrentTenant()/modulesForCurrentTenant()/cloudTranslations()/loadCloud()are scoped to whichever tenant the activex-blocks-keyresolves to (and send the caller's access token if the client is configured with one) — use these for protected, tenant-specific dictionaries behind a signed-in session.
keysByNames({ keyNames, moduleId? }) fetches specific key records (metadata/translations) without downloading a whole module dictionary; useful for a one-off label or an admin screen that inspects individual keys.
Argument order matters: translations(moduleName, language) and cloudTranslations(moduleName, language) take module first, language second — easy to transpose.
Startup sequence
- List languages on app boot (or in a query hook) —
blocksClient.localization.languagesForCurrentTenant()(orlanguages()if you want it available pre-login). UseisDefault/languageCodefrom the result to build the picker and preselect a default, falling back to a persisted user choice (e.g.localStorage). - Load dictionaries for the active language —
blocksClient.localization.load(language, modules)wheremodulesis the list of bundles the app needs (e.g.["common", "dashboard", "assets"]).load()fetches each module's dictionary in parallel viatranslations()and merges them into one object, with later modules in the array overwriting earlier ones on key collision. UseloadCloud()instead for protected dictionaries once the user is signed in. - Render labels with
blocksClient.localization.t(key, fallback, { language, moduleName }). It reads from dictionaries already loaded bytranslations()/load()(or their cloud equivalents) — it does not fetch anything itself. Missing key →fallback→ the raw key, in that order. - Switch language: on switcher change, call
load()(orloadCloud()) again with the new language and the same module list, then re-render. There's no separate "invalidate" step — loading a language populates its own cache entries; you don't need to clear the old language's entries (they just stop being read onceactiveLanguage/your app state moves on).
The canonical scaffold (blocks new web) wires exactly this pattern in src/lib/i18n/LocalizationProvider.tsx: a React context holds language state (seeded from localStorage), a useEffect on language calls blocksClient.localization.load(language, MODULES) and stores the merged dictionary in state, and t(key, fallback) reads cloudDictionary[key] ?? defaultDictionary[key] ?? fallback ?? key — layering the network dictionary over a build-time defaultDictionary (from src/lib/i18n/dictionary.ts, generated from the same keys as the seed JSON in blocks/localization/*.json) as an offline/first-paint safety net, itself falling back to the caller-supplied fallback and finally the key. Mirror this shape rather than inventing your own provider — it's already generated into new projects. Note the scaffold's own t() is a plain function on context, not the SDK's localization.t() — either is fine; the SDK's built-in t() needs no separate context/provider if you're happy reading blocksClient.localization.t(...) directly in components.
t() lookup details worth knowing
- If you pass
moduleName,t()does an exact`${language}:${moduleName}`cache lookup — deterministic. - If you omit
moduleName,t()scans all cached dictionaries and returns the first match whose cache key starts with`${language}:`(or any language if you didn't pass one). Scan order follows Map insertion order, which is the order the underlying HTTP requests resolved in (not necessarily the order you listed modules inload()) — fine when keys are unique across modules, ambiguous if two modules define the same key. PassmoduleNameexplicitly whenever you know it and key collisions across modules are possible. t()never throws and never fetches — callload()/translations()(or the cloud variants) first, or every lookup falls straight tofallback/the key.
Gotchas
- No raw fetch/curl, ever — every read here goes through
blocksClient.localization.*. The SDK already sendsx-blocks-keyand, for the authenticated variants, the caller's access token when configured. - One client, one cache — don't call
createBlocksClient()more than once in the app; import the scaffold'sblocksClientsingleton everywheret()/load()is needed, or dictionaries loaded in one part of the app won't be visible in another. translations/cloudTranslationstake(moduleName, language)— module first.- Dictionaries only contain string values — the SDK strips any non-string fields from the raw response (and unwraps a
dataenvelope if present) before caching, so don't expect nested objects in a loaded dictionary. - This skill doesn't author content. Adding a new key/module or changing a translated value goes through
blocks-localization-configuration'sblocks localization *commands, not this skill.
Example trigger prompts
- "Add a language switcher and translate the UI."
- "Load the
commonanddashboardtranslation modules on app startup and use them to render labels." - "The Assets page still has hard-coded English strings — replace them with
t()lookups." - "Show only the languages this tenant actually has configured, with the default one preselected."
- "I need one specific translated key without pulling down the whole module."
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

