sittari-studio

strings

by sittari-studio
payload-plugins
Localized content
v4
^4.0.0-0
MIT

Overview

Summary generated from the README

Adds a single localized global to Payload where each scope becomes an admin tab and a nested API property. Developers define scopes and string keys in plugin config, and editors translate them per locale. Helper functions resolve keys like general.cancelButton across all locales in one query, falling back to a developer-defined default value. Requires Payload localization to be configured and Payload 4.

Features

  • Generates one localized global with a tab per scope
  • Per-string default value shown as admin placeholder and used as runtime fallback
  • getTranslations helper loads all locales in a single query
  • getStrings and createTranslator for caching and shared fetches
  • Custom global slug and overrides option for hooks and access control
  • Localized scope labels and field descriptions

Use cases

  • Manage frontend button and form labels as editable translations without hardcoding them
  • Let editors translate interface strings per locale from the admin panel
  • Serve UI copy to a Next.js app with isolated locales and safe defaults

From the author

Developer-defined UI strings global for Payload CMS with scoped tabs and localized text fields.

Installation

npm i @sittari/payload-strings

0

Stars

0

Forks

0

Open Issues

2 months ago

Last Updated

13

Weekly Downloads

v0.2.0

npm Version

35.0 KB

Unpacked Size

0

Dependencies

Repository stars

00 since Sep 6

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
Oct 31, 20260
Oct 30, 20260
Oct 29, 20260
Oct 28, 20260
Oct 27, 20260
Oct 26, 20260
Oct 25, 20260
Oct 24, 20260
Oct 23, 20260
Oct 22, 20260
Oct 21, 20260
Oct 20, 20260
Oct 19, 20260
Oct 18, 20260
Oct 17, 20260
Oct 16, 20260
Oct 15, 20260
Oct 14, 20260
Oct 13, 20260
Oct 12, 20260
Oct 11, 20260
Oct 10, 20260
Oct 9, 20260
Oct 8, 20260
Oct 7, 20260
Oct 6, 20260
Oct 5, 20260
Oct 4, 20260
Oct 3, 20260
Oct 2, 20260
Oct 1, 20260
Sep 30, 20260
Sep 29, 20260
Sep 28, 20260
Sep 27, 20260
Sep 26, 20260
Sep 25, 20260
Sep 24, 20260
Sep 23, 20260
Sep 22, 20260
Sep 21, 20260
Sep 20, 20260
Sep 19, 20260
Sep 18, 20260
Sep 17, 20260
Sep 16, 20260
Sep 15, 20260
Sep 14, 20260
Sep 13, 20260
Sep 12, 20260
Sep 11, 20260
Sep 10, 20260
Sep 9, 20260
Sep 8, 20260
Sep 7, 20260
Sep 6, 20260

Shared by 8 plugins in sittari-studio/payload-plugins.

npm weekly downloads

9−65 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 20269
Dec 4, 202610
Dec 3, 202612
Dec 2, 20266
Dec 1, 202610
Nov 30, 202610
Nov 29, 202610
Nov 28, 20268
Nov 27, 20268
Nov 26, 20266
Nov 25, 20267
Nov 24, 20263
Nov 23, 20263
Nov 22, 20264
Nov 21, 20266
Nov 20, 20269
Nov 19, 202610
Nov 18, 202613
Nov 17, 202613
Nov 16, 202613
Nov 15, 202612
Nov 14, 202610
Nov 13, 20266
Nov 12, 20265
Nov 11, 20261
Nov 10, 20265
Nov 9, 20268
Nov 8, 20267
Nov 7, 202610
Nov 6, 202610
Nov 5, 202614
Nov 4, 202614
Nov 3, 202610
Nov 2, 20267
Nov 1, 20267
Oct 31, 20264
Oct 30, 20264
Oct 29, 20260
Oct 28, 20260
Oct 27, 20260
Oct 26, 20261
Oct 25, 20262
Oct 24, 20264
Oct 23, 20264
Oct 22, 20267
Oct 21, 202611
Oct 20, 202613
Oct 19, 202613
Oct 18, 202612
Oct 17, 202613
Oct 16, 202614
Oct 15, 202617
Oct 14, 202614
Oct 13, 202612
Oct 12, 202611
Oct 11, 202612
Oct 10, 202618
Oct 9, 202625
Oct 8, 202621
Oct 7, 202623
Oct 6, 202626
Oct 5, 202626
Oct 4, 202629
Oct 3, 202629
Oct 2, 202622
Oct 1, 202620
Sep 30, 202621
Sep 29, 202619
Sep 28, 202634
Sep 27, 202631
Sep 26, 202633
Sep 25, 202633
Sep 24, 202638
Sep 23, 202641
Sep 22, 202647
Sep 21, 202653
Sep 20, 2026201
Sep 19, 2026191
Sep 18, 2026192
Sep 17, 2026190
Sep 16, 2026185
Sep 15, 2026179
Sep 14, 2026160
Sep 13, 202620
Sep 12, 202625
Sep 11, 202627
Sep 10, 202627
Sep 9, 202636
Sep 8, 202650
Sep 7, 202656
Sep 6, 202674

