2017 © Pedro Peláez
 

library translator

Simple translator.

image

drago-ex/translator

Simple translator.

  • Friday, July 20, 2018
  • by accgit
  • Repository
  • 1 Watchers
  • 0 Stars
  • 203 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 25 % Grown

The README.md

Drago Translator

Simple and lightweight translator for Nette Framework, providing localization support using NEON translation files., (*1)

License: MIT PHP version Tests Coding Style CodeFactor Coverage Status, (*2)

Technology

  • PHP 8.3 or higher
  • composer

Installation

composer require drago-ex/translator

Extension registration

Register the Drago\Localization\DI\TranslatorExtension in your Nette project by adding the following configuration to your neon file:, (*3)

extensions:
    - Drago\Localization\DI\TranslatorExtension(translateDir: %appDir%/locale)

Use in the presenter

To use the translator in your presenter, add the TranslatorAdapter trait:, (*4)

use Drago\Localization\TranslatorAdapter

Accessing the Current Language

You can access the currently set language using the following property:, (*5)

$this->lang;

Get Translator Instance

To get the translator instance, use the getTranslator method:, (*6)

$this->getTranslator();

Translation File Format

Translation files should be written in the NEON format. For example:, (*7)

"Hello, world!": "Hello, world!"

Using Translations in Templates

You can translate strings directly in your Latte templates using the following syntax:, (*8)

{_"Hello, world!"}

{* Using a filter for translation *}
{$var|translate}

Translating Forms

To use translations in forms, simply set the translator for the form:, (*9)

$form->setTranslator($this->getTranslator());

Route Configuration for Language Switching

Set up your routes to support language prefixes. For example, you can define routes with language codes:, (*10)

$router->addRoute('[<lang=en cs|en>/]<presenter>/<action>', 'Presenter:action');

Switching Languages in Templates

To switch between languages in your templates, you can use n:href to pass the selected language:, (*11)

<a n:href="this, 'lang' => 'cs'">Czech</a>
<a n:href="this, 'lang' => 'en'">English</a>

The Versions

20/07 2018

dev-master

9999999-dev

Simple translator.

  Sources   Download

MIT

The Requires

 

11/06 2018

v1.0.5

1.0.5.0

Simple translator.

  Sources   Download

MIT

The Requires

 

04/06 2018

v1.0.4

1.0.4.0

Simple translator.

  Sources   Download

MIT

The Requires

 

30/05 2018

v1.0.3

1.0.3.0

Simple translator.

  Sources   Download

MIT

The Requires

 

29/05 2018

v1.0.x-dev

1.0.9999999.9999999-dev

Simple translator.

  Sources   Download

MIT

The Requires

 

29/05 2018

v2.0.x-dev

2.0.9999999.9999999-dev

Simple translator.

  Sources   Download

MIT

The Requires

 

11/01 2018

v1.0.2

1.0.2.0

Simple translator.

  Sources   Download

MIT

The Requires

 

11/01 2018

v1.0.1

1.0.1.0

Simple translator.

  Sources   Download

MIT

The Requires

 

18/10 2017

v1.0.0

1.0.0.0

Simple translator.

  Sources   Download

MIT

The Requires