Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/68publishers/translation-bridge

🌉 Integrations of translation components and '68 Publishers bundles
https://github.com/68publishers/translation-bridge

bridge bundle extension nette nette-extension translation

Last synced: 2 months ago
JSON representation

🌉 Integrations of translation components and '68 Publishers bundles

Awesome Lists containing this project

README

        

Translation bridge


Checks
Coverage Status
Total Downloads
Latest Version
PHP Version

## About

The package contains bridges for the following integrations of [symfomy/translation](https://symfony.com/doc/current/translation.html) into [Nette Framework](https://nette.org):

- [contributte/translations](https://github.com/contributte/translation)

Why? Because we want to keep our bundles independent of specific integrations so applications can use any of the integrations mentioned above and will be still compatible with our bundles.

## Installation

The best way to install 68publishers/translation-bridge is using Composer:

```sh
$ composer require 68publishers/translation-bridge
```

## Configuration

```neon
extensions:
# if you are using contributte/translation:
translation_bridge: SixtyEightPublishers\TranslationBridge\Bridge\Nette\DI\ContributteTranslationBridgeExtension
```

## Usage

### Translation Resources Provider

Extensions can provide paths with translation resources.

```php
use Nette\DI\CompilerExtension;
use SixtyEightPublishers\TranslationBridge\Bridge\Nette\DI\TranslationProviderInterface;

final class MyBundleExtension extends CompilerExtension implements TranslationProviderInterface
{
public function getTranslationResources(): array
{
return [
__DIR__ . '/translations',
];
}
}
```

### Translator Aware

All services that implement an interface `TranslatorAwareInterface` will automatically receive the Translator instance.

```php
translator->translate('....');
}
}
```

### Prefixed Translator Factory

The Container contains an autowired service of type `PrefixedTranslatorFactoryInterface` for creating prefixed translators.

```php
translator = $prefixedTranslatorFactory->create('MyService');
}
}
```

### Translator Localizer

The Container contains the service of type `TranslatorLocalizerInterface` for manipulating with the Translator locale.

```php
use SixtyEightPublishers\TranslationBridge\Localization\TranslatorLocalizerInterface;

final class MyService
{
public function __construct(
private readonly TranslatorLocalizerInterface $localizer
) {}

public function doSomething(): void
{
# Get the current locale
$locale = $this->localizer->getLocale();

# Set the new locale
$this->localizer->setLocale('cs_CZ');
}
}
```

### Translator Locale Resolver

The Translator's locale can be resolved with own resolvers like this:

```php