Download the PHP package vladahejda/nettesimpletranslator without Composer

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

NetteSimpleTranslator

NetteSimpleTranslator is tool to simply translate your web apps based on Nette Framework.

You have an app published in certain language, e.g. english. All you need to do is fullfill your database with translated texts and easily mark them in your app to translate, see below.

Installation

Then load classes via autoloader (composer autoloading or Nette RobotLoader).

Usage

To launch the translator follow these steps:

1. prepare storage

Execute SQL script in src/Storage/NetteDatabase.createTable.sql (or its namespaced version, see using namespaces) at your database.

Open your configuration file and add service:

You can rename tables in SQL script (use the same names in config file).

Look at the interface NetteSimpleTranslator\ITranslatorStorage and implement it to write your own storage.

Then add storage into your configuration file as a service.

2. add NetteSimpleTranslator service

Into your config file add service NetteSimpleTranslator\Translator and define the default language (it is language which in your web is written basically):

3. set up your BasePresenter

Inject NetteSimpleTranslator, set current language and bring translator into template and forms:

4. mark texts for translation

In presenters call $this->translator->translate('text to translate'), in latte use underscore macro {_ 'text to translate'}

Done. Make links to switch your $language persistent parameter and see the translations.

Advanced

If you want to use your translator fully, there is some more stuff you would do.

Say translator which languages you use

Call function $translator->setAvailableLanguages() and give the array of languages that your web is available in. Then set the name of presenter language persistent parameter ($translator->setLanguageParameter()).

Better way of this is setting it in config:

Translator will now recognize the current language itself.

Use advantages of sprintf

If you give more arguments to translate method, it will be handed to php function sprintf.

That means that $translator->translate('Call me %s.', 'Johan') results in "Call me Johan", whereas "Johan" will not be translated.

It can be used in latte too.

Translate plurals (1 apple → 2 apples)

You can say what plural-form each language uses via setAvailableLanguages, this way:

(to understand this see plural forms)

Then you can add even translations in plural. All you need is to use the column variant in translations database (in case you use the NetteDatabase storage).

More you need to do is to give plural variants of the default language to the translator, in array. And the number. Example: $translator->translate( array( 'There is %d apple', 'There is %d apples' ), 3 ) or in latte: {_ ['There is %d apple', 'There is %d apples'], 3}.

Using namespaces

When there is huge amount of texts at your web, it would be good to sort them somehow. Just give the namespace to the translator dependent for example on module. $translator->setNamespace('products')

And now, enjoy.

Under New BSD License


All versions of nettesimpletranslator with dependencies

PHP Build Version
Package Version
Requires nette/utils Version ~2.3
nette/database Version ~2.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 vladahejda/nettesimpletranslator contains the following files

Loading the files please wait ....