Documentation

LocalizeScriptResources
in package

Bucket-backed localize orchestration for an `AnonymousAssetBuilder`.

Table of Contents

Properties

$builder  : AnonymousAssetBuilder
Builder.

Methods

__construct()  : mixed
C'tor.
wpLocalizeScriptResources()  : array<string|int, string>|false
Localize script via bucket-backed resources and an inline bootstrap.
writeLocalizedResourceContent()  : string|false
Writes a localized resource file and returns its public URL.
buildInlineBootstrapScript()  : mixed
Builds inline bootstrap JavaScript with lazy `fetch()` support.
jsonEncode()  : string
Encodes values as JSON in WordPress and PHPUnit environments.

Properties

Methods

wpLocalizeScriptResources()

Localize script via bucket-backed resources and an inline bootstrap.

public wpLocalizeScriptResources(string $handle, string $objectName, array<string|int, mixed> $l10n[, array<string, array{path: string, strategy: "defer"|"lazy", required?: bool, include?: string[], exclude?: string[]}> $resourceGroups = [] ]) : array<string|int, string>|false

Returns enqueued defer-group handles, or false for fallback to anonymous_localize_script.

Defer groups are prepended as dependencies of $handle so WordPress prints them before the handle (resource tags, bootstrap before inline, then handle tag). The consumer applies enableDeferredEnqueue to the returned handles.

Each entry maps a group name to its definition:

  • path — Dot-separated path into $l10n (e.g. 'others.bannerI18n' or 'others').
  • strategy — 'defer' emits a separate <script src>, 'lazy' loads on demand via .fetch().
  • required — If true, returns false when the path resolves to null (default false).
  • include — Whitelist of top-level keys (or key[].nested paths) to extract into the resource file.
  • exclude — Keys to keep in the inline script and omit from the resource file (e.g. per-request values).
Parameters
$handle : string
$objectName : string
$l10n : array<string|int, mixed>
$resourceGroups : array<string, array{path: string, strategy: "defer"|"lazy", required?: bool, include?: string[], exclude?: string[]}> = []
Return values
array<string|int, string>|false

writeLocalizedResourceContent()

Writes a localized resource file and returns its public URL.

public writeLocalizedResourceContent(string $content) : string|false

Filename is simpleHash(bucketId + sha256(content)) so the URL cannot be blocked by group name. Existing files are left untouched — same content hashes to the same path.

Parameters
$content : string
Return values
string|false

buildInlineBootstrapScript()

Builds inline bootstrap JavaScript with lazy `fetch()` support.

private buildInlineBootstrapScript(string $bucketId, string $objectName, array<string|int, mixed> $l10n, array<string, array{strategy: string, url: string}> $manifest) : mixed
Parameters
$bucketId : string
$objectName : string
$l10n : array<string|int, mixed>
$manifest : array<string, array{strategy: string, url: string}>

jsonEncode()

Encodes values as JSON in WordPress and PHPUnit environments.

private jsonEncode(mixed $value) : string
Parameters
$value : mixed
Return values
string
On this page

Search results