alpakaio/i18next-php

A port of the i18next JS library for PHP

Installs: 5 075

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 0

Forks: 3

Open Issues: 10

Type:project

v1.0.6 2021-11-18 17:42 UTC

This package is not auto-updated.

Last update: 2024-04-20 04:13:22 UTC


README

A port of i18next in PHP. With a rest API. (coming soon [tm])

Code in this repository is largely based on the original code base in JavaScript, rewritten in PHP. This project focuses only on the newest version of i18next, disregarding compatibility with previous ones.

Warning!

This version is usable, but could contain bugs. If you find any issues please report them or create a PR.

Features

  • PSR3 logging support (psr/log is a hard requirement, but you're not required to actually use a logger)
  • Extremely similar API to the JS version
  • PHP-specific features like interfaces for modules
  • PHP 7.3+
  • Automatic language detection support

Usage

View all examples here

Basic example

// You can also use I18n globally via I18n::get()

$i18n = new I18n([
    'lng'           =>  'en',
    'resources'     =>  [
        'en'        =>  [
            'translation'       =>  [
                'key'           =>  'Value',
                'key_plural'    =>  'Value plural',
                'deeper'        =>  [
                    'key'           =>  'Deep value'
                ]
            ]
        ]
    ]
]);

$i18n->t('key'); // "Value"
$i18n->t('key', ['count' => 5]); // "Value plural"
$i18n->t('deeper.key'); // "Depp value"

Composer

Simply enter your project directory and run

composer require alpakaio/i18next-php

Todo

  • Add event emitting

Packagist

Visit the page here