Download the PHP package carrooi/translator without Composer

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

Build Status

Donate

translator

PHP translator with plural forms support.

This library is compatible with node package translator.

Help

Unfortunately I don't have any more time to maintain this repository :-(

Don't you want to save me and this project by taking over it?

sad cat

Installation

Preferred way is to install via composer.

Dictionary files

This translator supposed to be translator working with key -> translation principe. For easier manipulation, you can have many smaller dictionaries for smaller group of translations.

These dictionaries are json files with language code on the beginning. Below is example of few files.

There we have got three dictionaries, two for homepage and one for about page, but these names are totally up to you.

Dictionary

Here is example of /app/lang/homepage/promo/en.box.json dictionary.

This is the most simple example of dictionary (and most stupid). Again these translation's names are up to you.

Usage

When you have got your dictionaries, you can setup translator and start using it.

You just have to set language, and base directory path.

Then you can begin with translating. You can see that messages to translate are paths to your dictionary files but with dots instead of slashes and without language code and .json extension.

Plural forms

There is already registered 138 plural forms and you can find list of them on this site. If you will miss some language, wrote issue or register it by your own.

First you have to set plural forms rule for language which you want to use. This is the same for like plural forms for gettext.

For comparing, here is example of czech plural forms.

Now we have to add plural forms to our dictionary. (/app/lang/homepage/promo/en.box.json)

%count% will be automatically replaced with count of items. Again for comparing czech version. (/app/lang/homepage/promo/cs.box.json)

And now you can finally use it.

Replacements

%count% is the base example of replacements, but you can create others. For example you can set replacement for %site% and then it will be automatically changed to name of your site, so if you will change it in future, you will change it only in one place.

Dictionary:

Usage:

This is example of persistent replacements, but you can create independent replacements for each translation.

Dictionary:

Usage:

if you do not need to pass any count (like in example above), you can remove second argument (null).

In names of translations

These replacements can be used also in message names. This is quite useful when you have got for example different user roles with different translations. Then you can set replacement with name role and save these translations into different directories.

en.admin.json:

en.normal.json:

Usage:

Filters (eg. markdown)

If you want some special formatting in your translations (for example markdown syntax or others) you can add filter which will automatically transform all successfully translated messages.

Helpers

You can imagine helpers as translation dependent filter with optional arguments.

List of translations

Sometimes you may want to display list of texts but don't want to create translations with these names: item1, item2, item3 and so on. What if you will want to add some other? This is not the good idea.

But you can create lists in your dictionary and translator will return array of translations.

Dictionary:

Usage:

And you can also use it with plural forms.

Dictionary:

Usage:

Accessing exact item

Shorter syntax

If your list contains just singular forms translations, you can use shorter syntax for it.

List of pairs

If you have got one list of for example titles or headlines and other list with texts for these titles, you can let this translator to automatically combine these two lists together into associative array.

Dictionary:

Usage:

Output:

Translate whole array

When you have got some array, which you need to translate, you don't have to iterate through it yourself.

If your array to translate contains translations just from one dictionary, you can set some kind of base path.

Or use count for translations with plural forms.

Or with some replacements.

Temporary override language

There may be some cases when you need to get translations for different language.

Now in message variable will be translation of homepage.title in czech language.

Comments in dictionaries

You can write some comments into your dictionaries. These comments has to be enclosed into #.

Or with lists:

With Nette framework

If you want to use this translator with nette, please use sakren/nette-translator library.

Changelog


All versions of translator with dependencies

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

Loading the files please wait ....