Download the PHP package m1sh0u/polyglot-php without Composer

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

Polyglot.php

Latest Version on Packagist Tests Code Quality Total Downloads

Polyglot.php is a tiny I18n helper library written in PHP, which is based entirely on the Polyglot.js Airbnb's I18n javascript library.

The reason behind the decision to replicate the Airbnb's javascript library was to have a small, but yet powerful library, for developers to use the same way of internationalizing their PHP back-ends as they do in the front-end apps.

Polylglot doesn’t perform any translation; it simply gives you a way to manage translated phrases from your server-side PHP application.

Installation

install with composer:

$ composer require m1sh0u/polyglot-php

Running the tests

Clone the repo, run composer update --prefer-dist --dev, and composer test, or composer test-win for windows.

Usage

Instantiation

First, create an instance of the Polyglot class, which you will use for translation.

Polyglot is class-based so you can maintain different sets of phrases at the same time, possibly in different locales.

See Options Overview for information about the options array you can choose to pass to new Polyglot.

Translation

Tell Polyglot what to say by simply giving it a phrases key-value pair, where the key is the canonical name of the phrase and the value is the already-translated string.

You can also pass a mapping at instantiation, using the key phrases:

Polyglot doesn’t do the translation for you. It’s up to you to give it the proper phrases for the user’s locale.

Interpolation

Polyglot->t() also provides interpolation. Pass an array with key-value pairs of interpolation arguments as the second parameter.

Polyglot also supports nested phrase objects.

The substitution variable syntax is customizable.

Pluralization

For pluralization to work properly, you need to tell Polyglot what the current locale is. You can use $polyglot->locale("fr") to set the locale to, for example, French. This method is also a getter:

You can also pass this in during instantiation.

Currently, the only thing that Polyglot uses this locale setting for is pluralization.

Polyglot provides a very basic pattern for providing pluralization based on a single string that contains all plural forms for a given phrase. Because various languages have different nominal forms for zero, one, and multiple, and because the noun can be before or after the count, we have to be overly explicit about the possible phrases.

To get a pluralized phrase, still use $polyglot->t() but use a specially-formatted phrase string that separates the plural forms by the delimiter ||||, or four vertical pipe characters.

For pluralizing "car" in English, Polyglot assumes you have a phrase of the form:

In English (and German, Spanish, Italian, and a few others) there are only two plural forms: singular and not-singular.

Some languages get a bit more complicated. In Czech, there are three separate forms: 1, 2 through 4, and 5 and up. Russian is even more involved.

$polyglot->t() will choose the appropriate phrase based on the provided smart_count option, whose value is a number.

As a shortcut, you can also pass a number to the second parameter:

Custom plural rules

If needed, one can replace the existing plural rules or specify new custom plural rules for certain locales. The custom plural rules must be objects which implements Polyglot\Pluralization\Rules\RuleInterface. They will be passed to the Polyglot pluralRules option as a key-value pair where the key is the locale and the value is the custom rule object.

Let's define a custom plural rule for romanian language:

Now you can pass it to the Polyglot options to be used whenever the ro locale is used for pluralization:

Public Instance Methods

Polyglot->t($key, $interpolationOptions)

The most-used method. Provide a key, and t() will return the phrase.

The phrase value is provided first by a call to $polyglot->extend() or $polyglot->replace().

Pass in an object as the second argument to perform interpolation.

Pass a number as the second argument as a shortcut to smart_count:

If you like, you can provide a default value in case the phrase is missing. Use the special option key "_" to specify a default.

Polyglot->extend($phrases)

Use extend to tell Polyglot how to translate a given key.

The key can be any string. Feel free to call extend multiple times; it will override any phrases with the same key, but leave existing phrases untouched.

Polyglot->unset($keyOrArray)

Use unset to selectively remove keys from a polyglot instance. unset accepts one argument: either a single string key, or an array whose keys are string keys, and whose values are ignored unless they are nested arrays (in the same format).

Example:

Polyglot->locale(?$localeToSet)

Get or set the locale (also can be set using the constructor option, which is used only for pluralization. If a truthy value is provided, it will set the locale. Afterwards, it will return it.

Polyglot->clear()

Clears all phrases. Useful for special cases, such as freeing up memory if you have lots of phrases but no longer need to perform any translation. Also used internally by replace.

Polyglot->replace($phrases)

Completely replace the existing phrases with a new set of phrases. Normally, just use extend to add more phrases, but under certain circumstances, you may want to make sure no old phrases are lying around.

Polyglot->has($key)

Returns true if the key does exist in the provided phrases, otherwise it will return false.

Polyglot->phrases()

Returns all the phrases.

Polyglot->transformPhrase($phrase[, $substitutions[, $locale[, $tokenRegex]]])

Options Overview

new Polyglot accepts a number of options:

Related projects


All versions of polyglot-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
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 m1sh0u/polyglot-php contains the following files

Loading the files please wait ....