Download the PHP package ipl/i18n without Composer

On this page you can find all versions of the php package ipl/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 i18n

Icinga PHP Library - Internationalization (i18n)

ipl/i18n provides a translation suite built on PHP's native gettext extension. It handles locale negotiation from HTTP Accept-Language headers, wires a static translator instance for use anywhere in an application, and exposes convenient global helper functions and a trait for use in classes.

Installation

The recommended way to install this library is via Composer:

ipl/i18n requires PHP 7.2 or later with the intl and gettext extensions.

Translation catalogs are expected in gettext's standard directory layout:

.mo files are compiled binary catalogs produced from human-editable .po files via msgfmt. If you do not specify a domain, ipl/i18n uses the default domain.

Usage

Setting Up the Translator

Bootstrap the translator once at application startup and assign it to StaticTranslator so that the global helper functions and the Translation trait resolve it automatically from anywhere in your application. addTranslationDirectory() accepts an optional second argument to register a named domain — see Working With Multiple Domains for details:

Global Helper Functions

Once StaticTranslator::$instance is set, import t() and tp() via use function and call them anywhere in your application:

Both functions forward to the static translator instance, so they always reflect the currently active locale.

Translation Trait

Add the Translation trait to any class that needs to translate messages. Set $translationDomain to scope translations to a specific gettext domain, or leave it null (the default) to use the default domain:

Working With Multiple Domains and Message Context

Register additional translation directories under named domains and use the domain- and context-aware methods to resolve messages precisely. Context disambiguates source strings that share the same English word but require different translations — for example, "request" as an HTTP request versus a change request:

Detecting the User's Language

Browsers send an Accept-Language header with each request listing the user's preferred languages in priority order (e.g., de-DE,de;q=0.9,en-US;q=0.8). Use Locale::getPreferred() to match that list against the locales your application actually has available and activate the best fit:

If no exact or language-level match is available, locale selection falls back to en_US by default. Use setDefaultLocale() on the Locale instance to change the fallback.

Testing With NoopTranslator

In tests you typically do not want to depend on compiled .mo catalog files being present on disk. NoopTranslator satisfies the translator interface by returning every message unchanged, so your test suite runs without any gettext setup while still exercising all code paths that call t(), tp(), or the Translation trait:

Changelog

See CHANGELOG.md for a list of notable changes.

License

ipl/i18n is licensed under the terms of the MIT License.


All versions of i18n with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-gettext Version *
ext-intl Version *
ipl/stdlib Version >=0.15.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 ipl/i18n contains the following files

Loading the files please wait ...