Download the PHP package czukowski/i18n-nette without Composer

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

Introduction

This package will help you to do grammatically accurate translations in your Nette application (framework version 2.2+ supported; still working great in 2.4, yay!).

The suggested translation sources for Nette application are actually Neon files which may be located virtually anywhere in the application, for example, app/i18n folder, this will be used for the examples. Note that you are not limited in where you store your translations: also pure PHP files, databases and even all of them together may be used!

Installation and setup

Add to your application using Composer:

composer require czukowski/i18n-nette

Add I18n service to your configuration file:

Place your translations into the i18n directory, like this:

If you request the translation for 'fr-CH' locale, it'll look in the fr/ch.neon first, and failing that in the general fr.neon. If the translation wasn't found even there, the untranslated input string is returned.

The translation data structure is very similar to what you're used to in Neon configuration (may be either flat or nested, your choice!):

Some of the Nette controls are ready for translations, you just need to set the translator instance to them in your factories, for example (assuming $this->translator is an instance of the translator service provided by this package):

After setting the translator to the templates, you'll be able to use the translation macro: {_'translate this'}. We'll get into the details on its usage later on.

Configuration options

Configuration options available for this Nette extension:

How to make the translations work

You can find the information about the translation contexts, plural forms and even more in the base package readme. It is omitted here in order to avoid duplication.

Translating in Nette templates

Here are some examples, those are pretty self-explanatory:

// Basic translation.
{_'Welcome!'}
// Translation with context.
{_'New customer has been saved.', $customer->gender}
// Translation with parameters and context skipped.
{_'Hi, my name is :name', [':name' => $name]}
// All arguments present, including target language.
{_'You have :count messages', $count, [':count' => $count], 'cs'}

Note: if you use useNeonStyleParams, the translation could look like:

{_'You have %count% messages', $count, ['count' => $count], 'cs'}

API

The base package API is covered in its own readme.

class I18n\NetteTranslator

You are not required to use core object directly. This class is a Nette-compatible wrapper and it's the suggested usage in Nette applications. See above for an example on how to setup a trasnlation service.

public function __construct($default_lang = 'x', $use_neon_style_params = FALSE)

Translator constructor takes default language to use when none is specified explicitly. Initializes a Core object instance internally.

public function attach(I18n\Reader\ReaderInterface $reader)

Attaches a Reader object to the Core object (see below). I18n\Nette\NeonReader is a suggested default reader for Nette application, although there's I18n\Nette\NetteReader that gets translations from raw PHP files placed similarly into the Nette application, and you may of course also implement your own readers to provide translations from any source of your choice.

public function getAvailableLanguages()

Returns list of available languages.

public function setAvailableLanguages($langs)

Sets list of available languages.

public function getDefaultLanguage()

Returns default language, used when no target language passed to translate function call.

public function setDefaultLanguage($lang)

Sets default language.

public function setLanguageFromHeaders(Nette\Http\IRequest $httpRequest)

Sets default language from HTTP Request headers, if at least one of accepted language is contained in the available languages list. The one with the highest priority is chosen.

public function setTranslator($object)

Sets Nette translator ($this object instance) to the compatible objects:

public function translate($string, $count, $parameters, $lang)

The $parameters values (array) may be passed as 2nd argument, in that case $count is considered NULL and $lang is the 3rd argument.

public function getService()

Returns the internal Core object reference if needed for some reason.

License

The distribution is permitted under the MIT License. See LICENSE.md for details.


All versions of i18n-nette with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
czukowski/i18n Version ~1.0
nette/caching Version ~2.2
nette/di Version ~2.2
nette/http Version ~2.2
nette/neon Version ~2.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 czukowski/i18n-nette contains the following files

Loading the files please wait ....