pwweb / localisation
Localisation package for Laravel
Requires
- php: >=7.3.7
- fzaninotto/faker: ^1.9
- laracasts/flash: ^3.0
- laravel/framework: ^7.3.0
- pwweb/laravel-core: ^0.1.0-beta
Requires (Dev)
- phpmd/phpmd: @stable
- phpunit/phpunit: ~8.0
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2020-11-06 18:47:31 UTC
README
Localisation: C3P0 for Laravel. Take a look at contributing.md to see a to do list.
Installation
Via Composer run the following:
# Install the package. $ composer require pwweb/localisation # Publish config, migration, languages and controllers. # Note: Individual publishing tags are available, see chapter Customizing. $ php artisan vendor:publish --provider="PWWEB\Localisation\LocalisationServiceProvider" # Run migrations $ php artisan migrate
Pre-requisites
The package assumes a standard Laravel installation if the bundled default contollers for the entities are to be used. The bundled controllers extend from App\Http\Controllers\Controller
. If other, custom base controllers are used as part of the installation, refer to Customizing.
Configuration
Customizing
The package provides the following tags for publishing individual components for customizing:
Tag | Description |
---|---|
pwweb.localisation.config |
Publish the configuration files to e.g. adjust database table names. |
pwweb.localisation.migrations |
Publish the migration file(s) to make alterations to the database tables. |
pwweb.localisation.language |
Publish the language files to make adjustments to the translation strings. |
pwweb.localisation.views |
Publish the view files to make adjustments to the overall structure of the views. |
Default and Fallback Language
It is recommended to change your app.php
to use both the ISO-639-1 ISO Language Code as well as the ISO-3166 ISO Country Code. This can be achieved by changing the following two variables:
<?php return [ ... 'locale' => 'en-GB', 'fallback_locale' => 'en-GB', ... ];
Usage
Addresses
The package provides a trait HasAddresses
which can be used to allow models to be associated with addresses.
<?php namespace Path\To; use Illuminate\Database\Eloquent\Model; use PWWEB\Localisation\Traits\HasAddresses; class MyModel extends Model { use HasAddresses; }
Language Switcher
The localisation package provides a language switcher that can easily be added to blade templates as follows (note: the <div>
is exemplary):
... <div class="anyContainer"> {{ Localisation::languageSelector() }} </div> ...
GraphQL
The package provides a graphql.schema
file for use within your parent project. This can be included in your primary schema
file as follows:
#import ../vendor/pwweb/localisation/graphql/schema.graphql
Note: don't forget to update the vendor path should yours be in a different location, relative to your primary schema file.
FAQs
During install via composer you get the following messages:
ErrorException : Trying to access array offset on value of type null at /var/www/vendor/pwweb/localisation/src/LocalisationServiceProvider.php:107 103| protected function registerModelBindings() 104| { 105| $config = $this->app->config['localisation.models']; 106| > 107| $this->app->bind(CountryContract::class, $config['country']); 108| $this->app->bind(LanguageContract::class, $config['language']); 109| $this->app->bind(CurrencyContract::class, $config['currency']); 110| } 111| Exception trace: 1 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Trying to access array offset on value of type null", "/var/www/vendor/pwweb/localisation/src/LocalisationServiceProvider.php", []) /var/www/vendor/pwweb/localisation/src/LocalisationServiceProvider.php:107 2 PWWeb\Localisation\LocalisationServiceProvider::registerModelBindings() /var/www/vendor/pwweb/localisation/src/LocalisationServiceProvider.php:81 Please use the argument -v to see more details.
This is due to the command php artisan config:cache
has been run. We suggest you delete the cache file bootstrap/cache/config.php
and then run composer dump-autoload
to be sure.
Change log
Please see the changelog for more information on what has changed recently.
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please use the issue tracker.
Credits
License
Copyright © pw-websolutions.com. Please see the license file for more information.