Download the PHP package webmunkeez/i18n-bundle without Composer

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

WebmunkeezI18nBundle

This bundle unleashes internationalization on Symfony applications.

Installation

Use Composer to install this bundle:

Add the bundle in your application kernel:

Configuration

The bundle prepends sane framework.default_locale/framework.translator/framework.set_content_language_from_locale defaults so a fresh app works out of the box, but enabled_locales itself has no default — every consuming application must declare it explicitly.

Usage

Languages

\Webmunkeez\I18nBundle\Repository\LanguageRepositoryInterface (backed by LanguageDependencyInjectionRepository, built from enabled_locales) exposes findAll(), findOneByLocale(string $locale) (throws LanguageNotFoundException), findOneDefault() (the first enabled locale) and localeExists(string $locale): bool. Each Language::getName() uses Symfony\Component\Intl\Locales, so region-specific entries get a distinct, region-aware name — fr_FR and fr_CA both configured side by side come out as "Français (France)" and "Français (Canada)" rather than colliding on a single "Français".

LocaleRequestListener runs on every request: if a _locale query parameter is present and enabled, it becomes the request locale and a \Webmunkeez\I18nBundle\Model\Language is stored as the current-language request attribute; otherwise it falls back to whatever current-language is already set (e.g. by the multi-site listener below) or to findOneDefault().

The #[Webmunkeez\I18nBundle\Validator\Constraint\Locale] constraint validates that a string property is one of the enabled locales:

Language-aware objects

Any translation-like class can implement \Webmunkeez\I18nBundle\Model\LanguageAwareInterface (getLocale() + getLanguage()/setLanguage()) to get its Language resolved and cached lazily:

The language() Twig function resolves it (and caches the result back onto the object, so it's only looked up once):

It also accepts a raw locale string directly — useful when you don't have a LanguageAwareInterface object at hand (this call is never cached, since there's nowhere to store the result):

\Webmunkeez\I18nBundle\Serializer\Normalizer\LanguageAwareNormalizer does the same resolution automatically when serializing any LanguageAwareInterface object.

The language_name() Twig function returns a language's autonym (its name in its own language) from any ISO code, regardless of enabled_locales — unlike language(), it never fails on a language that isn't configured. It accepts both a plain language code and a full locale (region part is ignored), and returns null if the code isn't a valid language:

Pass a second argument to get the name translated into another language instead of its autonym:

Translations

A translatable entity implements \Webmunkeez\I18nBundle\Model\TranslationAwareInterface (getTranslations()/getTranslation(string $locale), throwing TranslationNotFoundException) over a collection of \Webmunkeez\I18nBundle\Model\TranslationInterface (itself just LocaleAwareInterface, typically also implementing LanguageAwareInterface):

TranslatorAware

\Webmunkeez\I18nBundle\Translation\TranslatorAwareInterface/TranslatorAwareTrait give any service $this->trans() and $this->getTranslatorCatalogue(), wired automatically by an idempotent compiler pass (it only injects the translator if you haven't already configured your own setTranslator() call on that service, so your own explicit wiring is never silently overridden):

Multi-site

If your application serves several sites/locales behind different hosts and/or path prefixes, declare them under webmunkeez_i18n.sites (each entry validates that its locale, if set, is part of enabled_locales). position is required, must be at least 1 and must be unique across sites — it's purely a display ordering: findAll()/findAllLocalized() and the sites() Twig function sort by it, from the smallest position to the largest, regardless of declaration order. It has no effect on routing: findOneByUrl() (used by SiteRequestListener to resolve the current request) always matches against sites in declaration order, so the catch-all-last rule below still applies independently of position.

path is a plain literal path prefix (not a regex) — a request matches when its URI starts with path followed by / or the end of the string, so /api matches /api and /api/anything but not /apiary. Omitting path entirely matches any path on that host (an explicit path: null is rejected, same as an empty string — leave the key out instead), so declare the catch-all site for a given host last — regardless of its position, which only affects display order.

host can be omitted the same way to match any host — useful when every request lands on the same Symfony project regardless of subdomain (e.g. a wildcard DNS setup with subdomain1.example.com, subdomain2.example.com, etc. all pointing at the same app) and the routing should only depend on the path, not which subdomain was used:

SiteRequestListener runs before LocaleRequestListener and resolves the current request into either a \Webmunkeez\I18nBundle\Model\Site (host + path, no locale) or a \Webmunkeez\I18nBundle\Model\LocalizedSite (also LanguageAwareInterface) via \Webmunkeez\I18nBundle\Repository\SiteRepositoryInterface::findOneByUrl(), throwing SiteNotFoundException (converted to a 404) if nothing matches. The resolved site is stored as the current-site request attribute, and for a matched LocalizedSite the request locale and current-language are set immediately — before LocaleRequestListener even runs. The listener is a no-op entirely (no site resolution attempted) when no site is configured.

The sites() Twig function lists every configured site (SiteRepositoryInterface::findAll()) — useful for rendering a language/site switcher:

Ago filter

The ago Twig filter formats a \DateTimeInterface (\DateTime or \DateTimeImmutable) as a human-readable relative time, translated through the date_interval.* message keys. It only accepts dates in the past — a future date throws an \InvalidArgumentException:

Exceptions


All versions of i18n-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
symfony/config Version ^7.4
symfony/dependency-injection Version ^7.4
symfony/expression-language Version ^7.4
symfony/intl Version ^7.4
symfony/property-access Version ^7.4
symfony/property-info Version ^7.4
symfony/serializer Version ^7.4
symfony/string Version ^7.4
symfony/translation Version ^7.4
symfony/uid Version ^7.4
symfony/validator Version ^7.4
twig/twig Version ^3
webmunkeez/cqrs-bundle 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 webmunkeez/i18n-bundle contains the following files

Loading the files please wait ...