2017 © Pedro Peláez
 

library foo-translate

Library for making international applications in Opulence easy.

image

peteraba/foo-translate

Library for making international applications in Opulence easy.

  • Thursday, April 20, 2017
  • by peteraba
  • Repository
  • 2 Watchers
  • 0 Stars
  • 23 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

FooTranslate

Library for making multilingual applications in Opulence easy., (*1)

Build Status License composer.lock Scrutinizer Code Quality Code Coverage Build Status, (*2)

Setup

Install the library via composer:, (*3)

composer install peteraba/foo-translate

Add the bootstrapper to you application:, (*4)

# config/bootstrappers.php

return [
    // ...
    Foo\Translate\Bootstrapper\TranslatorBootstrapper::class,
];

Add your translations in resources/lang as it already exist for validation., (*5)

Add your default language to your .env.app.php:, (*6)

Environment::setVar('DEAFULT_LANGUAGE', "hu");

Usage

Files under resources/lang/${DEFAULT_LANG} will be loaded automatically. Values defined in the language files are namespaced by a : character, so the value mainPageTitle defined in application.php can be referenced as application:mainPageTitle, (*7)

User classes can access the translator via loading from the IOC Container as ITranslator., (*8)

In Fortune you can call the helper tr to retrieve your translations., (*9)

Example

resources/lang/en/form.php, (*10)

<?php

return [
    'createNewLabel' => 'Create new %s',
];

src/Project/Form/Login.php, (*11)

class Login
{
    /**
     * @param ITranslator $translator
     * @param string      $entityName
     */
    public function __construct(ITranslator $translator, string $entityName)
    {
        $this->translator = $translator;
        $this->entityName = $entityName;
    }

    /**
     * @return Button
     */
    public function createSaveButton(): Button
    {
        return new Button($this->translator->translate('form:createNewLabel', $this->entityName));
    }
}

resources/views/forms/login.fortune.php, (*12)

<button>{{ tr("form:createNewLabel", $entityName) }}</button>

Notes

  1. The library will default to use English (en) as default language if one is not provided.
  2. The bootrapper is not Lazy loaded, because international application usually need translations throughout the application.
  3. At the moment translations are not cached, but that's a planned feature.

The Versions

20/04 2017

dev-master

9999999-dev

Library for making international applications in Opulence easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Aba

19/04 2017

dev-scrutinizer-patch-2

dev-scrutinizer-patch-2

Library for making international applications in Opulence easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Aba

16/04 2017

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1

Library for making international applications in Opulence easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Peter Aba