Each point is npm's rolling 7-day download count.

Health Score

63/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1294311885-strings.svg)](https://payloaddirectory.dev/plugins/1294311885-strings)
HTML
<a href="https://payloaddirectory.dev/plugins/1294311885-strings"><img src="https://payloaddirectory.dev/badge/1294311885-strings.svg" alt="Payload Directory"></a>
Updated Sep 11, 2026Created Jul 8, 2026Published Sep 11, 2026

README

@sittari/payload-strings

A Payload CMS plugin that generates one localized strings global for developer-defined UI strings. Each scope becomes a named tab in the admin panel and a nested property in the API response, e.g. general.cancelButton.

Install

pnpm add @sittari/payload-strings

Payload localization must be configured in the consuming project.

Basic usage

import { buildConfig } from 'payload';
import { stringsPlugin } from '@sittari/payload-strings';

export default buildConfig({
  localization: {
    defaultLocale: 'en',
    locales: ['en', 'fr'],
  },
  plugins: [
    stringsPlugin({
      scopes: {
        general: {
          labels: 'General',
          strings: {
            cancelButton: {
              defaultValue: 'Cancel',
              description: 'Shown next to destructive actions.',
            },
            saveButton: {},
          },
        },
        auth: {
          labels: {
            en: 'Authentication',
            fr: 'Authentification',
          },
          strings: {
            loginTitle: {},
          },
        },
      },
    }),
  ],
});

Reading the strings

The global is exposed through Payload's normal global endpoints and Local API. Scope keys become nested properties:

const strings = await payload.findGlobal({ slug: 'strings', locale: 'fr' });

strings.general.cancelButton; // "Annuler" (once translated)
strings.auth.loginTitle;

Runtime translation behavior — including whether missing locale values fall back to the default locale — is controlled by Payload's localization configuration and per-request fallbackLocale options, exactly as for any other localized field.

getStrings and getTranslations

For application code, getTranslations resolves keys like general.cancelButton in one shot. It loads every configured locale in a single query with locale: 'all' and fallbackLocale: false, then returns a synchronous translator:

import { getTranslations } from '@sittari/payload-strings';

const t = await getTranslations({ payload, locale: 'en' });

t('general.cancelButton'); // stored value or defaultValue or null
t('general.cancelButton', 'fr'); // per-call explicit locale

Resolution order per key and locale:

  1. The stored database value for that locale when it is a non-empty string.
  2. Otherwise the configured defaultValue.
  3. Otherwise null.

Because lookups happen with fallbackLocale: false, locales stay fully isolated: an untranslated string falls back to its developer-defined defaultValue instead of leaking another locale's wording.

The helper discovers both custom slugs (slug) and configured defaults automatically from internal metadata the plugin attaches to the Payload config, so it works without duplicating any configuration. It throws if stringsPlugin is not part of the Payload config.

getStrings

getStrings performs the single findGlobal({ slug, locale: 'all', fallbackLocale: false }) call itself and returns the normalized data behind every translator — one request for all locales, no Promise.all fan-out per locale:

import { getStrings } from '@sittari/payload-strings';

const strings = await getStrings({ payload });

Payload's locale: 'all' response is scopes-first (scope.key.locale). getStrings inverts it into a locale-first table, materializing every configured locale, scope, and key; missing, nullish, and empty stored values become the scope's defaultValue, or null when none exists (whitespace-only strings count as values):

{
  en: {
    general: {
      cancelButton: 'Cancel',   // stored '' → defaultValue
      saveButton: 'Save changes',
    },
  },
  fr: {
    general: {
      cancelButton: 'Annuler',
      saveButton: null,         // untranslated, no default
    },
  },
}

Locales missing entirely from the table (for example a requested code that is not configured) resolve to null downstream.

createTranslator

The two helpers compose explicitly: getTranslations is just createTranslator(await getStrings(...)). You can call them directly when you want the normalized table (e.g. for caching) or several translators sharing one fetch:

import { createTranslator, getStrings } from '@sittari/payload-strings';

const strings = await getStrings({ payload });
const t = createTranslator(strings, 'en');

t('general.saveButton'); // 'Save changes'
t('general.saveButton', 'fr'); // null — locales stay isolated
t('general.unknownKey'); // null

Configuration

The generated global is labeled Translations in English, Russian, and Ukrainian.

OptionTypeDefaultDescription
enabledbooleantrueSet to false to return the incoming Payload config unchanged.
slugstring"strings"Slug of the generated global.
scopesStringsScopesRequiredScope definitions keyed by the generated tab and API property name.
overrides(defaultGlobal) => GlobalConfigDefault globalExtends or replaces the final global configuration. Applied last.

scopes is required unless the plugin is disabled, and every scope must define at least one string. Scope and string names are validated by Payload like any other field name.

Strings

Each entry under a scope's strings becomes a localized text field. Labels are generated by Payload from the string key.

OptionTypeDescription
defaultValuestringShown as the admin placeholder while the string is empty, in every locale.
descriptionstring | Record<string, string>Admin description below the field, localized when keyed by locale code.

defaultValue is an editing hint only. It does not pre-seed or synchronize database values — strings stay empty until an editor saves them. When you read the global directly through Payload's Local or REST API, empty fields stay empty and defaultValue is not applied.

Through getTranslations, defaultValue becomes a runtime fallback: it is returned whenever the stored value for the requested locale is missing or an empty string, so developer-defined defaults never leave placeholder duty in direct Payload reads but still protect production UI through t.

Custom slug

stringsPlugin({
  scopes: { general: { labels: 'General', strings: { ok: {} } } },
  slug: 'ui-strings',
});

Compose with hooks

Use overrides to append hooks without losing the generated fields:

stringsPlugin({
  scopes: { general: { labels: 'General', strings: { ok: {} } } },
  overrides: (defaultGlobal) => ({
    ...defaultGlobal,
    hooks: {
      ...defaultGlobal.hooks,
      afterChange: [
        async ({ doc }) => {
          // Revalidate cached UI strings, trigger ISR, etc.
        },
      ],
    },
  }),
});

The callback must return a complete Payload GlobalConfig. Spread defaultGlobal (and nested properties you want to preserve) when making partial changes.

Customize access

The generated global uses Payload's authenticated read/update defaults. Replace them through overrides:

import { adminAccess } from './access';

stringsPlugin({
  scopes: { general: { labels: 'General', strings: { ok: {} } } },
  overrides: (defaultGlobal) => ({
    ...defaultGlobal,
    access: {
      read: () => true,
      update: adminAccess,
    },
  }),
});

Types

Configuration types are exported from the package root and from @sittari/payload-strings/types:

import type {
  GetStringsOptions,
  GetTranslationsOptions,
  LocalizedText,
  Strings,
  StringsPluginConfig,
  StringsRuntimeConfig,
  StringsScope,
  StringsScopes,
  StringsString,
  Translator,
} from '@sittari/payload-strings/types';

Similar plugins