PHPackages                             abedmaatalla/slim-twig-translation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. abedmaatalla/slim-twig-translation

ActiveLibrary[Templating &amp; Views](/categories/templating)

abedmaatalla/slim-twig-translation
==================================

Twig function for Illuminate\\Translation\\Translator in Slim framework

1.0.0(9y ago)29422[2 PRs](https://github.com/abedmaatalla/slim-twig-translation/pulls)MITPHPPHP &gt;=5.3.0

Since Nov 25Pushed 7y agoCompare

[ Source](https://github.com/abedmaatalla/slim-twig-translation)[ Packagist](https://packagist.org/packages/abedmaatalla/slim-twig-translation)[ Docs](http://github.com/abedmaatalla/slim-twig-translation)[ RSS](/packages/abedmaatalla-slim-twig-translation/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Slim Twig Translation
=====================

[](#slim-twig-translation)

This repository provides a twig extension class for the twig view parser. The class adds a translate helper function for the use in twig templates. The translator function tries to call the trans() function of an Illuminate\\Translation\\Translator object in the slim DI container.

How to install
--------------

[](#how-to-install)

#### using [Composer](http://getcomposer.org/)

[](#using-composer)

Create a composer.json file in your project root:

```
{
    "require": {
        "abedmaatalla/slim-twig-translation": "1.0.0"
    }
}
```

Then run the following composer command:

```
$ php composer.phar install
```

How to use
----------

[](#how-to-use)

Create new folder for langauges

-

\-- lang

- -- en
    - -- file.php
- -- fr
    - -- file.php

### Tanslator

[](#tanslator)

Set up your Tansloator

```
$container['translator'] = function ($c)
{
  // Register the English translator 'en'
  $translator = new Illuminate\Translation\Translator(new Illuminate\Translation\FileLoader(new Illuminate\Filesystem\Filesystem(), __DIR__ . '/lang'), 'en');
    // setLocal for new location
    $translator->setLocale('fr');
    return $translator;
};
```

### Slim

[](#slim)

Set up your twig views as described in the [SlimViews Repository](https://github.com/codeguy/Slim-Views). Add the extension to your parser extensions.

```
$container['view'] = function ($c)
{
  $view = new \Slim\Views\Twig('../resources/views');

  // add translator functions to Twig
  $view->addExtension(new \abedmaatalla\Slim\Twig\Extension\TranslationExtension($c->translator));

}
```

### Twig template

[](#twig-template)

In your twig template you would write:

```
  {{ translate('male') }}

```

You can also use the shorthand:

```
  {{ tans('male') }}

```

You can also use the shorthand:

```
  {{ _('male') }}

```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3455d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d1bd2b6a6ddce6947359a04901c138b219ea115d7eb7c82966a98f440f32fd7f?d=identicon)[abedmaatalla](/maintainers/abedmaatalla)

---

Top Contributors

[![abedmaatalla](https://avatars.githubusercontent.com/u/5932922?v=4)](https://github.com/abedmaatalla "abedmaatalla (6 commits)")

---

Tags

twigtranslationslimilluminatemicroframework

### Embed Badge

![Health badge](/badges/abedmaatalla-slim-twig-translation/health.svg)

```
[![Health](https://phpackages.com/badges/abedmaatalla-slim-twig-translation/health.svg)](https://phpackages.com/packages/abedmaatalla-slim-twig-translation)
```

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91292.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36663.2M221](/packages/twig-intl-extra)[twig/string-extra

A Twig extension for Symfony String

21946.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

23018.5M55](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21814.8M162](/packages/symfony-ux-twig-component)[twig/markdown-extra

A Twig extension for Markdown

12114.3M83](/packages/twig-markdown-extra)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
