mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 11:30:55 +01:00
Correzioni minori e aggiornamento a Laravel 9
This commit is contained in:
parent
990ed0475f
commit
279fe2eca9
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Util\FileSystem;
|
||||
|
||||
class RequirementsController extends Controller
|
||||
@ -42,7 +43,7 @@ class RequirementsController extends Controller
|
||||
$list = config('requirements');
|
||||
if (!empty($file)) {
|
||||
$file = realpath($file);
|
||||
if (string_starts_with($file)) {
|
||||
if (Str::startsWith($file)) {
|
||||
$list = include $file;
|
||||
}
|
||||
}
|
||||
@ -89,9 +90,9 @@ class RequirementsController extends Controller
|
||||
$ini = FileSystem::convertBytes($value);
|
||||
$real = FileSystem::convertBytes($suggested);
|
||||
|
||||
if (starts_with($values['suggested'], '>')) {
|
||||
if (Str::startsWith($values['suggested'], '>')) {
|
||||
$status = $ini >= substr($real, 1);
|
||||
} elseif (starts_with($values['suggested'], '<')) {
|
||||
} elseif (Str::startsWith($values['suggested'], '<')) {
|
||||
$status = $ini <= substr($real, 1);
|
||||
} else {
|
||||
$status = ($real == $ini);
|
||||
|
@ -21,7 +21,7 @@ class Kernel extends HttpKernel
|
||||
protected $middleware = [
|
||||
\App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Fruitcake\Cors\HandleCors::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
|
@ -9,6 +9,7 @@ use App\Http\Controllers\UpdateController;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EnsureConfiguration
|
||||
{
|
||||
@ -33,7 +34,7 @@ class EnsureConfiguration
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$route = $request->route();
|
||||
if (starts_with($route->parameter('path'), 'assets')) {
|
||||
if (Str::startsWith($route->parameter('path'), 'assets')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Xinax\LaravelGettext\Facades\LaravelGettext;
|
||||
use App\LaravelGettext\Facades\LaravelGettext;
|
||||
|
||||
class Language
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
@ -19,5 +19,9 @@ class TrustProxies extends Middleware
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
||||
protected $headers = Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
|
@ -12,6 +12,5 @@ class VerifyCsrfToken extends Middleware
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'legacy',
|
||||
];
|
||||
}
|
||||
|
28
app/LaravelGettext/Adapters/AdapterInterface.php
Normal file
28
app/LaravelGettext/Adapters/AdapterInterface.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Adapters;
|
||||
|
||||
interface AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Get the current locale
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale();
|
||||
|
||||
/**
|
||||
* Sets the locale on the adapter
|
||||
*
|
||||
* @param string $locale
|
||||
* @return boolean
|
||||
*/
|
||||
public function setLocale($locale);
|
||||
|
||||
/**
|
||||
* Get the application path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApplicationPath();
|
||||
}
|
40
app/LaravelGettext/Adapters/LaravelAdapter.php
Normal file
40
app/LaravelGettext/Adapters/LaravelAdapter.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Adapters;
|
||||
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class LaravelAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Set current locale
|
||||
*
|
||||
* @param string $locale
|
||||
* @return bool
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
App::setLocale(substr($locale, 0, 2));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locale
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return App::getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the application path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApplicationPath()
|
||||
{
|
||||
return app_path();
|
||||
}
|
||||
}
|
42
app/LaravelGettext/Commands/BaseCommand.php
Normal file
42
app/LaravelGettext/Commands/BaseCommand.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\LaravelGettext\FileSystem;
|
||||
use App\LaravelGettext\Config\ConfigManager;
|
||||
|
||||
class BaseCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Filesystem helper
|
||||
*
|
||||
* @var \App\LaravelGettext\FileSystem
|
||||
*/
|
||||
protected $fileSystem;
|
||||
|
||||
/**
|
||||
* Package configuration data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* Prepares the package environment for gettext commands
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepare()
|
||||
{
|
||||
$configManager = ConfigManager::create();
|
||||
|
||||
$this->fileSystem = new FileSystem(
|
||||
$configManager->get(),
|
||||
app_path(),
|
||||
storage_path()
|
||||
);
|
||||
|
||||
$this->configuration = $configManager->get();
|
||||
}
|
||||
}
|
76
app/LaravelGettext/Commands/GettextCreate.php
Normal file
76
app/LaravelGettext/Commands/GettextCreate.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Commands;
|
||||
|
||||
class GettextCreate extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'gettext:create';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description =
|
||||
'Generates the initial directories and files for laravel-gettext.';
|
||||
|
||||
/**
|
||||
* Execute the console command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->prepare();
|
||||
|
||||
// Directories created counter
|
||||
$dirCreations = 0;
|
||||
|
||||
try {
|
||||
// Locales
|
||||
$localesGenerated = $this->fileSystem->generateLocales();
|
||||
|
||||
foreach ($localesGenerated as $localePath) {
|
||||
$this->comment(sprintf("Locale directory created (%s)", $localePath));
|
||||
$dirCreations++;
|
||||
}
|
||||
|
||||
$this->info("Finished");
|
||||
|
||||
$msg = "The directory structure is right. No directory creation were needed.";
|
||||
|
||||
if ($dirCreations) {
|
||||
$msg = $dirCreations . " directories has been created.";
|
||||
}
|
||||
|
||||
$this->info($msg);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getFile() . ":" . $e->getLine() . " - " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
136
app/LaravelGettext/Commands/GettextUpdate.php
Normal file
136
app/LaravelGettext/Commands/GettextUpdate.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Commands;
|
||||
|
||||
use Exception;
|
||||
use App\LaravelGettext\Exceptions\DirectoryNotFoundException;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class GettextUpdate extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'gettext:update';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Update PO files (when you modify configuration).';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->prepare();
|
||||
|
||||
$domainPath = $this->fileSystem->getDomainPath();
|
||||
$fileSystem = $this->fileSystem;
|
||||
|
||||
try {
|
||||
// Translation files base path
|
||||
if (!file_exists($domainPath)) {
|
||||
throw new DirectoryNotFoundException(
|
||||
"You need to call gettext:create (No locale directory)"
|
||||
);
|
||||
}
|
||||
|
||||
$count = [
|
||||
'added' => 0,
|
||||
'updated' => 0,
|
||||
];
|
||||
|
||||
$domains = $this->configuration->getAllDomains();
|
||||
|
||||
foreach ($this->configuration->getSupportedLocales() as $locale) {
|
||||
$localePath = $this->fileSystem->getDomainPath($locale);
|
||||
|
||||
// Create new locale
|
||||
if (!file_exists($localePath)) {
|
||||
$this->fileSystem->addLocale($localePath, $locale);
|
||||
$this->comment("New locale was added: $locale ($localePath)");
|
||||
|
||||
$count['added']++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Domain by command line argument
|
||||
if ($this->option('domain')) {
|
||||
$domains = [$this->option('domain')];
|
||||
}
|
||||
|
||||
// Update by domain(s)
|
||||
foreach ($domains as $domain) {
|
||||
$fileSystem->updateLocale(
|
||||
$localePath,
|
||||
$locale,
|
||||
$domain
|
||||
);
|
||||
|
||||
$this->comment(
|
||||
sprintf(
|
||||
"PO file for locale: %s/%s updated successfully",
|
||||
$locale,
|
||||
$domain
|
||||
)
|
||||
);
|
||||
|
||||
$count['updated']++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("Finished");
|
||||
|
||||
// Number of locales created
|
||||
if ($count['added'] > 0) {
|
||||
$this->info(sprintf('%s new locales were added.', $count['added']));
|
||||
}
|
||||
|
||||
|
||||
// Number of locales updated
|
||||
if ($count['updated'] > 0) {
|
||||
$this->info(sprintf('%s locales updated.', $count['updated']));
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getFile() . ":" . $e->getLine() . " = " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'domain',
|
||||
'-d',
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'Update files only for this domain',
|
||||
null,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
86
app/LaravelGettext/Composers/LanguageSelector.php
Normal file
86
app/LaravelGettext/Composers/LanguageSelector.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php namespace App\LaravelGettext\Composers;
|
||||
|
||||
use App\LaravelGettext\LaravelGettext;
|
||||
|
||||
/**
|
||||
* Simple language selector generator.
|
||||
* @author Nicolás Daniel Palumbo
|
||||
*/
|
||||
class LanguageSelector
|
||||
{
|
||||
/**
|
||||
* Labels
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $labels = [];
|
||||
|
||||
/**
|
||||
* @var LaravelGettext
|
||||
*/
|
||||
protected $gettext;
|
||||
|
||||
/**
|
||||
* @param LaravelGettext $gettext
|
||||
* @param array $labels
|
||||
*/
|
||||
public function __construct(LaravelGettext $gettext, array $labels = [])
|
||||
{
|
||||
$this->labels = $labels;
|
||||
$this->gettext = $gettext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LaravelGettext $gettext
|
||||
* @param array $labels
|
||||
* @return LanguageSelector
|
||||
*/
|
||||
public static function create(LaravelGettext $gettext, $labels = [])
|
||||
{
|
||||
return new LanguageSelector($gettext, $labels);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the language selector
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
/** @var string $currentLocale */
|
||||
$currentLocale = $this->gettext->getLocale();
|
||||
|
||||
$html = '<ul class="language-selector">';
|
||||
|
||||
foreach ($this->gettext->getSupportedLocales() as $locale) {
|
||||
$localeLabel = $locale;
|
||||
|
||||
// Check if label exists
|
||||
if (array_key_exists($locale, $this->labels)) {
|
||||
$localeLabel = $this->labels[$locale];
|
||||
}
|
||||
|
||||
|
||||
$link = '<a href="/lang/' . $locale . '" class="' . $locale . '">' . $localeLabel . '</a>';
|
||||
|
||||
if ($locale == $currentLocale) {
|
||||
$link = '<strong class="active ' . $locale . '">' . $localeLabel . '</strong>';
|
||||
}
|
||||
|
||||
$html .= '<li>' . $link . '</li>';
|
||||
}
|
||||
|
||||
$html .= '</ul>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->render();
|
||||
}
|
||||
}
|
131
app/LaravelGettext/Config/ConfigManager.php
Normal file
131
app/LaravelGettext/Config/ConfigManager.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Config;
|
||||
|
||||
use \App\LaravelGettext\Config\Models\Config as ConfigModel;
|
||||
use \App\LaravelGettext\Exceptions\RequiredConfigurationFileException;
|
||||
use \App\LaravelGettext\Exceptions\RequiredConfigurationKeyException;
|
||||
use \Illuminate\Support\Facades\Config;
|
||||
use App\LaravelGettext\Storages\SessionStorage;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ConfigManager
|
||||
{
|
||||
/**
|
||||
* Config model
|
||||
*
|
||||
* @var ConfigModel
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Package configuration route (published)
|
||||
*/
|
||||
const DEFAULT_PACKAGE_CONFIG = 'laravel-gettext';
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @throws RequiredConfigurationKeyException
|
||||
*/
|
||||
public function __construct($config = null)
|
||||
{
|
||||
if ($config) {
|
||||
$this->config = $this->generateFromArray($config);
|
||||
} else {
|
||||
// In Laravel 5.3 we need empty config model
|
||||
$this->config = new ConfigModel;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get new instance of the ConfigManager
|
||||
*
|
||||
* @param null $config
|
||||
* @return static
|
||||
* @throws RequiredConfigurationFileException
|
||||
*/
|
||||
public static function create($config = null)
|
||||
{
|
||||
if (is_null($config)) {
|
||||
// Default package configuration file (published)
|
||||
$config = Config::get(static::DEFAULT_PACKAGE_CONFIG);
|
||||
}
|
||||
|
||||
return new static($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config model
|
||||
*
|
||||
* @return ConfigModel
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a configuration container and checks the required fields
|
||||
*
|
||||
* @param array $config
|
||||
* @return ConfigModel
|
||||
* @throws RequiredConfigurationKeyException
|
||||
*/
|
||||
protected function generateFromArray(array $config)
|
||||
{
|
||||
$requiredKeys = [
|
||||
'locale',
|
||||
'fallback-locale',
|
||||
'encoding'
|
||||
];
|
||||
|
||||
foreach ($requiredKeys as $key) {
|
||||
if (!array_key_exists($key, $config)) {
|
||||
throw new RequiredConfigurationKeyException(
|
||||
sprintf('Unconfigured required value: %s', $key)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$container = new ConfigModel();
|
||||
|
||||
$id = isset($config['session-identifier']) ? $config['session-identifier'] : 'laravel-gettext-locale';
|
||||
|
||||
$adapter = isset($config['adapter']) ? $config['adapter'] : \App\LaravelGettext\Adapters\LaravelAdapter::class;
|
||||
|
||||
$storage = isset($config['storage']) ? $config['storage'] : SessionStorage::class;
|
||||
|
||||
$container->setLocale($config['locale'])
|
||||
->setSessionIdentifier($id)
|
||||
->setEncoding($config['encoding'])
|
||||
->setCategories(Arr::get('categories', $config, ['LC_ALL']))
|
||||
->setFallbackLocale($config['fallback-locale'])
|
||||
->setSupportedLocales($config['supported-locales'])
|
||||
->setDomain($config['domain'])
|
||||
->setTranslationsPath($config['translations-path'])
|
||||
->setProject($config['project'])
|
||||
->setTranslator($config['translator'])
|
||||
->setSourcePaths($config['source-paths'])
|
||||
->setSyncLaravel($config['sync-laravel'])
|
||||
->setAdapter($adapter)
|
||||
->setStorage($storage);
|
||||
|
||||
if (array_key_exists('relative-path', $config)) {
|
||||
$container->setRelativePath($config['relative-path']);
|
||||
}
|
||||
|
||||
if (array_key_exists("custom-locale", $config)) {
|
||||
$container->setCustomLocale($config['custom-locale']);
|
||||
}
|
||||
|
||||
if (array_key_exists("keywords-list", $config)) {
|
||||
$container->setKeywordsList($config['keywords-list']);
|
||||
}
|
||||
|
||||
if (array_key_exists("handler", $config)) {
|
||||
$container->setHandler($config['handler']);
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
589
app/LaravelGettext/Config/Models/Config.php
Normal file
589
app/LaravelGettext/Config/Models/Config.php
Normal file
@ -0,0 +1,589 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Config\Models;
|
||||
|
||||
class Config
|
||||
{
|
||||
/**
|
||||
* Session identifier
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $sessionIdentifier;
|
||||
|
||||
/**
|
||||
* Charset encoding for files
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $encoding;
|
||||
|
||||
/**
|
||||
* Full ISO Locale (en_EN)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* Locale categories
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
protected $categories;
|
||||
|
||||
/**
|
||||
* Fallback locale
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fallbackLocale;
|
||||
|
||||
/**
|
||||
* Supported locales
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $supportedLocales;
|
||||
|
||||
/**
|
||||
* Gettext domain
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $domain;
|
||||
|
||||
/**
|
||||
* Path to translation files
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $translationsPath;
|
||||
|
||||
/**
|
||||
* Project identifier
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $project;
|
||||
|
||||
/**
|
||||
* Translator contact data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* Source paths
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sourcePaths;
|
||||
|
||||
/**
|
||||
* Sync with laravel locale
|
||||
*
|
||||
* @type Boolean
|
||||
*/
|
||||
protected $syncLaravel;
|
||||
|
||||
/**
|
||||
* The adapter class used to sync with laravel locale
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $adapter;
|
||||
|
||||
|
||||
/**
|
||||
* The storage class used store the current locale information
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* Custom locale name
|
||||
* Used when needed locales are unavalilable
|
||||
*
|
||||
* @type Boolean
|
||||
*/
|
||||
protected $customLocale;
|
||||
|
||||
/**
|
||||
* Default relative path
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
protected $relativePath;
|
||||
|
||||
/**
|
||||
* Poedit keywords list
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
protected $keywordsList;
|
||||
|
||||
/**
|
||||
* Core translation handler
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->encoding = 'UTF-8';
|
||||
$this->supportedLocales = [];
|
||||
$this->sourcePaths = [];
|
||||
$this->customLocale = false;
|
||||
$this->relativePath = "../../../../../app";
|
||||
}
|
||||
|
||||
public function getRelativePath()
|
||||
{
|
||||
return $this->relativePath;
|
||||
}
|
||||
|
||||
public function setRelativePath($path)
|
||||
{
|
||||
$this->relativePath = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSessionIdentifier()
|
||||
{
|
||||
return $this->sessionIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sessionIdentifier
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSessionIdentifier($sessionIdentifier)
|
||||
{
|
||||
$this->sessionIdentifier = $sessionIdentifier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
return $this->encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $encoding
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEncoding($encoding)
|
||||
{
|
||||
$this->encoding = $encoding;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets categories
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategories()
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets categories
|
||||
*
|
||||
* @param array $categories
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setCategories($categories)
|
||||
{
|
||||
$this->categories = $categories;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFallbackLocale()
|
||||
{
|
||||
return $this->fallbackLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fallbackLocale
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFallbackLocale($fallbackLocale)
|
||||
{
|
||||
$this->fallbackLocale = $fallbackLocale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSupportedLocales()
|
||||
{
|
||||
return $this->supportedLocales;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $supportedLocales
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSupportedLocales($supportedLocales)
|
||||
{
|
||||
$this->supportedLocales = $supportedLocales;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
return $this->domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $domain
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
$this->domain = $domain;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTranslationsPath()
|
||||
{
|
||||
return $this->translationsPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $translationsPath
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTranslationsPath($translationsPath)
|
||||
{
|
||||
$this->translationsPath = $translationsPath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
return $this->project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $project
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setProject($project)
|
||||
{
|
||||
$this->project = $project;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
return $this->translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $translator
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTranslator($translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSourcePaths()
|
||||
{
|
||||
return $this->sourcePaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sourcePaths
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSourcePaths($sourcePaths)
|
||||
{
|
||||
$this->sourcePaths = $sourcePaths;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSyncLaravel()
|
||||
{
|
||||
return $this->syncLaravel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Sync with laravel locale.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSyncLaravel()
|
||||
{
|
||||
return $this->syncLaravel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $syncLaravel
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSyncLaravel($syncLaravel)
|
||||
{
|
||||
$this->syncLaravel = $syncLaravel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the adapter class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAdapter()
|
||||
{
|
||||
return $this->adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $adapter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAdapter($adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for storage
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStorage()
|
||||
{
|
||||
return $this->storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $storage
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setStorage($storage)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return an array with all domain names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllDomains()
|
||||
{
|
||||
$domains = [$this->domain]; // add the default domain
|
||||
|
||||
foreach ($this->sourcePaths as $domain => $paths) {
|
||||
if (is_array($paths)) {
|
||||
array_push($domains, $domain);
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique($domains);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all routes for a single domain
|
||||
*
|
||||
* @param $domain
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSourcesFromDomain($domain)
|
||||
{
|
||||
// grab any paths wrapped in $domain
|
||||
$explicitPaths = array_key_exists($domain, $this->sourcePaths)
|
||||
? $this->sourcePaths[$domain]
|
||||
: [];
|
||||
|
||||
// if we're not including the default domain, return what we have so far
|
||||
if ($this->domain != $domain) {
|
||||
return $explicitPaths;
|
||||
}
|
||||
|
||||
// otherwise, grab all the default domain paths
|
||||
// and merge them with paths wrapped in $domain
|
||||
return array_reduce(
|
||||
$this->sourcePaths,
|
||||
function ($carry, $path) {
|
||||
if (!is_array($path)) {
|
||||
$carry[] = $path;
|
||||
}
|
||||
|
||||
return $carry;
|
||||
},
|
||||
$explicitPaths
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets C locale setting.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCustomLocale()
|
||||
{
|
||||
return $this->customLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if will use C locale structure.
|
||||
*
|
||||
* @param mixed $sourcePaths the source paths
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setCustomLocale($customLocale)
|
||||
{
|
||||
$this->customLocale = $customLocale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Poedit keywords list.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getKeywordsList()
|
||||
{
|
||||
return !empty($this->keywordsList)
|
||||
? $this->keywordsList
|
||||
: ['_'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Poedit keywords list.
|
||||
*
|
||||
* @param mixed $keywordsList the keywords list
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setKeywordsList($keywordsList)
|
||||
{
|
||||
$this->keywordsList = $keywordsList;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the handler type. Also check for valid handler name
|
||||
*
|
||||
* @param $handler
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setHandler($handler)
|
||||
{
|
||||
if (!in_array($handler, [
|
||||
'symfony',
|
||||
'gettext',
|
||||
])
|
||||
) {
|
||||
throw new \Exception("Handler '$handler' is not supported'");
|
||||
};
|
||||
|
||||
$this->handler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the handler name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getHandler()
|
||||
{
|
||||
return !empty($this->handler)
|
||||
? $this->handler
|
||||
: 'symfony';
|
||||
}
|
||||
}
|
10
app/LaravelGettext/Exceptions/DirectoryNotFoundException.php
Normal file
10
app/LaravelGettext/Exceptions/DirectoryNotFoundException.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class DirectoryNotFoundException extends Exception
|
||||
{
|
||||
|
||||
}
|
10
app/LaravelGettext/Exceptions/FileCreationException.php
Normal file
10
app/LaravelGettext/Exceptions/FileCreationException.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FileCreationException extends Exception
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class LocaleFileNotFoundException extends Exception
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class LocaleNotSupportedException extends Exception
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class MissingPhpGettextModuleException extends Exception
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class RequiredConfigurationFileException extends Exception
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class RequiredConfigurationKeyException extends Exception
|
||||
{
|
||||
|
||||
}
|
10
app/LaravelGettext/Exceptions/UndefinedDomainException.php
Normal file
10
app/LaravelGettext/Exceptions/UndefinedDomainException.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class UndefinedDomainException extends Exception
|
||||
{
|
||||
|
||||
}
|
18
app/LaravelGettext/Facades/LaravelGettext.php
Normal file
18
app/LaravelGettext/Facades/LaravelGettext.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class LaravelGettext extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return \App\LaravelGettext\LaravelGettext::class;
|
||||
}
|
||||
}
|
106
app/LaravelGettext/FileLoader/Cache/ApcuFileCacheLoader.php
Normal file
106
app/LaravelGettext/FileLoader/Cache/ApcuFileCacheLoader.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: aaflalo
|
||||
* Date: 18-03-01
|
||||
* Time: 10:23
|
||||
*/
|
||||
|
||||
namespace App\LaravelGettext\FileLoader\Cache;
|
||||
|
||||
use Symfony\Component\Translation\Exception\InvalidResourceException;
|
||||
use Symfony\Component\Translation\Loader\FileLoader;
|
||||
|
||||
class ApcuFileCacheLoader extends FileLoader
|
||||
{
|
||||
|
||||
/**
|
||||
* @var FileLoader
|
||||
*/
|
||||
private $underlyingFileLoader;
|
||||
|
||||
/**
|
||||
* ApcuFileCacheLoader constructor.
|
||||
*
|
||||
* @param FileLoader $underlyingFileLoader
|
||||
*/
|
||||
public function __construct(FileLoader $underlyingFileLoader)
|
||||
{
|
||||
$this->underlyingFileLoader = $underlyingFileLoader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $resource
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws InvalidResourceException if stream content has an invalid format
|
||||
*/
|
||||
protected function loadResource(string $resource): array
|
||||
{
|
||||
if (!extension_loaded('apcu')) {
|
||||
return $this->underlyingFileLoader->loadResource($resource);
|
||||
}
|
||||
|
||||
return $this->cachedMessages($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the checksum for the file
|
||||
*
|
||||
* @param $resource
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function checksum($resource)
|
||||
{
|
||||
return filemtime($resource) . '-' . filesize($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checksum saved in cache
|
||||
*
|
||||
* @param $resource
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function cacheChecksum($resource)
|
||||
{
|
||||
return apcu_fetch($resource . '-checksum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache checksum
|
||||
*
|
||||
* @param $resource
|
||||
* @param $checksum
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
private function setCacheChecksum($resource, $checksum)
|
||||
{
|
||||
return apcu_store($resource . '-checksum', $checksum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cached messages
|
||||
*
|
||||
* @param $ressource
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function cachedMessages($ressource)
|
||||
{
|
||||
if ($this->cacheChecksum($ressource) == ($currentChecksum = $this->checksum($ressource))) {
|
||||
return apcu_fetch($ressource . '-messages');
|
||||
}
|
||||
|
||||
$messages = $this->underlyingFileLoader->loadResource($ressource);
|
||||
|
||||
apcu_store($ressource . '-messages', $messages);
|
||||
$this->setCacheChecksum($ressource, $currentChecksum);
|
||||
|
||||
return $messages;
|
||||
}
|
||||
}
|
143
app/LaravelGettext/FileLoader/MoFileLoader.php
Normal file
143
app/LaravelGettext/FileLoader/MoFileLoader.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\FileLoader;
|
||||
|
||||
|
||||
use Symfony\Component\Translation\Exception\InvalidResourceException;
|
||||
use Symfony\Component\Translation\Loader\FileLoader;
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2010, Union of RAD http://union-of-rad.org (http://lithify.me/)
|
||||
*/
|
||||
class MoFileLoader extends FileLoader
|
||||
{
|
||||
/**
|
||||
* Magic used for validating the format of a MO file as well as
|
||||
* detecting if the machine used to create that file was little endian.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
const MO_LITTLE_ENDIAN_MAGIC = 0x950412de;
|
||||
|
||||
/**
|
||||
* Magic used for validating the format of a MO file as well as
|
||||
* detecting if the machine used to create that file was big endian.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
const MO_BIG_ENDIAN_MAGIC = 0xde120495;
|
||||
|
||||
/**
|
||||
* The size of the header of a MO file in bytes.
|
||||
*
|
||||
* @var int Number of bytes
|
||||
*/
|
||||
const MO_HEADER_SIZE = 28;
|
||||
|
||||
/**
|
||||
* Parses machine object (MO) format, independent of the machine's endian it
|
||||
* was created on. Both 32bit and 64bit systems are supported.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function loadResource(string $resource): array
|
||||
{
|
||||
$stream = fopen($resource, 'r');
|
||||
|
||||
$stat = fstat($stream);
|
||||
|
||||
if ($stat['size'] < self::MO_HEADER_SIZE) {
|
||||
throw new InvalidResourceException('MO stream content has an invalid format.');
|
||||
}
|
||||
$magic = unpack('V1', fread($stream, 4));
|
||||
$magic = hexdec(substr(dechex(current($magic)), -8));
|
||||
|
||||
if ($magic == self::MO_LITTLE_ENDIAN_MAGIC) {
|
||||
$isBigEndian = false;
|
||||
} elseif ($magic == self::MO_BIG_ENDIAN_MAGIC) {
|
||||
$isBigEndian = true;
|
||||
} else {
|
||||
throw new InvalidResourceException('MO stream content has an invalid format.');
|
||||
}
|
||||
|
||||
// formatRevision
|
||||
$this->readLong($stream, $isBigEndian);
|
||||
$count = $this->readLong($stream, $isBigEndian);
|
||||
$offsetId = $this->readLong($stream, $isBigEndian);
|
||||
$offsetTranslated = $this->readLong($stream, $isBigEndian);
|
||||
// sizeHashes
|
||||
$this->readLong($stream, $isBigEndian);
|
||||
// offsetHashes
|
||||
$this->readLong($stream, $isBigEndian);
|
||||
|
||||
$messages = array();
|
||||
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$pluralId = null;
|
||||
$translated = null;
|
||||
|
||||
fseek($stream, $offsetId + $i * 8);
|
||||
|
||||
$length = $this->readLong($stream, $isBigEndian);
|
||||
$offset = $this->readLong($stream, $isBigEndian);
|
||||
|
||||
if ($length < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fseek($stream, $offset);
|
||||
$singularId = fread($stream, $length);
|
||||
|
||||
if (strpos($singularId, "\000") !== false) {
|
||||
list($singularId, $pluralId) = explode("\000", $singularId);
|
||||
}
|
||||
|
||||
fseek($stream, $offsetTranslated + $i * 8);
|
||||
$length = $this->readLong($stream, $isBigEndian);
|
||||
$offset = $this->readLong($stream, $isBigEndian);
|
||||
|
||||
if ($length < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fseek($stream, $offset);
|
||||
$translated = fread($stream, $length);
|
||||
|
||||
if (strpos($translated, "\000") !== false) {
|
||||
$translated = explode("\000", $translated);
|
||||
}
|
||||
|
||||
$ids = array('singular' => $singularId, 'plural' => $pluralId);
|
||||
$item = compact('ids', 'translated');
|
||||
|
||||
if (is_array($item['translated'])) {
|
||||
$messages[$item['ids']['singular']] = stripcslashes($item['translated'][0]);
|
||||
if (isset($item['ids']['plural'])) {
|
||||
$messages[$item['ids']['plural']] = stripcslashes(implode('|', $item['translated']));
|
||||
}
|
||||
} elseif (!empty($item['ids']['singular'])) {
|
||||
$messages[$item['ids']['singular']] = stripcslashes($item['translated']);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($stream);
|
||||
|
||||
return array_filter($messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned long from stream respecting endianess.
|
||||
*
|
||||
* @param resource $stream
|
||||
* @param bool $isBigEndian
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function readLong($stream, $isBigEndian)
|
||||
{
|
||||
$result = unpack($isBigEndian ? 'N1' : 'V1', fread($stream, 4));
|
||||
$result = current($result);
|
||||
|
||||
return (int) substr($result, -8);
|
||||
}
|
||||
}
|
621
app/LaravelGettext/FileSystem.php
Normal file
621
app/LaravelGettext/FileSystem.php
Normal file
@ -0,0 +1,621 @@
|
||||
<?php namespace App\LaravelGettext;
|
||||
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use App\LaravelGettext\Config\Models\Config;
|
||||
use App\LaravelGettext\Exceptions\DirectoryNotFoundException;
|
||||
use App\LaravelGettext\Exceptions\FileCreationException;
|
||||
use App\LaravelGettext\Exceptions\LocaleFileNotFoundException;
|
||||
|
||||
class FileSystem
|
||||
{
|
||||
/**
|
||||
* Package configuration model
|
||||
*
|
||||
* @var Config
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* File system base path
|
||||
* All paths will be relative to this
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $basePath;
|
||||
|
||||
/**
|
||||
* Storage path for file generation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $storagePath;
|
||||
|
||||
/**
|
||||
* Storage directory name for view compilation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $storageContainer;
|
||||
|
||||
/**
|
||||
* The folder name in which the language files are stored
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $folderName;
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
* @param $basePath
|
||||
* @param $storagePath
|
||||
*/
|
||||
public function __construct(Config $config, $basePath, $storagePath)
|
||||
{
|
||||
$this->configuration = $config;
|
||||
$this->basePath = $basePath;
|
||||
|
||||
$this->storagePath = $storagePath;
|
||||
$this->storageContainer = "framework";
|
||||
$this->folderName = 'i18n';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build views in order to parse php files
|
||||
*
|
||||
* @param Array $viewPaths
|
||||
* @param String $domain
|
||||
*
|
||||
* @return Boolean status
|
||||
*/
|
||||
/**
|
||||
* Build views in order to parse php files
|
||||
*
|
||||
* @param array $viewPaths
|
||||
* @param string $domain
|
||||
* @return bool
|
||||
* @throws FileCreationException
|
||||
*/
|
||||
public function compileViews(array $viewPaths, $domain)
|
||||
{
|
||||
// Check the output directory
|
||||
$targetDir = $this->storagePath . DIRECTORY_SEPARATOR . $this->storageContainer;
|
||||
|
||||
if (!file_exists($targetDir)) {
|
||||
$this->createDirectory($targetDir);
|
||||
}
|
||||
|
||||
// Domain separation
|
||||
$domainDir = $targetDir . DIRECTORY_SEPARATOR . $domain;
|
||||
$this->clearDirectory($domainDir);
|
||||
$this->createDirectory($domainDir);
|
||||
|
||||
foreach ($viewPaths as $path) {
|
||||
$path = $this->basePath . DIRECTORY_SEPARATOR . $path;
|
||||
|
||||
if (!$realPath = realPath($path)) {
|
||||
throw new Exceptions\DirectoryNotFoundException("Failed to resolve $path, please check that it exists");
|
||||
}
|
||||
|
||||
$fs = new \Illuminate\Filesystem\Filesystem($path);
|
||||
$files = $fs->allFiles($realPath);
|
||||
|
||||
$compiler = new \Illuminate\View\Compilers\BladeCompiler($fs, $domainDir);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$filePath = $file->getRealPath();
|
||||
$compiler->setPath($filePath);
|
||||
|
||||
$contents = $compiler->compileString($fs->get($filePath));
|
||||
|
||||
$compiledPath = $compiler->getCompiledPath($compiler->getPath());
|
||||
|
||||
$fs->put(
|
||||
$compiledPath . '.php',
|
||||
$contents
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns the full path to the translation files
|
||||
*
|
||||
* @param null $append
|
||||
* @return string
|
||||
*/
|
||||
public function getDomainPath($append = null)
|
||||
{
|
||||
$path = [
|
||||
$this->basePath,
|
||||
$this->configuration->getTranslationsPath(),
|
||||
$this->folderName,
|
||||
];
|
||||
|
||||
if (!is_null($append)) {
|
||||
array_push($path, $append);
|
||||
}
|
||||
|
||||
return implode(DIRECTORY_SEPARATOR, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a configured .po file on $path
|
||||
* If PHP are not able to create the file the content will be returned instead
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $locale
|
||||
* @param string $domain
|
||||
* @param bool|true $write
|
||||
* @return int|string
|
||||
*/
|
||||
public function createPOFile($path, $locale, $domain, $write = true)
|
||||
{
|
||||
$project = $this->configuration->getProject();
|
||||
$timestamp = date("Y-m-d H:iO");
|
||||
$translator = $this->configuration->getTranslator();
|
||||
$encoding = $this->configuration->getEncoding();
|
||||
|
||||
$relativePath = $this->configuration->getRelativePath();
|
||||
|
||||
$keywords = implode(';', $this->configuration->getKeywordsList());
|
||||
|
||||
$template = 'msgid ""' . "\n";
|
||||
$template .= 'msgstr ""' . "\n";
|
||||
$template .= '"Project-Id-Version: ' . $project . '\n' . "\"\n";
|
||||
$template .= '"POT-Creation-Date: ' . $timestamp . '\n' . "\"\n";
|
||||
$template .= '"PO-Revision-Date: ' . $timestamp . '\n' . "\"\n";
|
||||
$template .= '"Last-Translator: ' . $translator . '\n' . "\"\n";
|
||||
$template .= '"Language-Team: ' . $translator . '\n' . "\"\n";
|
||||
$template .= '"Language: ' . $locale . '\n' . "\"\n";
|
||||
$template .= '"MIME-Version: 1.0' . '\n' . "\"\n";
|
||||
$template .= '"Content-Type: text/plain; charset=' . $encoding . '\n' . "\"\n";
|
||||
$template .= '"Content-Transfer-Encoding: 8bit' . '\n' . "\"\n";
|
||||
$template .= '"X-Generator: Poedit 1.5.4' . '\n' . "\"\n";
|
||||
$template .= '"X-Poedit-KeywordsList: ' . $keywords . '\n' . "\"\n";
|
||||
$template .= '"X-Poedit-Basepath: ' . $relativePath . '\n' . "\"\n";
|
||||
$template .= '"X-Poedit-SourceCharset: ' . $encoding . '\n' . "\"\n";
|
||||
|
||||
// Source paths
|
||||
$sourcePaths = $this->configuration->getSourcesFromDomain($domain);
|
||||
|
||||
// Compiled views on paths
|
||||
if (count($sourcePaths)) {
|
||||
|
||||
// View compilation
|
||||
$this->compileViews($sourcePaths, $domain);
|
||||
array_push($sourcePaths, $this->getStorageForDomain($domain));
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($sourcePaths as $sourcePath) {
|
||||
$template .= '"X-Poedit-SearchPath-' . $i . ': ' . $sourcePath . '\n' . "\"\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!$write) {
|
||||
return $template . "\n";
|
||||
}
|
||||
|
||||
// File creation
|
||||
$file = fopen($path, "w");
|
||||
$result = fwrite($file, $template);
|
||||
fclose($file);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if the directory can be created
|
||||
*
|
||||
* @param $path
|
||||
* @throws FileCreationException
|
||||
*/
|
||||
protected function createDirectory($path)
|
||||
{
|
||||
if (!file_exists($path) && !mkdir($path)) {
|
||||
throw new FileCreationException(
|
||||
sprintf('Can\'t create the directory: %s', $path)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new locale directory + .po file
|
||||
*
|
||||
* @param String $localePath
|
||||
* @param String $locale
|
||||
* @throws FileCreationException
|
||||
*/
|
||||
public function addLocale($localePath, $locale)
|
||||
{
|
||||
$data = array(
|
||||
$localePath,
|
||||
"LC_MESSAGES"
|
||||
);
|
||||
|
||||
if (!file_exists($localePath)) {
|
||||
$this->createDirectory($localePath);
|
||||
}
|
||||
|
||||
if ($this->configuration->getCustomLocale()) {
|
||||
$data[1] = 'C';
|
||||
|
||||
$gettextPath = implode(DIRECTORY_SEPARATOR, $data);
|
||||
if (!file_exists($gettextPath)) {
|
||||
$this->createDirectory($gettextPath);
|
||||
}
|
||||
|
||||
$data[2] = 'LC_MESSAGES';
|
||||
}
|
||||
|
||||
$gettextPath = implode(DIRECTORY_SEPARATOR, $data);
|
||||
if (!file_exists($gettextPath)) {
|
||||
$this->createDirectory($gettextPath);
|
||||
}
|
||||
|
||||
|
||||
// File generation for each domain
|
||||
foreach ($this->configuration->getAllDomains() as $domain) {
|
||||
$data[3] = $domain . ".po";
|
||||
|
||||
$localePOPath = implode(DIRECTORY_SEPARATOR, $data);
|
||||
|
||||
if (!$this->createPOFile($localePOPath, $locale, $domain)) {
|
||||
throw new FileCreationException(
|
||||
sprintf('Can\'t create the file: %s', $localePOPath)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the .po file headers by domain
|
||||
* (mainly source-file paths)
|
||||
*
|
||||
* @param $localePath
|
||||
* @param $locale
|
||||
* @param $domain
|
||||
* @return bool
|
||||
* @throws LocaleFileNotFoundException
|
||||
*/
|
||||
public function updateLocale($localePath, $locale, $domain)
|
||||
{
|
||||
$data = [
|
||||
$localePath,
|
||||
"LC_MESSAGES",
|
||||
$domain . ".po",
|
||||
];
|
||||
|
||||
if ($this->configuration->getCustomLocale()) {
|
||||
$customLocale = array('C');
|
||||
array_splice($data, 1, 0, $customLocale);
|
||||
}
|
||||
|
||||
$localePOPath = implode(DIRECTORY_SEPARATOR, $data);
|
||||
|
||||
if (!file_exists($localePOPath) || !$localeContents = file_get_contents($localePOPath)) {
|
||||
throw new LocaleFileNotFoundException(
|
||||
sprintf('Can\'t read %s verify your locale structure', $localePOPath)
|
||||
);
|
||||
}
|
||||
|
||||
$newHeader = $this->createPOFile(
|
||||
$localePOPath,
|
||||
$locale,
|
||||
$domain,
|
||||
false
|
||||
);
|
||||
|
||||
// Header replacement
|
||||
$localeContents = preg_replace('/^([^#])+:?/', $newHeader, $localeContents);
|
||||
|
||||
if (!file_put_contents($localePOPath, $localeContents)) {
|
||||
throw new LocaleFileNotFoundException(
|
||||
sprintf('Can\'t write on %s', $localePOPath)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the relative path from a file or directory to anothe
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return string
|
||||
* @author Laurent Goussard
|
||||
*/
|
||||
public function getRelativePath($from, $to)
|
||||
{
|
||||
// Compatibility fixes for Windows paths
|
||||
$from = is_dir($from) ? rtrim($from, '\/') . '/' : $from;
|
||||
$to = is_dir($to) ? rtrim($to, '\/') . '/' : $to;
|
||||
$from = str_replace('\\', '/', $from);
|
||||
$to = str_replace('\\', '/', $to);
|
||||
|
||||
$from = explode('/', $from);
|
||||
$to = explode('/', $to);
|
||||
$relPath = $to;
|
||||
|
||||
foreach ($from as $depth => $dir) {
|
||||
if ($dir !== $to[$depth]) {
|
||||
// Number of remaining directories
|
||||
$remaining = count($from) - $depth;
|
||||
|
||||
if ($remaining > 1) {
|
||||
// Add traversals up to first matching directory
|
||||
$padLength = (count($relPath) + $remaining - 1) * -1;
|
||||
|
||||
$relPath = array_pad(
|
||||
$relPath,
|
||||
$padLength,
|
||||
'..'
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$relPath[0] = './' . $relPath[0];
|
||||
}
|
||||
|
||||
array_shift($relPath);
|
||||
}
|
||||
|
||||
return implode('/', $relPath);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the required directory
|
||||
* Optionally checks each local directory, if $checkLocales is true
|
||||
*
|
||||
* @param bool|false $checkLocales
|
||||
* @return bool
|
||||
* @throws DirectoryNotFoundException
|
||||
*/
|
||||
public function checkDirectoryStructure($checkLocales = false)
|
||||
{
|
||||
// Application base path
|
||||
if (!file_exists($this->basePath)) {
|
||||
throw new Exceptions\DirectoryNotFoundException(
|
||||
sprintf(
|
||||
'Missing root path directory: %s, check the \'base-path\' key in your configuration.',
|
||||
$this->basePath
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Domain path
|
||||
$domainPath = $this->getDomainPath();
|
||||
|
||||
// Translation files domain path
|
||||
if (!file_exists($domainPath)) {
|
||||
throw new Exceptions\DirectoryNotFoundException(
|
||||
sprintf(
|
||||
'Missing base required directory: %s, remember to run \'artisan gettext:create\' the first time',
|
||||
$domainPath
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$checkLocales) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->configuration->getSupportedLocales() as $locale) {
|
||||
// Default locale is not needed
|
||||
if ($locale == $this->configuration->getLocale()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$localePath = $this->getDomainPath($locale);
|
||||
|
||||
if (!file_exists($localePath)) {
|
||||
throw new Exceptions\DirectoryNotFoundException(
|
||||
sprintf(
|
||||
'Missing locale required directory: %s, maybe you forgot to run \'artisan gettext:update\'',
|
||||
$locale
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the localization directories and files by domain
|
||||
*
|
||||
* @return array
|
||||
* @throws FileCreationException
|
||||
*/
|
||||
public function generateLocales()
|
||||
{
|
||||
// Application base path
|
||||
if (!file_exists($this->getDomainPath())) {
|
||||
$this->createDirectory($this->getDomainPath());
|
||||
}
|
||||
$localePaths = [];
|
||||
|
||||
// Locale directories
|
||||
foreach ($this->configuration->getSupportedLocales() as $locale) {
|
||||
$localePath = $this->getDomainPath($locale);
|
||||
|
||||
if (!file_exists($localePath)) {
|
||||
// Locale directory is created
|
||||
$this->addLocale($localePath, $locale);
|
||||
|
||||
array_push($localePaths, $localePath);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $localePaths;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the package configuration model.
|
||||
*
|
||||
* @return Config
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the package configuration model
|
||||
*
|
||||
* @param Config $configuration
|
||||
* @return $this
|
||||
*/
|
||||
public function setConfiguration(Config $configuration)
|
||||
{
|
||||
$this->configuration = $configuration;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filesystem base path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBasePath()
|
||||
{
|
||||
return $this->basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filesystem base path
|
||||
*
|
||||
* @param $basePath
|
||||
* @return $this
|
||||
*/
|
||||
public function setBasePath($basePath)
|
||||
{
|
||||
$this->basePath = $basePath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the storage path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStoragePath()
|
||||
{
|
||||
return $this->storagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the storage path
|
||||
*
|
||||
* @param $storagePath
|
||||
* @return $this
|
||||
*/
|
||||
public function setStoragePath($storagePath)
|
||||
{
|
||||
$this->storagePath = $storagePath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path for domain storage directory
|
||||
*
|
||||
* @param $domain
|
||||
* @return String
|
||||
*/
|
||||
public function getStorageForDomain($domain)
|
||||
{
|
||||
$domainPath = $this->storagePath .
|
||||
DIRECTORY_SEPARATOR .
|
||||
$this->storageContainer .
|
||||
DIRECTORY_SEPARATOR .
|
||||
$domain;
|
||||
|
||||
return $this->getRelativePath($this->basePath, $domainPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the directory contents recursively
|
||||
*
|
||||
* @param string $path
|
||||
* @return null|boolean
|
||||
*/
|
||||
public static function clearDirectory($path)
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$files = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
|
||||
foreach ($files as $fileinfo) {
|
||||
// if the file isn't a .gitignore file we should remove it.
|
||||
if ($fileinfo->getFilename() !== '.gitignore') {
|
||||
$todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
|
||||
$todo($fileinfo->getRealPath());
|
||||
}
|
||||
}
|
||||
|
||||
// since the folder now contains a .gitignore we can't remove it
|
||||
//rmdir($path);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folder name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFolderName()
|
||||
{
|
||||
return $this->folderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the folder name
|
||||
*
|
||||
* @param $folderName
|
||||
*/
|
||||
public function setFolderName($folderName)
|
||||
{
|
||||
$this->folderName = $folderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full path for a .po/.mo file from its domain and locale
|
||||
*
|
||||
* @param $locale
|
||||
* @param $domain
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function makeFilePath($locale, $domain, $type = 'po')
|
||||
{
|
||||
$filePath = implode(
|
||||
DIRECTORY_SEPARATOR, [
|
||||
$locale,
|
||||
'LC_MESSAGES',
|
||||
$domain . "." . $type
|
||||
]
|
||||
);
|
||||
|
||||
return $this->getDomainPath($filePath);
|
||||
}
|
||||
|
||||
}
|
195
app/LaravelGettext/LaravelGettext.php
Normal file
195
app/LaravelGettext/LaravelGettext.php
Normal file
@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext;
|
||||
|
||||
use App\LaravelGettext\Composers\LanguageSelector;
|
||||
use App\LaravelGettext\Translators\TranslatorInterface;
|
||||
|
||||
class LaravelGettext
|
||||
{
|
||||
/**
|
||||
* Translator handler
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @param TranslatorInterface $gettext
|
||||
* @throws Exceptions\MissingPhpGettextModuleException
|
||||
*/
|
||||
public function __construct(TranslatorInterface $gettext)
|
||||
{
|
||||
$this->translator = $gettext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
return $this->translator->getEncoding();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current encoding
|
||||
*
|
||||
* @param string $encoding
|
||||
* @return $this
|
||||
*/
|
||||
public function setEncoding($encoding)
|
||||
{
|
||||
$this->encoding = $encoding;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Current locale.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->translator->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current locale
|
||||
*
|
||||
* @param string $locale
|
||||
* @return $this
|
||||
* @throws Exceptions\LocaleNotSupportedException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
if ($locale != $this->getLocale()) {
|
||||
$this->translator->setLocale($locale);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the language portion of the locale
|
||||
* (ex. en_GB returns en)
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLocaleLanguage($locale = null)
|
||||
{
|
||||
if (is_null($locale)) {
|
||||
$locale = $this->getLocale();
|
||||
}
|
||||
|
||||
$localeArray = explode('_', $locale);
|
||||
|
||||
if (!isset($localeArray[0])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $localeArray[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the language selector object
|
||||
*
|
||||
* @param array $labels
|
||||
* @return LanguageSelector
|
||||
*/
|
||||
public function getSelector($labels = [])
|
||||
{
|
||||
return LanguageSelector::create($this, $labels);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current domain
|
||||
*
|
||||
* @param string $domain
|
||||
* @return $this
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
$this->translator->setDomain($domain);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current domain
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
return $this->translator->getDomain();
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a message with the current handler
|
||||
*
|
||||
* @param $message
|
||||
* @return string
|
||||
*/
|
||||
public function translate($message)
|
||||
{
|
||||
return $this->translator->translate($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a plural string with the current handler
|
||||
*
|
||||
* @param $singular
|
||||
* @param $plural
|
||||
* @param $count
|
||||
* @return string
|
||||
*/
|
||||
public function translatePlural($singular, $plural, $count)
|
||||
{
|
||||
return $this->translator->translatePlural($singular, $plural, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translator.
|
||||
*
|
||||
* @return TranslatorInterface
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
return $this->translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the translator
|
||||
*
|
||||
* @param TranslatorInterface $translator
|
||||
* @return $this
|
||||
*/
|
||||
public function setTranslator(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns supported locales
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSupportedLocales()
|
||||
{
|
||||
return $this->translator->supportedLocales();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if given locale is supported
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLocaleSupported($locale)
|
||||
{
|
||||
return $this->translator->isLocaleSupported($locale);
|
||||
}
|
||||
}
|
128
app/LaravelGettext/LaravelGettextServiceProvider.php
Normal file
128
app/LaravelGettext/LaravelGettextServiceProvider.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Foundation\AliasLoader;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\LaravelGettext\Adapters\AdapterInterface;
|
||||
use App\LaravelGettext\Config\ConfigManager;
|
||||
use App\LaravelGettext\Config\Models\Config;
|
||||
|
||||
/**
|
||||
* Main service provider
|
||||
*
|
||||
* Class LaravelGettextServiceProvider
|
||||
* @package App\LaravelGettext
|
||||
*
|
||||
*/
|
||||
class LaravelGettextServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__ . '/../../config/config.php' => config_path('laravel-gettext.php')
|
||||
], 'config');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$configuration = ConfigManager::create();
|
||||
|
||||
$this->app->bind(
|
||||
AdapterInterface::class,
|
||||
$configuration->get()->getAdapter()
|
||||
);
|
||||
|
||||
$this->app->singleton(Config::class, function($app) use ($configuration){
|
||||
return $configuration->get();
|
||||
});
|
||||
|
||||
// Main class register
|
||||
$this->app->singleton(LaravelGettext::class, function (Application $app) use ($configuration) {
|
||||
|
||||
$fileSystem = new FileSystem($configuration->get(), app_path(), storage_path());
|
||||
$storage = $app->make($configuration->get()->getStorage());
|
||||
|
||||
if ('symfony' == $configuration->get()->getHandler()) {
|
||||
// symfony translator implementation
|
||||
$translator = new Translators\Symfony(
|
||||
$configuration->get(),
|
||||
$this->app->make(AdapterInterface::class),
|
||||
$fileSystem,
|
||||
$storage
|
||||
);
|
||||
} else {
|
||||
// GNU/Gettext php extension
|
||||
$translator = new Translators\Gettext(
|
||||
$configuration->get(),
|
||||
$this->app->make(AdapterInterface::class),
|
||||
$fileSystem,
|
||||
$storage
|
||||
);
|
||||
}
|
||||
|
||||
return new LaravelGettext($translator);
|
||||
|
||||
});
|
||||
$this->app->alias(LaravelGettext::class, 'laravel-gettext');
|
||||
|
||||
// Alias
|
||||
$this->app->booting(function () {
|
||||
$aliasLoader = AliasLoader::getInstance();
|
||||
$aliasLoader->alias('LaravelGettext', \App\LaravelGettext\Facades\LaravelGettext::class);
|
||||
});
|
||||
|
||||
$this->registerCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands
|
||||
*/
|
||||
protected function registerCommands()
|
||||
{
|
||||
// Package commands
|
||||
$this->app->bind('xinax::gettext.create', function ($app) {
|
||||
return new Commands\GettextCreate();
|
||||
});
|
||||
|
||||
$this->app->bind('xinax::gettext.update', function ($app) {
|
||||
return new Commands\GettextUpdate();
|
||||
});
|
||||
|
||||
$this->commands([
|
||||
'xinax::gettext.create',
|
||||
'xinax::gettext.update',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return [
|
||||
'laravel-gettext'
|
||||
];
|
||||
}
|
||||
}
|
29
app/LaravelGettext/Middleware/GettextMiddleware.php
Normal file
29
app/LaravelGettext/Middleware/GettextMiddleware.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Middleware;
|
||||
|
||||
use Closure;
|
||||
use \LaravelGettext;
|
||||
|
||||
class GettextMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
/**
|
||||
* The package need to be initialized, the locale will
|
||||
* be available after first method call. If you have
|
||||
* async calls in your project, this filter starts the
|
||||
* locale environment before each request.
|
||||
*/
|
||||
LaravelGettext::getLocale();
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
132
app/LaravelGettext/Storages/MemoryStorage.php
Normal file
132
app/LaravelGettext/Storages/MemoryStorage.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: aaflalo
|
||||
* Date: 03/02/17
|
||||
* Time: 10:08 AM
|
||||
*/
|
||||
|
||||
namespace App\LaravelGettext\Storages;
|
||||
|
||||
|
||||
class MemoryStorage implements Storage
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Config container
|
||||
*
|
||||
* @type \App\LaravelGettext\Config\Models\Config
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* SessionStorage constructor.
|
||||
*
|
||||
* @param \App\LaravelGettext\Config\Models\Config $configuration
|
||||
*/
|
||||
public function __construct(\App\LaravelGettext\Config\Models\Config $configuration)
|
||||
{
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var String
|
||||
*/
|
||||
protected $domain;
|
||||
|
||||
/**
|
||||
* Current locale
|
||||
* @type String
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* Current encoding
|
||||
* @type String
|
||||
*/
|
||||
protected $encoding;
|
||||
|
||||
|
||||
/**
|
||||
* Getter for domain
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
return $this->domain ?: $this->configuration->getDomain();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $domain
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
$this->domain = $domain;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for locale
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale ?: $this->configuration->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $locale
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for configuration
|
||||
*
|
||||
* @return \App\LaravelGettext\Config\Models\Config
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for encoding
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
return $this->encoding ?: $this->configuration->getEncoding();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $encoding
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEncoding($encoding)
|
||||
{
|
||||
$this->encoding = $encoding;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
140
app/LaravelGettext/Storages/SessionStorage.php
Normal file
140
app/LaravelGettext/Storages/SessionStorage.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: aaflalo
|
||||
* Date: 03/02/17
|
||||
* Time: 10:08 AM
|
||||
*/
|
||||
|
||||
namespace App\LaravelGettext\Storages;
|
||||
|
||||
use Session;
|
||||
|
||||
class SessionStorage implements Storage
|
||||
{
|
||||
/**
|
||||
* Config container
|
||||
*
|
||||
* @type \App\LaravelGettext\Config\Models\Config
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* SessionStorage constructor.
|
||||
*
|
||||
* @param \App\LaravelGettext\Config\Models\Config $configuration
|
||||
*/
|
||||
public function __construct(\App\LaravelGettext\Config\Models\Config $configuration)
|
||||
{
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter for domain
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
return $this->sessionGet('domain', $this->configuration->getDomain());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $domain
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
$this->sessionSet('domain', $domain);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for locale
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->sessionGet('locale', $this->configuration->getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $locale
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->sessionSet('locale', $locale);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for configuration
|
||||
*
|
||||
* @return \App\LaravelGettext\Config\Models\Config
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a value from session with an optional default
|
||||
*
|
||||
* @param $key
|
||||
* @param null $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function sessionGet($key, $default = null)
|
||||
{
|
||||
$token = $this->configuration->getSessionIdentifier() . "-" . $key;
|
||||
|
||||
return Session::get($token, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value in session session
|
||||
*
|
||||
* @param $key
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function sessionSet($key, $value)
|
||||
{
|
||||
$token = $this->configuration->getSessionIdentifier() . "-" . $key;
|
||||
Session::put($token, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for locale
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
return $this->sessionGet('encoding', $this->configuration->getEncoding());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $encoding
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEncoding($encoding)
|
||||
{
|
||||
$this->sessionSet('encoding', $encoding);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
60
app/LaravelGettext/Storages/Storage.php
Normal file
60
app/LaravelGettext/Storages/Storage.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: aaflalo
|
||||
* Date: 03/02/17
|
||||
* Time: 10:10 AM
|
||||
*/
|
||||
namespace App\LaravelGettext\Storages;
|
||||
|
||||
interface Storage
|
||||
{
|
||||
/**
|
||||
* Getter for domain
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getDomain();
|
||||
|
||||
/**
|
||||
* @param string $domain
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDomain($domain);
|
||||
|
||||
/**
|
||||
* Getter for locale
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getLocale();
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLocale($locale);
|
||||
|
||||
/**
|
||||
* Getter for locale
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getEncoding();
|
||||
|
||||
/**
|
||||
* @param string $encoding
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEncoding($encoding);
|
||||
|
||||
/**
|
||||
* Getter for configuration
|
||||
*
|
||||
* @return \App\LaravelGettext\Config\Models\Config
|
||||
*/
|
||||
public function getConfiguration();
|
||||
}
|
124
app/LaravelGettext/Support/helpers.php
Normal file
124
app/LaravelGettext/Support/helpers.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
use App\LaravelGettext\LaravelGettext;
|
||||
|
||||
if (!function_exists('_i')) {
|
||||
/**
|
||||
* Translate a formatted string based on printf formats
|
||||
* Can be use an array on args or use the number of the arguments
|
||||
*
|
||||
* @param string $message the message to translate
|
||||
* @param array|mixed $args the tokens values used inside the $message
|
||||
*
|
||||
* @return string the message translated and formatted
|
||||
*/
|
||||
function _i($message, $args = null)
|
||||
{
|
||||
|
||||
$translator = app(LaravelGettext::class);
|
||||
$translation = $translator->translate($message);
|
||||
|
||||
if (strlen($translation)) {
|
||||
if (isset($args)) {
|
||||
if (!is_array($args)) {
|
||||
$args = array_slice(func_get_args(), 1);
|
||||
}
|
||||
$translation = vsprintf($translation, $args);
|
||||
}
|
||||
|
||||
return $translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* If translations are missing returns
|
||||
* the original message.
|
||||
*
|
||||
* @see https://github.com/symfony/symfony/issues/13483
|
||||
*/
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('__')) {
|
||||
/**
|
||||
* Translate a formatted string based on printf formats
|
||||
* Can be use an array on args or use the number of the arguments
|
||||
*
|
||||
* @param string $message the message to translate
|
||||
* @param array|mixed $args the tokens values used inside the $message
|
||||
*
|
||||
* @return string the message translated and formatted
|
||||
*/
|
||||
function __($message, $args = null)
|
||||
{
|
||||
return _i($message, $args);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('_')) {
|
||||
/**
|
||||
* Generic translation function
|
||||
*
|
||||
* @param $message
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function _($message, $args = null)
|
||||
{
|
||||
return _i($message, $args);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('_n')) {
|
||||
/**
|
||||
* Translate a formatted pluralized string based on printf formats
|
||||
* Can be use an array on args or use the number of the arguments
|
||||
*
|
||||
* @param string $singular the singular message to be translated
|
||||
* @param string $plural the plural message to be translated if the $count > 1
|
||||
* @param int $count the number of occurrence to be used to pluralize the $singular
|
||||
* @param array|mixed $args the tokens values used inside $singular or $plural
|
||||
*
|
||||
* @return string the message translated, pluralized and formatted
|
||||
*/
|
||||
function _n($singular, $plural, $count, $args = null)
|
||||
{
|
||||
$translator = app(LaravelGettext::class);
|
||||
$message = $translator->translatePlural($singular, $plural, $count);
|
||||
|
||||
if (isset($args) && !is_array($args)) {
|
||||
$args = array_slice(func_get_args(), 3);
|
||||
}
|
||||
$message = vsprintf($message, $args);
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('_s')) {
|
||||
/**
|
||||
* Translate a formatted pluralized string based on printf formats mixed with the Symfony format
|
||||
* Can be use an array on args or use the number of the arguments
|
||||
*
|
||||
* <b>Only works if Symfony is the used backend</b>
|
||||
*
|
||||
* @param string $message The one line message containing the different pluralization separated by pipes
|
||||
* See Symfony translation documentation
|
||||
* @param int $count the number of occurrence to be used to pluralize the $singular
|
||||
* @param array|mixed $args the tokens values used inside $singular or $plural
|
||||
*
|
||||
* @return string the message translated, pluralized and formatted
|
||||
*/
|
||||
function _s($message, $count, $args = null)
|
||||
{
|
||||
$translator = app(LaravelGettext::class);
|
||||
$message = $translator->getTranslator()->translatePluralInline($message, $count);
|
||||
|
||||
if (isset($args) && !is_array($args)) {
|
||||
$args = array_slice(func_get_args(), 3);
|
||||
}
|
||||
$message = vsprintf($message, $args);
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
53
app/LaravelGettext/Testing/Adapter/TestAdapter.php
Normal file
53
app/LaravelGettext/Testing/Adapter/TestAdapter.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: aaflalo
|
||||
* Date: 18-02-23
|
||||
* Time: 11:50
|
||||
*/
|
||||
|
||||
namespace App\LaravelGettext\Testing\Adapter;
|
||||
|
||||
use App\LaravelGettext\Adapters\AdapterInterface;
|
||||
|
||||
class TestAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $locale = 'en_US';
|
||||
|
||||
/**
|
||||
* Get the current locale
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the locale on the adapter
|
||||
*
|
||||
* @param string $locale
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the application path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApplicationPath()
|
||||
{
|
||||
return app_path();
|
||||
}
|
||||
}
|
40
app/LaravelGettext/Testing/BaseTestCase.php
Normal file
40
app/LaravelGettext/Testing/BaseTestCase.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php namespace App\LaravelGettext\Testing;
|
||||
|
||||
use \Illuminate\Foundation\Testing\TestCase;
|
||||
use App\LaravelGettext\LaravelGettextServiceProvider;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: shaggyz
|
||||
* Date: 17/10/16
|
||||
* Time: 14:41
|
||||
*/
|
||||
class BaseTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* Base app path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $appPath;
|
||||
|
||||
/**
|
||||
* Instantiates the laravel environment.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
// relative path in package folder
|
||||
if (!$this->appPath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$app = require $this->appPath;
|
||||
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
|
||||
$app->register(LaravelGettextServiceProvider::class);
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
176
app/LaravelGettext/Translators/BaseTranslator.php
Normal file
176
app/LaravelGettext/Translators/BaseTranslator.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php namespace App\LaravelGettext\Translators;
|
||||
|
||||
use App\LaravelGettext\Adapters\AdapterInterface;
|
||||
use App\LaravelGettext\Config\Models\Config;
|
||||
use App\LaravelGettext\Exceptions\UndefinedDomainException;
|
||||
use App\LaravelGettext\FileSystem;
|
||||
use App\LaravelGettext\Storages\Storage;
|
||||
|
||||
abstract class BaseTranslator implements TranslatorInterface
|
||||
{
|
||||
/**
|
||||
* Config container
|
||||
*
|
||||
* @type \App\LaravelGettext\Config\Models\Config
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* Framework adapter
|
||||
*
|
||||
* @type \App\LaravelGettext\Adapters\LaravelAdapter
|
||||
*/
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
* File system helper
|
||||
*
|
||||
* @var \App\LaravelGettext\FileSystem
|
||||
*/
|
||||
protected $fileSystem;
|
||||
|
||||
/**
|
||||
* @var Storage
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the module translator
|
||||
*
|
||||
* @param Config $config
|
||||
* @param AdapterInterface $adapter
|
||||
* @param FileSystem $fileSystem
|
||||
*
|
||||
* @param Storage $storage
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config, AdapterInterface $adapter, FileSystem $fileSystem, Storage $storage)
|
||||
{
|
||||
// Sets the package configuration and session handler
|
||||
$this->configuration = $config;
|
||||
$this->adapter = $adapter;
|
||||
$this->fileSystem = $fileSystem;
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current locale string identifier
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->storage->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets and stores on session the current locale code
|
||||
*
|
||||
* @param $locale
|
||||
*
|
||||
* @return BaseTranslator
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
if ($locale == $this->storage->getLocale()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->storage->setLocale($locale);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean that indicates if $locale
|
||||
* is supported by configuration
|
||||
*
|
||||
* @param $locale
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLocaleSupported($locale)
|
||||
{
|
||||
if ($locale) {
|
||||
return in_array($locale, $this->configuration->getSupportedLocales());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current locale
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Current encoding.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
return $this->storage->getEncoding();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Current encoding.
|
||||
*
|
||||
* @param mixed $encoding the encoding
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setEncoding($encoding)
|
||||
{
|
||||
$this->storage->setEncoding($encoding);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current domain and updates gettext domain application
|
||||
*
|
||||
* @param String $domain
|
||||
*
|
||||
* @throws UndefinedDomainException If domain is not defined
|
||||
* @return self
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
if (!in_array($domain, $this->configuration->getAllDomains())) {
|
||||
throw new UndefinedDomainException("Domain '$domain' is not registered.");
|
||||
}
|
||||
|
||||
$this->storage->setDomain($domain);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current domain
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getDomain()
|
||||
{
|
||||
return $this->storage->getDomain();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns supported locales
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function supportedLocales()
|
||||
{
|
||||
return $this->configuration->getSupportedLocales();
|
||||
}
|
||||
|
||||
}
|
219
app/LaravelGettext/Translators/Gettext.php
Normal file
219
app/LaravelGettext/Translators/Gettext.php
Normal file
@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext\Translators;
|
||||
|
||||
use App\LaravelGettext\FileSystem;
|
||||
use App\LaravelGettext\Adapters\AdapterInterface;
|
||||
use App\LaravelGettext\Config\Models\Config;
|
||||
use App\LaravelGettext\Exceptions\LocaleNotSupportedException;
|
||||
use App\LaravelGettext\Exceptions\MissingPhpGettextModuleException;
|
||||
use App\LaravelGettext\Exceptions\UndefinedDomainException;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use App\LaravelGettext\Storages\Storage;
|
||||
|
||||
/**
|
||||
* Class implemented by the php-gettext module translator
|
||||
* @package App\LaravelGettext\Translators
|
||||
*/
|
||||
class Gettext extends BaseTranslator implements TranslatorInterface
|
||||
{
|
||||
/**
|
||||
* Config container
|
||||
* @type \App\LaravelGettext\Config\Models\Config
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* Current encoding
|
||||
* @type String
|
||||
*/
|
||||
protected $encoding;
|
||||
|
||||
/**
|
||||
* Current locale
|
||||
* @type String
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* Locale categories
|
||||
* @type array
|
||||
*/
|
||||
protected $categories;
|
||||
|
||||
/**
|
||||
* Framework adapter
|
||||
* @type \App\LaravelGettext\Adapters\LaravelAdapter
|
||||
*/
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
* File system helper
|
||||
* @var FileSystem
|
||||
*/
|
||||
protected $fileSystem;
|
||||
|
||||
/**
|
||||
* @var String
|
||||
*/
|
||||
protected $domain;
|
||||
|
||||
public function __construct(Config $config, AdapterInterface $adapter, FileSystem $fileSystem,
|
||||
Storage $storage)
|
||||
{
|
||||
parent::__construct($config, $adapter, $fileSystem, $storage);
|
||||
|
||||
// General domain
|
||||
$this->domain = $this->storage->getDomain();
|
||||
|
||||
// Encoding is set from configuration
|
||||
$this->encoding = $this->storage->getEncoding();
|
||||
|
||||
// Categories are set from configuration
|
||||
$this->categories = $this->configuration->getCategories();
|
||||
|
||||
// Sets defaults for boot
|
||||
$locale = $this->storage->getLocale();
|
||||
|
||||
$this->setLocale($locale);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the current locale code
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
if (!$this->isLocaleSupported($locale)) {
|
||||
throw new LocaleNotSupportedException(
|
||||
sprintf('Locale %s is not supported', $locale)
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
$customLocale = $this->configuration->getCustomLocale() ? "C." : $locale . ".";
|
||||
$gettextLocale = $customLocale . $this->getEncoding();
|
||||
|
||||
// Update all categories set in config
|
||||
foreach($this->categories as $category) {
|
||||
putenv("$category=$gettextLocale");
|
||||
setlocale(constant($category), $gettextLocale);
|
||||
}
|
||||
|
||||
parent::setLocale($locale);
|
||||
|
||||
// Laravel built-in locale
|
||||
if ($this->configuration->isSyncLaravel()) {
|
||||
$this->adapter->setLocale($locale);
|
||||
}
|
||||
|
||||
return $this->getLocale();
|
||||
} catch (\Exception $e) {
|
||||
$this->locale = $this->configuration->getFallbackLocale();
|
||||
$exceptionPosition = $e->getFile() . ":" . $e->getLine();
|
||||
throw new \Exception($exceptionPosition . $e->getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean that indicates if $locale
|
||||
* is supported by configuration
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLocaleSupported($locale)
|
||||
{
|
||||
if ($locale) {
|
||||
return in_array($locale, $this->supportedLocales());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current locale
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getLocale();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the Current encoding.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
return $this->encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Current encoding.
|
||||
*
|
||||
* @param mixed $encoding the encoding
|
||||
* @return self
|
||||
*/
|
||||
public function setEncoding($encoding)
|
||||
{
|
||||
$this->encoding = $encoding;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current domain and updates gettext domain application
|
||||
*
|
||||
* @param String $domain
|
||||
* @throws UndefinedDomainException If domain is not defined
|
||||
* @return self
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
parent::setDomain($domain);
|
||||
|
||||
$customLocale = $this->configuration->getCustomLocale() ? "/" . $this->getLocale() : "";
|
||||
|
||||
bindtextdomain($domain, $this->fileSystem->getDomainPath() . $customLocale);
|
||||
bind_textdomain_codeset($domain, $this->getEncoding());
|
||||
|
||||
$this->domain = textdomain($domain);
|
||||
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a message with gettext
|
||||
*
|
||||
* @param $message
|
||||
*/
|
||||
public function translate($message)
|
||||
{
|
||||
return gettext($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a plural message with gettext
|
||||
*
|
||||
* @param $singular
|
||||
* @param $plural
|
||||
* @param $count
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function translatePlural($singular, $plural, $count)
|
||||
{
|
||||
return ngettext($singular, $plural, $count);
|
||||
}
|
||||
|
||||
public function translatePluralInline($message, $amount)
|
||||
{
|
||||
throw new \RuntimeException('Not supported by gettext, please use Symfony');
|
||||
}
|
||||
}
|
220
app/LaravelGettext/Translators/Symfony.php
Normal file
220
app/LaravelGettext/Translators/Symfony.php
Normal file
@ -0,0 +1,220 @@
|
||||
<?php namespace App\LaravelGettext\Translators;
|
||||
|
||||
use Symfony\Component\Translation\Loader\PoFileLoader;
|
||||
use Symfony\Component\Translation\Translator as SymfonyTranslator;
|
||||
use App\LaravelGettext\Adapters\AdapterInterface;
|
||||
use App\LaravelGettext\Config\Models\Config;
|
||||
use App\LaravelGettext\FileLoader\Cache\ApcuFileCacheLoader;
|
||||
use App\LaravelGettext\FileLoader\MoFileLoader;
|
||||
use App\LaravelGettext\FileSystem;
|
||||
use App\LaravelGettext\Storages\Storage;
|
||||
|
||||
/**
|
||||
* Class implemented by Symfony translation component
|
||||
*
|
||||
* @package App\LaravelGettext\Translators
|
||||
*/
|
||||
class Symfony extends BaseTranslator
|
||||
{
|
||||
|
||||
/**
|
||||
* Symfony translator
|
||||
*
|
||||
* @var SymfonyTranslator
|
||||
*/
|
||||
protected $symfonyTranslator;
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
*/
|
||||
protected $loadedResources = [];
|
||||
|
||||
public function __construct(Config $config, AdapterInterface $adapter, FileSystem $fileSystem, Storage $storage)
|
||||
{
|
||||
parent::__construct($config, $adapter, $fileSystem, $storage);
|
||||
$this->setLocale($this->storage->getLocale());
|
||||
$this->loadLocaleFile();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translates a message using the Symfony translation component
|
||||
*
|
||||
* @param $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function translate($message)
|
||||
{
|
||||
return $this->symfonyTranslator->trans($message, [], $this->getDomain(), $this->getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translator instance
|
||||
*
|
||||
* @return SymfonyTranslator
|
||||
*/
|
||||
protected function getTranslator()
|
||||
{
|
||||
if (isset($this->symfonyTranslator)) {
|
||||
return $this->symfonyTranslator;
|
||||
}
|
||||
|
||||
return $this->symfonyTranslator = $this->createTranslator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set locale overload.
|
||||
* Needed to re-build the catalogue when locale changes.
|
||||
*
|
||||
* @param $locale
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
parent::setLocale($locale);
|
||||
$this->getTranslator()->setLocale($locale);
|
||||
$this->loadLocaleFile();
|
||||
|
||||
if ($locale != $this->adapter->getLocale()) {
|
||||
$this->adapter->setLocale($locale);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set domain overload.
|
||||
* Needed to re-build the catalogue when domain changes.
|
||||
*
|
||||
*
|
||||
* @param String $domain
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDomain($domain)
|
||||
{
|
||||
parent::setDomain($domain);
|
||||
|
||||
$this->loadLocaleFile();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new translator instance
|
||||
*
|
||||
* @return SymfonyTranslator
|
||||
*/
|
||||
protected function createTranslator()
|
||||
{
|
||||
$translator = new SymfonyTranslator($this->configuration->getLocale());
|
||||
$translator->setFallbackLocales([$this->configuration->getFallbackLocale()]);
|
||||
$translator->addLoader('mo', new ApcuFileCacheLoader(new MoFileLoader()));
|
||||
$translator->addLoader('po', new ApcuFileCacheLoader(new PoFileLoader()));
|
||||
|
||||
return $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a plural string
|
||||
*
|
||||
* @param $singular
|
||||
* @param $plural
|
||||
* @param $amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function translatePlural($singular, $plural, $amount)
|
||||
{
|
||||
return $this->symfonyTranslator->trans(
|
||||
$amount > 1
|
||||
? $plural
|
||||
: $singular,
|
||||
['%count%' => $amount],
|
||||
$this->getDomain(),
|
||||
$this->getLocale()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a plural string that is only on one line separated with pipes
|
||||
*
|
||||
* @param $message
|
||||
* @param $amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function translatePluralInline($message, $amount)
|
||||
{
|
||||
return $this->symfonyTranslator->trans(
|
||||
$message,
|
||||
[
|
||||
'%count%' => $amount
|
||||
],
|
||||
$this->getDomain(),
|
||||
$this->getLocale()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal param $translator
|
||||
*/
|
||||
protected function loadLocaleFile()
|
||||
{
|
||||
if (isset($this->loadedResources[$this->getDomain()])
|
||||
&& isset($this->loadedResources[$this->getDomain()][$this->getLocale()])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
$translator = $this->getTranslator();
|
||||
|
||||
$fileMo = $this->fileSystem->makeFilePath($this->getLocale(), $this->getDomain(), 'mo');
|
||||
if (file_exists($fileMo)) {
|
||||
$translator->addResource('mo', $fileMo, $this->getLocale(), $this->getDomain());
|
||||
} else {
|
||||
$file = $this->fileSystem->makeFilePath($this->getLocale(), $this->getDomain());
|
||||
$translator->addResource('po', $file, $this->getLocale(), $this->getDomain());
|
||||
}
|
||||
|
||||
$this->loadedResources[$this->getDomain()][$this->getLocale()] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean that indicates if $locale
|
||||
* is supported by configuration
|
||||
*
|
||||
* @param $locale
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLocaleSupported($locale)
|
||||
{
|
||||
if ($locale) {
|
||||
return in_array($locale, $this->configuration->getSupportedLocales());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current locale
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns supported locales
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function supportedLocales()
|
||||
{
|
||||
return $this->configuration->getSupportedLocales();
|
||||
}
|
||||
}
|
119
app/LaravelGettext/Translators/TranslatorInterface.php
Normal file
119
app/LaravelGettext/Translators/TranslatorInterface.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php namespace App\LaravelGettext\Translators;
|
||||
|
||||
use App\LaravelGettext\Adapters\AdapterInterface;
|
||||
use App\LaravelGettext\Config\Models\Config;
|
||||
use App\LaravelGettext\FileSystem;
|
||||
use App\LaravelGettext\Storages\Storage;
|
||||
|
||||
interface TranslatorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Initializes the module translator
|
||||
*
|
||||
* @param Config $config
|
||||
* @param AdapterInterface $adapter
|
||||
* @param FileSystem $fileSystem
|
||||
*
|
||||
* @param Storage $storage
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config, AdapterInterface $adapter, FileSystem $fileSystem, Storage $storage);
|
||||
|
||||
/**
|
||||
* Sets the current locale code
|
||||
*/
|
||||
public function setLocale($locale);
|
||||
|
||||
/**
|
||||
* Returns the current locale string identifier
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getLocale();
|
||||
|
||||
/**
|
||||
* Returns a boolean that indicates if $locale
|
||||
* is supported by configuration
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLocaleSupported($locale);
|
||||
|
||||
/**
|
||||
* Returns supported locales
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function supportedLocales();
|
||||
|
||||
/**
|
||||
* Return the current locale
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __toString();
|
||||
|
||||
/**
|
||||
* Gets the Current encoding.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEncoding();
|
||||
|
||||
/**
|
||||
* Sets the Current encoding.
|
||||
*
|
||||
* @param mixed $encoding the encoding
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setEncoding($encoding);
|
||||
|
||||
/**
|
||||
* Sets the current domain and updates gettext domain application
|
||||
*
|
||||
* @param String $domain
|
||||
*
|
||||
* @throws \App\LaravelGettext\Exceptions\UndefinedDomainException If domain is not defined
|
||||
* @return self
|
||||
*/
|
||||
public function setDomain($domain);
|
||||
|
||||
/**
|
||||
* Returns the current domain
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function getDomain();
|
||||
|
||||
/**
|
||||
* Translates a single message
|
||||
*
|
||||
* @param $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function translate($message);
|
||||
|
||||
/**
|
||||
* Translates a plural string
|
||||
*
|
||||
* @param $singular
|
||||
* @param $plural
|
||||
* @param $count
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function translatePlural($singular, $plural, $count);
|
||||
|
||||
/**
|
||||
* Translate a plural string that is only on one line separated with pipes
|
||||
*
|
||||
* @param $message
|
||||
* @param $amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function translatePluralInline($message, $amount);
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
namespace App\View\Components\Inputs;
|
||||
|
||||
use App\View\Components\InputWrapper;
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\Component;use Illuminate\Support\Str;
|
||||
|
||||
class Number extends InputWrapper
|
||||
{
|
||||
@ -40,7 +40,7 @@ class Number extends InputWrapper
|
||||
|
||||
// Gestione della precisione (numero specifico, oppure "qta" per il valore previsto nell'impostazione "Cifre decimali per quantità").
|
||||
$decimals = $this->get('decimals');
|
||||
if (string_starts_with($decimals, 'qta')) {
|
||||
if (Str::startsWith($decimals, 'qta')) {
|
||||
$decimals = setting('Cifre decimali per quantità');
|
||||
|
||||
// Se non è previsto un valore minimo, lo imposta a 1
|
||||
|
@ -15,7 +15,7 @@
|
||||
}],
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php": "^7.3|^8.0",
|
||||
"php": "^8.0.2",
|
||||
"ext-curl": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-fileinfo": "*",
|
||||
@ -32,26 +32,21 @@
|
||||
"danielstjules/stringy": "^3.1",
|
||||
"devcode-it/aggiornamenti": "@dev",
|
||||
"devcode-it/causali-trasporto": "@dev",
|
||||
"devcode-it/legacy": "@dev",
|
||||
"fideloper/proxy": "^4.4",
|
||||
"filp/whoops": "^2.1",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"devcode-it/legacy": "dev-legacy",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"intervention/image": "^2.3",
|
||||
"laravel/framework": "^8.12",
|
||||
"laravel/framework": "^9.0",
|
||||
"laravel/tinker": "^2.5",
|
||||
"spatie/laravel-ignition": "^1.0",
|
||||
"symfony/polyfill-ctype": "^1.8",
|
||||
"symfony/polyfill-php70": "^1.8",
|
||||
"zerospam/laravel-gettext": "^7.2"
|
||||
"symfony/polyfill-php70": "^1.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"facade/ignition": "^2.5",
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
"friendsofphp/php-cs-fixer": "^3.0",
|
||||
"jeroen-g/laravel-packager": "^2.5",
|
||||
"laravel/homestead": "^12.2",
|
||||
"mockery/mockery": "^1.4.2",
|
||||
"nunomaduro/collision": "^5.0",
|
||||
"nunomaduro/collision": "^6.1",
|
||||
"phpunit/phpunit": "^9.3.3"
|
||||
},
|
||||
"config": {
|
||||
@ -66,7 +61,8 @@
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
},
|
||||
"files": [
|
||||
"app/helpers.php"
|
||||
"app/helpers.php",
|
||||
"app/LaravelGettext/Support/helpers.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
@ -95,27 +91,34 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"repositories": {
|
||||
"devcode-it/aggiornamenti": {
|
||||
"repositories": [
|
||||
{
|
||||
"url": "https://github.com/wdog/sdd_ita.git",
|
||||
"type": "git"
|
||||
},
|
||||
{
|
||||
"name": "devcode-it/aggiornamenti",
|
||||
"type": "path",
|
||||
"url": "./packages/devcode-it/aggiornamenti",
|
||||
"options": {
|
||||
"symlink": true
|
||||
}
|
||||
},
|
||||
"devcode-it/causali-trasporto": {
|
||||
{
|
||||
"name": "devcode-it/causali-trasporto",
|
||||
"type": "path",
|
||||
"url": "./packages/devcode-it/causali-trasporto",
|
||||
"options": {
|
||||
"symlink": true
|
||||
}
|
||||
},
|
||||
"devcode-it/legacy": {
|
||||
{
|
||||
"name": "devcode-it/legacy",
|
||||
"type": "path",
|
||||
"url": "../legacy",
|
||||
"options": {
|
||||
"symlink": true
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -172,6 +172,7 @@ return [
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
App\LaravelGettext\LaravelGettextServiceProvider::class,
|
||||
],
|
||||
|
||||
/*
|
||||
|
@ -126,7 +126,7 @@ return [
|
||||
/*
|
||||
* The adapter used to sync the laravel built-in locale
|
||||
*/
|
||||
'adapter' => \Xinax\LaravelGettext\Adapters\LaravelAdapter::class,
|
||||
'adapter' => \App\LaravelGettext\Adapters\LaravelAdapter::class,
|
||||
|
||||
/*
|
||||
* Where to store the current locale/domain
|
||||
@ -134,9 +134,9 @@ return [
|
||||
* By default, in the session.
|
||||
* Can be changed for only memory or your own storage mechanism
|
||||
*
|
||||
* @see \Xinax\LaravelGettext\Storages\Storage
|
||||
* @see \App\LaravelGettext\Storages\Storage
|
||||
*/
|
||||
'storage' => \Xinax\LaravelGettext\Storages\SessionStorage::class,
|
||||
'storage' => \App\LaravelGettext\Storages\SessionStorage::class,
|
||||
|
||||
/*
|
||||
* Use custom locale that is not supported by the system
|
||||
@ -150,7 +150,7 @@ return [
|
||||
* The "_n" and "ngettext" are plural translation functions
|
||||
* The "dgettext" function allows a translation domain to be explicitly specified
|
||||
*
|
||||
* "__" and "_n" and "_i" and "_s" are helpers functions @see \Xinax\LaravelGettext\Support\helpers.php
|
||||
* "__" and "_n" and "_i" and "_s" are helpers functions @see \App\LaravelGettext\Support\helpers.php
|
||||
*/
|
||||
'keywords-list' => ['_', '__', '_i', '_s', 'gettext', '_n:1,2', 'ngettext:1,2', 'dgettext:2', 'tr'],
|
||||
];
|
||||
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
/*
|
||||
* Set trusted proxy IP addresses.
|
||||
*
|
||||
* Both IPv4 and IPv6 addresses are
|
||||
* supported, along with CIDR notation.
|
||||
*
|
||||
* The "*" character is syntactic sugar
|
||||
* within TrustedProxy to trust any proxy
|
||||
* that connects directly to your server,
|
||||
* a requirement when you cannot know the address
|
||||
* of your proxy (e.g. if using ELB or similar).
|
||||
*
|
||||
*/
|
||||
'proxies' => null, // [<ip addresses>,], '*', '<ip addresses>,'
|
||||
|
||||
/*
|
||||
* To trust one or more specific proxies that connect
|
||||
* directly to your server, use an array or a string separated by comma of IP addresses:
|
||||
*/
|
||||
// 'proxies' => ['192.168.1.1'],
|
||||
// 'proxies' => '192.168.1.1, 192.168.1.2',
|
||||
|
||||
/*
|
||||
* Or, to trust all proxies that connect
|
||||
* directly to your server, use a "*"
|
||||
*/
|
||||
// 'proxies' => '*',
|
||||
|
||||
/*
|
||||
* Which headers to use to detect proxy related data (For, Host, Proto, Port)
|
||||
*
|
||||
* Options include:
|
||||
*
|
||||
* - Illuminate\Http\Request::HEADER_X_FORWARDED_ALL (use all x-forwarded-* headers to establish trust)
|
||||
* - Illuminate\Http\Request::HEADER_FORWARDED (use the FORWARDED header to establish trust)
|
||||
* - Illuminate\Http\Request::HEADER_X_FORWARDED_AWS_ELB (If you are using AWS Elastic Load Balancer)
|
||||
*
|
||||
* - 'HEADER_X_FORWARDED_ALL' (use all x-forwarded-* headers to establish trust)
|
||||
* - 'HEADER_FORWARDED' (use the FORWARDED header to establish trust)
|
||||
* - 'HEADER_X_FORWARDED_AWS_ELB' (If you are using AWS Elastic Load Balancer)
|
||||
*
|
||||
* @link https://symfony.com/doc/current/deployment/proxies.html
|
||||
*/
|
||||
'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,
|
||||
];
|
@ -1 +0,0 @@
|
||||
Deny from all
|
@ -13,7 +13,7 @@
|
||||
"keywords": ["Laravel", "Aggiornamenti"],
|
||||
"require": {
|
||||
"erusev/parsedown": "^1.7",
|
||||
"illuminate/support": "~7|~8"
|
||||
"illuminate/support": "~9"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~9.0",
|
||||
|
@ -12,7 +12,7 @@
|
||||
"homepage": "https://github.com/devcode-it/causali-trasporto",
|
||||
"keywords": ["Laravel", "CausaliTrasporto"],
|
||||
"require": {
|
||||
"illuminate/support": "~7|~8"
|
||||
"illuminate/support": "~9"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~9.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user