PixelPub / laravel-loco by pixelpub

Laravel package for the localise.biz api
1,595
0
4
Package Data
Maintainer Username: pixelpub
Maintainer Contact: stefan@pixel-pub.de (Stefan Probst)
Package Create Date: 2016-07-14
Package Last Update: 2016-07-18
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-05-16 15:01:13
Package Statistics
Total Downloads: 1,595
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 4
Total Forks: 0
Total Open Issues: 0

Laravel package for the localise.biz api

This package delivers an easy to use interface for fetching and caching assets from the Localise.biz api.

Table of Contents

  • Installation
    • Composer
    • Manually
    • Laravel
  • Configuration
    • Configuration file
    • Configuration values
  • Usage
    • Fetch translation
    • Flush Cache
  • Changelog
  • License

Installation

Composer

Add PixelPub/Loco to your composer.json file.

"pixelpub/loco":"dev-master"

Run composer install to get the latest version of the package.

Manually

It's recommended that you use Composer, however you can download and install from this repository.

Laravel

Laravel-Loco comes with a service provider for Laravel.

To register the service provider in your Laravel application, open config/app.php and add the following line to the providers array:

	...
	Pixelpub\Loco\LocoServiceProvider::class
	...

Configuration

Configuration file

In order to edit the default package configuration, you can run the following artisan command:

php artisan vendor:publish --provider="Pixelpub\Loco\LocoServiceProvider" --tag="config"

Once you have done that, you will find the config file at config/loco.php.

Configuration values

  • api (default: https://localise.biz/api/export/locale/)

Localise.biz api url.

  • languages (default: ['en_US', 'de_DE'])

An array of the locales available on the Localise.biz api.

  • projects

An array of key-value pairs, defining the Localise.biz projects including their api key.

  • cache (default: database)

Defining the laravel cache interface, which will contain the assets, fetched from Localise.biz.

Usage

Fetch translation

The LocoServiceProvider.php is injected via the Loco interface.

	...
	use Pixelpub\Loco\LocoContract;
	...
    public function translation(Loco $loco)
    {
        return $loco->fetch('my-translation-project', 'en_US');
    }
	...

Once you have done this, there is nothing more that you MUST do. Laravel application locale has been set and you can use other locale-dependant Laravel components (e.g. Translation) as you normally do.

Flush cache

All assets will be fetched one time from the loco api and stored permanently in the cache. If you call the flush method, this package will try to load the assets from loco before actually flushing the cache. If loco api is not available, the current assets will be remain in the cache and an exception is thrown.

    $loco->flush('my-translation-project');

License

This package is licensed under the MIT license.