Download the PHP package stromcom/php-i18n without Composer

On this page you can find all versions of the php package stromcom/php-i18n. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-i18n

stromcom/php-i18n

Translator client + AST scanner for PHP / Twig / XSLT sources. Connects an application to the self-hosted translator.

Zero regexes on sources. PHP via the nikic/php-parser AST, Twig via a custom Twig\NodeVisitorInterface plugged into Twig\NodeTraverser, XSLT via DOMDocument + DOMXPath (element variant — XPath inside a select= expression is still TODO).

Architecture

Tier Classes When it runs
Runtime Translator, BundleLoader, LocaleResolver, LocaleMiddleware, LocaleContext, TwigI18nExtension, MissingKeyPolicy, XsltRenderer, I18nPostProcessor, NotificationBundleLoader, HtmlFragmentSanitizer In Lambda / per request. Prefers build/locales/<locale>.cache.php (OPcache hot path) with a fallback to <locale>.json.
Scan PhpScanner, TwigScanner, XsltScanner, ScannerPipeline, AST visitors Buildtime — CI or composer i18n:sync.
Build TranslatorClient, BundleFetcher, KeySync, NotificationSync, NotificationBundleFetcher, EtagStore Buildtime — HTTP communication with the translator.
Console SyncCommand, FetchCommand, ScanCommand, StatusCommand Buildtime — CLI entry points.

Use in a consumer

DI registration

Slim middleware pipeline

Twig environment

Symfony Console

Use in the application

XSLT — two-pass renderer

The consumer calls a single method; the package runs the XSLT transformation plus post-processing of <i18n:t/> elements. AVTs in attributes (count="{$total}") are evaluated in the first pass, and attributes with concrete values then feed into MessageFormatter:

In the XSL template:

code-analysis.yml Important — escaping ICU placeholders in XSL attributes:

XSLT 1.0 evaluates {...} in attributes of literal result elements as Attribute Value Templates (AVTs) — XPath expressions. ICU placeholders such as {name} or {count, plural, ...} therefore must be doubled to {{name}} / {{count, ...}}. This is the XSLT 1.0 standard.

