Download the PHP package philipp15b/php-i18n without Composer

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

PHP i18n

Latest Stable Version Build Status

This is a simple i18n class for PHP. Nothing fancy, but fast, because it uses caching and it is easy to use. Try it out!

Some of its features:

Requirements

Setup

There's a usable example in the example.php file. You just have to follow these easy five steps:

1. Create language files

To use this class, you need to create translation files with your translated strings. They can be .ini/.properties, .json or .yaml files. This could look like this:

lang_en.ini (English)

lang_de.ini (German)

Save both files in the directory you will set in step 4. The files must be named according to the filePath setting, where '{LANGUAGE}' will be replaced by the user's language, e.g. 'en' or 'de'.

2. Include the class

3. Initialize the class

4. Set some settings if necessary

The possible settings are:

Shorthand

There is also a shorthand for that: you can set all settings in the constructor.

The (all optional) parameters are:

  1. the language file path (the ini files)
  2. the language cache path
  3. fallback language
  4. the prefix/compiled class name

5. Call the init() method to load all files and translations

Call the init() file to instruct the class to load the appropriate language file, load the cache file or generate it if it doesn't exist and make the L class available so you can access your localizations.

6. Use the localizations

To call your localizations, simply use the L class and a class constant for the string.

In this example, we use the translation string seen in step 1.

As you can see, you can also call the constant as a function. It will be formatted with vsprintf.

Also, like in the two last examples, a helper function with the same name as the class makes it easier to dynamically access the constants if ever needed.

Thats it!

How the user language detection works

This class tries to detect the user's language by trying the following sources in this order:

  1. Forced language (if set)
  2. GET parameter 'lang' ($_GET['lang'])
  3. SESSION parameter 'lang' ($_SESSION['lang'])
  4. HTTP_ACCEPT_LANGUAGE (can be multiple languages) ($_SERVER['HTTP_ACCEPT_LANGUAGE'])
  5. Fallback language

php-i18n will remove all characters that are not one of the following: A-Z, a-z or 0-9 to prevent arbitrary file inclusion. After that the class searches for the language files. For example, if you set the GET parameter 'lang' to 'en' without a forced language set, the class would try to find the file lang/lang_en.ini (if the setting langFilePath was set to default (lang/lang_{LANGUAGE}.ini)). If this file doesn't exist, php-i18n will try to find the language file for the language defined in the session variable and so on.

How to change this implementation

You can change the user detection by extending the i18n class and overriding the getUserLangs() method:

This very basic extension only uses the GET parameter 'language' and the session parameter 'userlanguage'. You see that this method must return an array.

Note that this example function is insecure: getUserLangs() also has to escape the results or else i18n will include arbitrary files. The default implementation is safe.

Fork it!

Contributions are always welcome.


All versions of php-i18n with dependencies

PHP Build Version
Package Version
Requires mustangostang/spyc Version 0.6.2
php Version >= 5.3
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 philipp15b/php-i18n contains the following files

Loading the files please wait ....