From 3e45f28346002c49d91b8749c670294f692d0467 Mon Sep 17 00:00:00 2001 From: farid saravi Date: Thu, 6 Aug 2020 21:32:32 +0430 Subject: [PATCH] feat: add translate package --- composer.json | 1 + composer.lock | 114 ++++++++++++++++++++++++++++--- config/translatable.php | 148 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 255 insertions(+), 8 deletions(-) create mode 100644 config/translatable.php diff --git a/composer.json b/composer.json index adb1df0..ecc3613 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "license": "MIT", "require": { "php": "^7.2", + "astrotomic/laravel-translatable": "^11.8", "coraxster/flysystem-aws-s3-v3-minio": "^1.0", "fideloper/proxy": "^4.0", "kalnoy/nestedset": "^5.0", diff --git a/composer.lock b/composer.lock index c89c3e6..ccba472 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,87 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c41e87ebe57c9f47a0c594757501d667", + "content-hash": "33b920bcb91c0553dd5f2a2920690079", "packages": [ + { + "name": "astrotomic/laravel-translatable", + "version": "v11.8.3", + "source": { + "type": "git", + "url": "https://github.com/Astrotomic/laravel-translatable.git", + "reference": "104f9501bf94738b6d82984685010e3d8040e891" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Astrotomic/laravel-translatable/zipball/104f9501bf94738b6d82984685010e3d8040e891", + "reference": "104f9501bf94738b6d82984685010e3d8040e891", + "shasum": "" + }, + "require": { + "illuminate/contracts": "5.8.* || ^6.0 || ^7.0", + "illuminate/database": "5.8.* || ^6.0 || ^7.0", + "illuminate/support": "5.8.* || ^6.0 || ^7.0", + "php": ">=7.2" + }, + "require-dev": { + "orchestra/testbench": "3.8.* || ^4.0 || ^5.0", + "phpunit/phpunit": "^8.0 || ^9.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Astrotomic\\Translatable\\TranslatableServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Astrotomic\\Translatable\\": "src/Translatable/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tom Witkowski", + "email": "gummibeer@astrotomic.info", + "homepage": "https://gummibeer.de", + "role": "Developer" + }, + { + "name": "Dimitrios Savvopoulos", + "email": "ds@dimsav.com", + "homepage": "http://dimsav.com", + "role": "Developer" + } + ], + "description": "A Laravel package for multilingual models", + "homepage": "https://astrotomic.info", + "keywords": [ + "database", + "language", + "laravel", + "translation" + ], + "funding": [ + { + "url": "https://offset.earth/treeware", + "type": "custom" + }, + { + "url": "https://github.com/Gummibeer", + "type": "github" + }, + { + "url": "https://issuehunt.io/r/astrotomic", + "type": "issuehunt" + } + ], + "time": "2020-07-08T17:21:18+00:00" + }, { "name": "aws/aws-sdk-php", "version": "3.134.3", @@ -4886,7 +4965,10 @@ "license": [ "MIT" ], - "description": "blog management" + "description": "blog management", + "transport-options": { + "relative": true + } }, { "name": "wm/common", @@ -4929,7 +5011,10 @@ "license": [ "MIT" ], - "description": "manage common information in willamall" + "description": "manage common information in willamall", + "transport-options": { + "relative": true + } }, { "name": "wm/core", @@ -4974,7 +5059,10 @@ "license": [ "MIT" ], - "description": "client relationship management" + "description": "client relationship management", + "transport-options": { + "relative": true + } }, { "name": "wm/crm", @@ -5018,7 +5106,10 @@ "license": [ "MIT" ], - "description": "client relationship management" + "description": "client relationship management", + "transport-options": { + "relative": true + } }, { "name": "wm/portfolio", @@ -5060,7 +5151,10 @@ "license": [ "MIT" ], - "description": "Portfolio management" + "description": "Portfolio management", + "transport-options": { + "relative": true + } }, { "name": "wm/reservation", @@ -5100,7 +5194,10 @@ "license": [ "MIT" ], - "description": "add reservation system to willamall" + "description": "add reservation system to willamall", + "transport-options": { + "relative": true + } }, { "name": "zendframework/zend-diactoros", @@ -7234,5 +7331,6 @@ "platform": { "php": "^7.2" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } diff --git a/config/translatable.php b/config/translatable.php new file mode 100644 index 0000000..be62d78 --- /dev/null +++ b/config/translatable.php @@ -0,0 +1,148 @@ + [ + Language::PERSIAN, + Language::ENGLISH, + Language::ARABIC, + ], + + /* + |-------------------------------------------------------------------------- + | Locale separator + |-------------------------------------------------------------------------- + | + | This is a string used to glue the language and the country when defining + | the available locales. Example: if set to '-', then the locale for + | colombian spanish will be saved as 'es-CO' into the database. + | + */ + 'locale_separator' => '-', + + /* + |-------------------------------------------------------------------------- + | Default locale + |-------------------------------------------------------------------------- + | + | As a default locale, Translatable takes the locale of Laravel's + | translator. If for some reason you want to override this, + | you can specify what default should be used here. + | If you set a value here it will only use the current config value + | and never fallback to the translator one. + | + */ + 'locale' => Language::PERSIAN, + + /* + |-------------------------------------------------------------------------- + | Use fallback + |-------------------------------------------------------------------------- + | + | Determine if fallback locales are returned by default or not. To add + | more flexibility and configure this option per "translatable" + | instance, this value will be overridden by the property + | $useTranslationFallback when defined + | + */ + 'use_fallback' => false, + + /* + |-------------------------------------------------------------------------- + | Use fallback per property + |-------------------------------------------------------------------------- + | + | The property fallback feature will return the translated value of + | the fallback locale if the property is empty for the selected + | locale. Note that 'use_fallback' must be enabled. + | + */ + 'use_property_fallback' => true, + + /* + |-------------------------------------------------------------------------- + | Fallback Locale + |-------------------------------------------------------------------------- + | + | A fallback locale is the locale being used to return a translation + | when the requested translation is not existing. To disable it + | set it to false. + | If set to null it will loop through all configured locales until + | one existing is found or end of list reached. The locales are looped + | from top to bottom and for country based locales the simple one + | is used first. So "es" will be checked before "es_MX". + | + */ + 'fallback_locale' => 'en', + + /* + |-------------------------------------------------------------------------- + | Translation Model Namespace + |-------------------------------------------------------------------------- + | + | Defines the default 'Translation' class namespace. For example, if + | you want to use App\Translations\CountryTranslation instead of App\CountryTranslation + | set this to 'App\Translations'. + | + */ + 'translation_model_namespace' => null, + + /* + |-------------------------------------------------------------------------- + | Translation Suffix + |-------------------------------------------------------------------------- + | + | Defines the default 'Translation' class suffix. For example, if + | you want to use CountryTrans instead of CountryTranslation + | application, set this to 'Trans'. + | + */ + 'translation_suffix' => 'Translation', + + /* + |-------------------------------------------------------------------------- + | Locale key + |-------------------------------------------------------------------------- + | + | Defines the 'locale' field name, which is used by the + | translation model. + | + */ + 'locale_key' => 'language_id', + + /* + |-------------------------------------------------------------------------- + | Always load translations when converting to array + |-------------------------------------------------------------------------- + | Setting this to false will have a performance improvement but will + | not return the translations when using toArray(), unless the + | translations relationship is already loaded. + | + */ + 'to_array_always_loads_translations' => true, + + /* + |-------------------------------------------------------------------------- + | Configure the default behavior of the rule factory + |-------------------------------------------------------------------------- + | The default values used to control the behavior of the RuleFactory. + | Here you can set your own default format and delimiters for + | your whole app. + * + */ + 'rule_factory' => [ + 'format' => \Astrotomic\Translatable\Validation\RuleFactory::FORMAT_ARRAY, + 'prefix' => '%', + 'suffix' => '%', + ], +];