XsltScanner undoes that escaping, so the source_text synced to the platform is the real ICU pattern ({count, plural, one {# item} other {# items}}) rather than the doubled-brace spelling. Write the doubled form in the template and expect the collapsed form everywhere else.

Do not use <xsl:attribute> for key / default. Its text content is not an AVT, so it avoids the doubling — but it is a child element, invisible to an attribute read. Such a template renders correctly while its key never reaches the platform. The scanner emits a warning naming the attribute instead of skipping in silence.

Namespace matching is exact. Both the scanner and the renderer resolve <i18n:t/> by namespace URI (https://stromcom.cz/i18n), never by prefix — any prefix bound to that URI works. A mistyped declaration (http:// instead of https://) makes the scanner warn and the renderer throw XsltRendererException, rather than leaking a raw <i18n:t/> tag into the page.

Rules for <i18n:t/> attributes:

Attribute Meaning
key Key identifier (required, must be a literal — no AVT expression)
default Source text — ICU template (required, must be a literal)
note Metadata for translators — ignored by the runtime
others ICU MessageFormatter params ({paramName} in default); AVTs welcome here

An element without key or default → removed from the output (warning in the scanner if it passes the scan). A key or default holding an AVT expression (key="{$dynamic}") cannot be synced — the scanner warns and skips it.

Note that omit-xml-declaration="yes" has no effect for XML output: pass 2 re-serialises the post-processed DOM, so the declaration is always emitted. Use method="html" or strip it yourself if a bare fragment is required.

Notifications (e-mails) — <i18n:email>

Texts of notifications live in the translator's notification module: one template per e-mail, one field per text. Code is the source of truth — i18n:sync creates the templates and fields, the translator never has to be set up by hand.

Part Required Meaning
element name — Notification type = translator channel code: <i18n:email> → email, <i18n:sms> → sms. Every i18n element except <i18n:t> is a notification field; which channels exist is up to the translator (an unknown one fails the sync with 400).
template yes Template code ([a-z0-9][a-z0-9._-]*, case-insensitive). One e-mail = one template; shared layout texts = template layout. Literal.
key yes Field of the template (^[a-z][a-zA-Z0-9_.]{0,63}$). Literal.
format no text (default) or html. Literal.
note no Note for translators. Literal.
content yes Default text in the source locale. text = plain text, html = markup from the whitelist. Static — no xsl:* inside.
other attributes — Placeholder values (login="{login}"). AVTs welcome — they are evaluated in the first XSLT pass.

Rules:

Every broken rule is logged by the scanner as skipping <i18n:email> — <reason> (with path, line, template, key in the context) and the field is not synced.

Runtime — I18nPostProcessor

XsltRenderer runs it for you. An application with its own XSLTProcessor (e.g. with registerPHPFunctions()) calls it on its own result tree:

It resolves <i18n:t> and <i18n:email> in one pass. A field's text comes from notification bundle[locale] → [sourceLocale] → the element's content; a missing translation goes through MissingKeyPolicy ([i18n] Missing notification translation). A lookalike in a foreign namespace (mistyped xmlns:i18n) throws XsltRendererException.

CLI

The same commands handle keys and notifications. The notification part is skipped when notificationBundlesDir is not configured.

Quality

Test layout mirrors src/, plus:

Directory Contents
tests/Integration/ Cross-class contracts — notably the XSLT scanner ⇄ renderer round-trip
tests/Support/ Doubles: TmpDir, CollectingLogger, HttpRecorder, RecordingScanner, StaticScanner, InMemoryBundleLoader, InMemoryNotificationBundleLoader

HTTP is exercised through symfony/http-client's MockHttpClient (no network in the suite), console commands through CommandTester.

composer mutate accepts the usual Infection arguments, so a single class can be probed in isolation:

Mutation testing needs a coverage driver and ext-intl for the ICU tests:

Then in consumers' composer.json:

Upgrading from 0.1

What the package does not do

On-disk bundle format

i18n:fetch writes two files per locale:

File Purpose Who reads it
build/locales/<locale>.json Source of truth, flat {key: text} map with sorted keys BundleLoader as a fallback, debugging
build/locales/<locale>.cache.php <?php return [flat-map] via var_export OPcache hot path — require caches bytecode in shared memory, no json_decode

Notification bundles go to notificationBundlesDir/<locale>.json (+ .cache.php) as the bare, recursively sorted {template: {field: text}} map. Their ETags share .i18n-etags.json under notifications:<locale>.

The response envelope ({version, locale, generated_at, translations}) is not stored: bundles are committed build inputs, and generated_at would change the file on every fetch, so no publish gate could compare a committed bundle against the published one. BundleLoader still accepts the wrapped shape, so hand-written or legacy bundles keep working.

BundleLoader tries .cache.php first only if its mtime is ≥ the JSON. After i18n:fetch the mtimes are synced (via touch()). If someone manually edits the JSON (mtime > PHP cache), the loader detects it and falls back to JSON — no stale cache.

For Lambda (singleton BundleLoader + in-memory cache) the difference is 0 — the bundle is parsed once per cold start. For PHP-FPM hosting OPcache is a win: bytecode is shared between workers, 0 parsing after the first request any worker made.


All versions of php-i18n with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-dom Version *
ext-json Version *
ext-libxml Version *
psr/container Version ^2.0
psr/http-message Version ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
psr/log Version ^3.0
nikic/php-parser Version ^5.0
php-di/php-di Version ^7.0
symfony/console Version ^7.0|^8.0
symfony/http-client Version ^7.0|^8.0
symfony/http-client-contracts Version ^3.0
twig/twig Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package stromcom/php-i18n contains the following files

Loading the files please wait ...