Represent translated literals in JSON.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.editorconfig
.gitattributes
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
build.xml
composer.json
phpunit.xml

README.md

TranslatedLiteral

Latest Version Build Status Software License

TranslatedLiteral is used to represent translated strings in JSON.

The library is framework-agnostic and does not have any dependencies.

System Requirements

PHP 7.0 or later.

Install

Install using Composer:

$ composer require maximegosselin/translated-literal

TranslatedLiteral is registered under the MaximeGosselin\TranslatedLiteral namespace.

Usage

Instantiate a Literal object by defining the default locale and translation.

A Literal instance is immutable. A copy can be created using withLocale and withTranslation functions.

$literal = new Literal('fr-ca', 'Bonjour le monde');
 
$literal = $literal->withTranslation('en-us', 'Hello world')->withLocale('en-us');
 
echo $literal;

This would output:

{
    "locale": "en_US",
    "content": {
        "fr_CA": "Bonjour le monde",
        "en_US": "Hello world"
    }
}

Tests

Run the following command from the project folder.

$ vendor/bin/phpunit

License

The MIT License (MIT). Please see LICENSE for more information.