Download the PHP package a21/lexicon-client without Composer
On this page you can find all versions of the php package a21/lexicon-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download a21/lexicon-client
More information about a21/lexicon-client
Files in a21/lexicon-client
Package lexicon-client
Short Description Laravel client for Lexicon: export, pull, import, extract/push, UGC sync, pull-lang, and scan-usage webhooks.
License MIT
Homepage https://github.com/A21-Center/lexicon-client
Informations about the package lexicon-client
a21/lexicon-client
Laravel package to connect any client application to a central Lexicon translation server.
Lexicon is a SaaS-style translation source of truth. This package lets an app:
- import / pull interface translations (
lang/*.php,lang/*.json), - extract & push translatable content from files, Blade templates and the database using configuration-only extractors,
- receive UGC translations from Lexicon into a local
entity_translationstable viaPOST /api/localization/sync(Google MT / Gallery), -
do all of it through Artisan commands, with secrets kept server-side.
- Requirements
- Installation
- Configuration
- Environment variables
- UGC sync (entity_translations)
- The
lexicon.jsonmanifest - Authentication & HTTP
- Artisan commands
- Translation layers
- Extractors
- Scheduling
- Programmatic usage
- Security
- Troubleshooting
Requirements
- PHP 8.1+
- Laravel 10.x, 11.x or 12.x (
illuminate/*^10|^11|^12)
Installation
The service provider is auto-discovered via Laravel package discovery
(extra.laravel.providers), so no manual registration is needed. If you disable
auto-discovery, register it manually in config/app.php (or
bootstrap/providers.php on Laravel 11+):
Publish the config file and scaffold the manifest:
For Gallery / UGC Google MT sync (consumer table + webhook):
See docs/ugc-entity-translations-sync.md.
Configuration
config/lexicon.php (published) reads everything from the environment:
| Key | Purpose |
|---|---|
api_url |
Base URL of the Lexicon server (the client calls {api_url}/api/lexicon). |
client_code |
Integration client identifier (falls back to lexicon.json → client). |
project_code |
Target project (falls back to lexicon.json → project). |
secret |
Integration client secret — server-side only. |
environment |
Logical environment sent to Lexicon (local/develop/production). |
manifest |
Absolute path to lexicon.json (defaults to the project root). |
output.* |
How pulled translations are written back to lang/. |
http.* |
Timeouts and retry policy for outbound requests. |
Environment variables
Add to .env (never commit secrets):
Get LEXICON_CLIENT_SECRET by creating an integration client on the Lexicon
server (admin API); the secret is shown once.
LEXICON_SYNC_SECRET must match integration_clients.sync_secret on Lexicon,
and Lexicon sync_url must point to https://your-api/api/localization/sync.
UGC sync (entity_translations)
Dual-store model:
| Store | Role |
|---|---|
| Lexicon DB | Edit / Google MT / approve |
| This app DB | Synced copy for Gallery (approved-only) |
This publishes the entity_translations migration, registers
POST /api/localization/sync when LEXICON_UGC_SYNC_ENABLED=true, and documents
the two secrets (inbound client secret vs outbound sync secret).
Full guide: docs/ugc-entity-translations-sync.md.
The lexicon.json manifest
A non-secret file at the project root, versioned with your app. It is merged
with config/lexicon.php at runtime (config wins for credentials; the
manifest provides client/project fallbacks plus languages, areas,
output, import and extractors).
Never put
LEXICON_CLIENT_SECRETinlexicon.json.
Authentication & HTTP
All requests go to {api_url}/api/lexicon/... with these headers (built by
LexiconHttpClient):
| Header | Value |
|---|---|
Authorization |
Bearer <secret> |
X-Lexicon-Client |
client_code |
X-Lexicon-Project |
project_code |
X-Lexicon-Environment |
environment |
Accept |
application/json |
Requests use the configured timeout, and automatically retry retry_times
on 5x server errors. Endpoints used: /client/status, /client/export,
/client/import, /integrations/translate.
Artisan commands
| Command | Description |
|---|---|
php artisan lexicon:init |
Create lexicon.json and append keys to .env.example. |
php artisan lexicon:install-ugc-sync |
Publish entity_translations migration + enable Lexicon→app sync webhook. |
php artisan lexicon:status |
Check server connection and project metadata. |
php artisan lexicon:export |
Request an export bundle from the server. |
php artisan lexicon:import |
Scan local lang/ files and import into Lexicon. |
php artisan lexicon:pull |
Write only files whose Lexicon content hash changed. |
php artisan lexicon:extract |
Preview translatable content from configured extractors (read-only). |
php artisan lexicon:push |
Extract and push translatable content to Lexicon. |
php artisan lexicon:sync |
Extract configured sources and synchronise them with Lexicon. |
php artisan lexicon:scan-usage |
Scan exact translation key literals in client code and report Used/Unused to Lexicon. |
Key usage scan (exact literals only)
V1 marks a catalog key Used only when an exact string literal appears in code
(__('age_artist'), @lang('…'), t('…'), …). Dynamic concatenations like
__('artist.'.$id) are ignored and stay Unused unless the same literal is
found elsewhere.
Options: --application, --path=*, --lang=*, --dry-run,
--no-replace-unmentioned.
Import / pull (interface layer)
Prefer lexicon:pull without --force. PHP output defaults to
merge=add_missing: only new non-empty leaf keys under existing top-level
branches are injected. Use --replace (or output.merge=replace) to
overwrite full trees from Lexicon. Use --force only to rewrite even when the
Lexicon content is unchanged.
Extract / push / sync (all layers)
Shared options: --group=<name> (repeatable), --entity=<type> (repeatable),
--all, --dry-run.
The push summary reports created vs already existing entries and any
failures. Pushing never deletes server-side keys or translations.
Translation layers
Every pushed entry carries a layer describing how it is sourced and keyed:
| Layer | Typical source | Key strategy |
|---|---|---|
interface |
lang/*.php, lang/*.json |
nested dotted key path |
template |
Blade views / email templates | {template_path}_{segment} |
database |
DB rows owned by the app | {code\|slug\|id}_{field} |
content |
CMS-style entities | {entity_type}_{entity_id}_{field} |
Google MT: Lexicon generates and accepts Google MT suggestions for all
layers (content, interface, template, database). The Lexicon UI review
workflow labels (draft / needs_review) are emphasized for content
projects; UGC / Gallery entity sync (needs_review=true) remains the consumer
path for CMS-style content.
Extractors
Declare an extractors array in lexicon.json. Each item is matched to an
extractor by type. group and entity_type power the --group/--entity
filters. Relative base_path / paths are resolved against the app root.
| Type | Reads | Key definition fields |
|---|---|---|
files |
lang/ for the source locale (flattened) |
base_path, source_language, formats |
blade |
.blade.php — __(), trans(), @lang() (deduped) |
paths[], area |
database / content |
rows from a DB table via Illuminate\Support\Facades\DB |
connection, table, id_column, code_column, fields[], where{}, source_url |
The database/content extractors use your configured Laravel database
connections. connection: null uses the default connection; set it to any name
from config/database.php. where maps column => value (a null value
becomes WHERE column IS NULL). source_url supports {id} and {code}
placeholders so translators can jump back to the source screen.
See docs/extraction-and-layers.md for the full reference and a custom-extractor guide.
Scheduling
Run extraction on a schedule (e.g. keep DB content in sync nightly). In
app/Console/Kernel.php (Laravel 10) or routes/console.php (Laravel 11+):
Programmatic usage
Call the extraction engine or HTTP client directly from your own services:
A custom extractor only implements A21\LexiconClient\Extraction\Extractor
(type() + extract(array $definition): array returning ExtractedEntry[]).
Server setup
Create an integration client on the Lexicon server (admin API), copy the secret
once, then configure this package. See the Lexicon server docs:
docs/client-package.md, docs/client-package-js.md (npm),
docs/integration-api.md, docs/export-cli.md.
Security
- Keep
LEXICON_CLIENT_SECRETandLEXICON_SYNC_SECRETserver-side only (.env), never inlexicon.jsonor any frontend code. - Frontends must call your backend, which then calls Lexicon with the client secret.
- Lexicon calls your
/api/localization/syncwith the sync secret (outbound webhook).
Troubleshooting
Lexicon configuration is incomplete— setLEXICON_API_URL,LEXICON_CLIENT_CODE,LEXICON_PROJECT_CODE,LEXICON_CLIENT_SECRET.No extractors defined in lexicon.json— add anextractorsarray to the manifest, or run the file-based commands (lexicon:import/lexicon:pull).No extractor registered for type: X— thetypein a definition must be one offiles,blade,database,content, or a custom registered type.- 401/403 — the secret/client/project headers don't match a Lexicon integration client with access to the project.
License
MIT
All versions of lexicon-client with dependencies
illuminate/contracts Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0