2017 © Pedro Peláez
 

library language

Language management

image

jdz/language

Language management

  • Wednesday, May 30, 2018
  • by jdz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Language

Language is a proxy I use to symfony/translation component is a modular PHP package designed for managing and translating multilingual content in your web projects. This project simplifies the use of language files and provides a clear API for easily handling translations., (*1)

Features

  • Built on the symfony/translation component for robust translation capabilities.
  • Uses the symfony/string inflector for pluralize and singularize.
  • Load default or application-specific language files.
  • Flexible management of translation keys.
  • Support for YAML format language files.
  • Easy integration with other frameworks or custom solutions.
  • Optimized for fast performance and maximum extensibility.
  • Inflector for French, English & soon Spanish -> introduced in symfony/string 7.2 (PHP >= 8.2).

Installation

Add the package to your project using Composer:, (*2)

composer require jdz/language

Usage

For a complete example, check the example folder in the repository., (*3)

Initialization

use JDZ\Language\Language;

$language = new Language(
    // app languages
    ['fr', 'en'],
    // default language
    'fr'
);

### load user language
if not an available languages it falls back to the default language

```php
$language->load('fr');

load translations from array

$language->loadArray([
    'welcome_message' => 'Hi !',
    'test' => [
        'key1' => 'Test 1 nested',
        'key2' => 'Test 1 nested 2',
    ],
    'test2' => 'Test 2',
]);

load translations from YAML file

$language->loadYmlFiles([
    __DIR__ . '/file1.yml',
    __DIR__ . '/file2.yml',
]);
$language->loadYmlFile(__DIR__ . '/file3.yml');
welcome_message: "Welcome"
goodbye_message: "Goodbye"

Setting Values

$language->set('custom.key', 'My custom value');

Getting Values

$welcomeMessage = $language->get('welcome_message');
// Hi !
$customMessage = $language->get('custom.key');
// My custom value
$notDefined = $language->get('test.me');
// null
$notDefinedButDefault = $language->get('test.me', 'Default value');
// Default value

Methods

Method Description
load() Load a user language.
loadYamlFiles() Load translations from an array of YAML files.
loadYamlFile() Load translations from a YAML file.
loadArray() Load translations from an array of key => value pairs.
set() Adds a translation.
get() Retrieves a translation at the specified path.
has() Checks if a translation exists at the specified path.
plural() Load a plural.
pluralize() Uses the symfony/string inflector.
pluralize() Uses the symfony/string inflector.

License

This project is licensed under the MIT License. See the LICENSE file for details., (*4)

Author

(c) Joffrey Demetz joffrey.demetz@gmail.com, (*5)

The Versions

30/05 2018

dev-master

9999999-dev https://github.com/joffreydemetz/language/

Language management

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

language i18n

30/05 2018

2.0.1

2.0.1.0 https://github.com/joffreydemetz/language/

Language management

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

language i18n

13/05 2018

2.0.0

2.0.0.0 https://github.com/joffreydemetz/language/

Language management

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

language i18n

02/03 2018

1.2.1

1.2.1.0 http://joffreydemetz.com/git/language/

Language management

  Sources   Download

MIT

The Requires

  • php >=5.6

 

language i18n

22/01 2018

1.2.0

1.2.0.0 http://joffreydemetz.com/git/language/

Language management

  Sources   Download

MIT

The Requires

  • php >=5.6

 

language i18n

03/12 2017

1.1.0

1.1.0.0 http://joffreydemetz.com/git/language/

Language management

  Sources   Download

MIT

The Requires

  • php >=5.6

 

language i18n