Download the PHP package michaelspiss/translation without Composer

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

Translation

A file based translation component without dependencies.

Build Status Coverage Status Latest Stable Version License

It supports every file format you throw at it, pluralization, placeholders, is fully tested and documented.

Installation

To install the package with Composer, simply run the following command:

Basic usage

Instantiating a new Translator is easy: Simply pass it the default locale ('en' in this case) and the path to your translations directory!

The component uses keys in the dot-notation to identify which string to load. To get a string in a specific language use the trans() method and pass it the key:

In this case the string would be found in path/to/translations/en/message.php. The file itself would look like "message.php" below.

Folder structure

Language strings are stored in files in the directory you passed the Translator during initialization. Within this directory each subfolder represents a supported language and holds the translation files.

A translation file would simply look like the following:

message.php

Even though only .php files are supported out-of-the-box, translation files can be of every format. For more information, please see the corresponding wiki article.

Setting the locale

Normally, the locale is only set once, at the initialization. But the component also allows you to change the locale mid-way, of course:

Additionally you can request single translation strings in a specific language without setting a new locale and resetting it afterwards:

Using placeholders

In your translation files, a placeholder is defined by putting curly braces around the placeholder name (upper- and lowercase letters only):

message.php

Now you can add an array to your trans() call containing values for the placeholders:

You can have as many placeholders in a string as you like!

Pluralization

To enable pluralization for a string simply add a pipe-character between the singular and plural form in your translation file:

message.php

The second option is a bit more advanced and actually allows you to set your own rules:

You can use the following expressions:

Expression Meaning
{3} match exactly 3
[1,10] match everything from 1 to 10, including 1 and 10
[11,*] match everything from 11 to infinite including 11
]10,20] match everything from 10 to 20, excluding 10, including 20
]10,20[ match everything from 10 to 20, excluding 10 and 20
[10,20[ match everything from 10 to 20, including 10, excluding 20

Expressions also support integers and floats!

To get the string use the transChoice() method, which takes an additional number argument (type int or float):

Read more

If you want further information on the Translator's methods or how to use other file formats than .php check out this project's wiki!

PHP Requirements

License

MIT


All versions of translation with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 michaelspiss/translation contains the following files

Loading the files please wait ....