Download the PHP package simplesamlphp/twig-configurable-i18n without Composer

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

Configurable Internationalization with Twig

This is a hack to get Twig's native internationalization extension to work with other translation systems than PHP's native gettext extension. That way, you can use other implementation, such as gettext/gettext or even your own one, provided a function is available to perform translations for singular strings, and another one for plural strings.

Installation

If you are using composer, installation is as easy as requiring this package:

If you are not using composer, you will need to manually include all (four) source files in this project from your script, and make sure you have the twig/extension package installed as well.

Usage

Using this extension is extremely simple, and won't require you to modify your code or existing templates, but just a couple of modifications to the PHP scripts where you want internationalization.

First, create aliases for two classes so that the ones defined in this extension override the default ones:

The first line allows you to redefine the twig environment class, so that you can keep the configuration options you pass to the constructor. The second line installs this extension instead of the native one. Your code will use now this extension without further modifications, and PHP's native gettext will continue to be used.

Now, you are ready to configure the extension to use different translation functions. You will do that by passing options to the Twig environment class you have just imported:

These are the only two supported options. translation_function lets you specify a function that is capable to translate strings in singular, being equivalent to gettext(). On the other hand, translate_function_plural lets you specify a function to handle the translation of strings in plural. This one is equivalent to ngettext().

You are all set. Twig will use the translate() and translate_plural() functions you have just specified, instead of the native gettext() and ngettext() functions. Of course, you will need to specify some functions that actually exist, but that depends on what implementation of gettext you want to use. If, for example, you plan to use Oscar Otero's pure-PHP implementation gettext/gettext, you can do the following:


All versions of twig-configurable-i18n with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
twig/extensions Version @dev
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 simplesamlphp/twig-configurable-i18n contains the following files

Loading the files please wait ....