From aa528bf5d573401ef18485eb19467e66ba5287d8 Mon Sep 17 00:00:00 2001 From: ThinhPhan Date: Fri, 17 Jan 2020 08:28:42 +0700 Subject: [PATCH] first commit --- .styleci.yml | 1 + changelog.md | 8 ++ composer.json | 43 ++++++ config/translate.php | 5 + contributing.md | 27 ++++ license.md | 5 + phpunit.xml | 22 +++ readme.md | 30 ++++ src/Facades/Translate.php | 18 +++ src/Translate.php | 8 ++ src/TranslateServiceProvider.php | 90 ++++++++++++ src/app/Http/Controllers/LangController.php | 23 +++ src/app/Http/Middleware/Localization.php | 25 ++++ src/resources/lang/vi/auth.php | 71 ++++++++++ src/resources/lang/vi/crud.php | 17 +++ src/resources/lang/vi/messages.php | 11 ++ src/resources/lang/vi/pagination.php | 19 +++ src/resources/lang/vi/passwords.php | 22 +++ src/resources/lang/vi/validation.php | 147 ++++++++++++++++++++ 19 files changed, 592 insertions(+) create mode 100644 .styleci.yml create mode 100644 changelog.md create mode 100644 composer.json create mode 100644 config/translate.php create mode 100644 contributing.md create mode 100644 license.md create mode 100644 phpunit.xml create mode 100644 readme.md create mode 100644 src/Facades/Translate.php create mode 100644 src/Translate.php create mode 100644 src/TranslateServiceProvider.php create mode 100644 src/app/Http/Controllers/LangController.php create mode 100644 src/app/Http/Middleware/Localization.php create mode 100644 src/resources/lang/vi/auth.php create mode 100644 src/resources/lang/vi/crud.php create mode 100644 src/resources/lang/vi/messages.php create mode 100644 src/resources/lang/vi/pagination.php create mode 100644 src/resources/lang/vi/passwords.php create mode 100644 src/resources/lang/vi/validation.php diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..c3bb259 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: laravel \ No newline at end of file diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..3e12bb8 --- /dev/null +++ b/changelog.md @@ -0,0 +1,8 @@ +# Changelog + +All notable changes to `Translate` will be documented in this file. + +## Version 1.0 + +### Added +- Everything diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..91ce698 --- /dev/null +++ b/composer.json @@ -0,0 +1,43 @@ +{ + "name": "thinhpd/translate", + "description": ":package_description", + "license": "license", + "authors": [ + { + "name": "author name", + "email": "author email", + "homepage": "author homepage" + } + ], + "homepage": "https://github.com/thinhpd/translate", + "keywords": ["Laravel", "Translate"], + "require": { + "illuminate/support": "~5|~6" + }, + "require-dev": { + "phpunit/phpunit": "^8.0", + "mockery/mockery": "^1.1", + "orchestra/testbench": "~3|~4", + "sempro/phpunit-pretty-print": "^1.0" + }, + "autoload": { + "psr-4": { + "Thinhpd\\Translate\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Thinhpd\\Translate\\Tests\\": "tests" + } + }, + "extra": { + "laravel": { + "providers": [ + "Thinhpd\\Translate\\TranslateServiceProvider" + ], + "aliases": { + "Translate": "Thinhpd\\Translate\\Facades\\Translate" + } + } + } +} diff --git a/config/translate.php b/config/translate.php new file mode 100644 index 0000000..035fcd5 --- /dev/null +++ b/config/translate.php @@ -0,0 +1,5 @@ + + +...Add your license text here... \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..ce34605 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,22 @@ + + + + + ./tests/ + + + + + src/ + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e8fffec --- /dev/null +++ b/readme.md @@ -0,0 +1,30 @@ +# Translate + +[![Latest Version on Packagist][ico-version]][link-packagist] +[![Total Downloads][ico-downloads]][link-downloads] +[![Build Status][ico-travis]][link-travis] +[![StyleCI][ico-styleci]][link-styleci] + +This is where your description should go. Take a look at [contributing.md](contributing.md) to see a to do list. + +## Installation + +Via Composer + +``` bash +$ composer require thinhpd/translate +``` +Run command +``` bash +php artisan vendor:publish --provider="Thinhpd\Translate\TranslateServiceProvider" +``` + +Add code in Kernel in $middlewareGroups web +``` bash +\App\Http\Middleware\Localization::class, +``` + +Add route in routes/web.php +``` bash +Route::get('lang/{lang}', 'LangController@changeLang')->name('lang'); +``` \ No newline at end of file diff --git a/src/Facades/Translate.php b/src/Facades/Translate.php new file mode 100644 index 0000000..9f95aa7 --- /dev/null +++ b/src/Facades/Translate.php @@ -0,0 +1,18 @@ +loadTranslationsFrom(__DIR__.'/../resources/lang', 'thinhpd'); + // $this->loadViewsFrom(__DIR__.'/../resources/views', 'thinhpd'); + // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + // $this->loadRoutesFrom(__DIR__.'/routes.php'); + + // Publishing is only necessary when using the CLI. + if ($this->app->runningInConsole()) { + $this->bootForConsole(); + } + } + + /** + * Register any package services. + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom(__DIR__.'/../config/translate.php', 'translate'); + + // Register the service the package provides. + $this->app->singleton('translate', function ($app) { + return new Translate; + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return ['translate']; + } + + /** + * Console-specific booting. + * + * @return void + */ + protected function bootForConsole() + { + // Publishing the configuration file. + $this->publishes([ + __DIR__.'/../config/translate.php' => config_path('translate.php'), + ], 'translate.config'); + + $this->publishes([ + __DIR__.'/../src/app' => base_path('app/'), + ], 'translate.app'); + + $this->publishes([ + __DIR__.'/../src/resources/lang' => resource_path('lang/'), + ], 'translate.lang'); + + // Publishing the views. + /*$this->publishes([ + __DIR__.'/../resources/views' => base_path('resources/views/vendor/thinhpd'), + ], 'translate.views');*/ + + // Publishing assets. + /*$this->publishes([ + __DIR__.'/../resources/assets' => public_path('vendor/thinhpd'), + ], 'translate.views');*/ + + // Publishing the translation files. + /*$this->publishes([ + __DIR__.'/../resources/lang' => resource_path('lang/vendor/thinhpd'), + ], 'translate.views');*/ + + // Registering package commands. + // $this->commands([]); + } +} diff --git a/src/app/Http/Controllers/LangController.php b/src/app/Http/Controllers/LangController.php new file mode 100644 index 0000000..8026149 --- /dev/null +++ b/src/app/Http/Controllers/LangController.php @@ -0,0 +1,23 @@ +langActive)) { + $request->session()->put(['lang' => $lang]); + return redirect()->back(); + } + } +} diff --git a/src/app/Http/Middleware/Localization.php b/src/app/Http/Middleware/Localization.php new file mode 100644 index 0000000..9483ac1 --- /dev/null +++ b/src/app/Http/Middleware/Localization.php @@ -0,0 +1,25 @@ +session()->get('lang')) { + \App::setLocale($lang); + } + return $next($request); + } +} diff --git a/src/resources/lang/vi/auth.php b/src/resources/lang/vi/auth.php new file mode 100644 index 0000000..9cdbed0 --- /dev/null +++ b/src/resources/lang/vi/auth.php @@ -0,0 +1,71 @@ + 'Tài khoản hoặc mật khẩu không đúng.', + 'throttle' => 'Quá nhiều lần thử đăng nhập. Vui lòng thử lại trong :seconds giây.', + + 'full_name' => 'Tên đầy đủ', + 'email' => 'Email', + 'password' => 'Mật khẩu', + 'confirm_password' => 'Xác nhận mật khẩu', + 'remember_me' => 'ghi nhớ', + 'sign_in' => 'Đăng nhập', + 'sign_out' => 'Đăng xuất', + 'register' => 'Đăng ký', + + 'login' => [ + 'title' => 'Đăng nhập để bắt đầu phiên của bạn', + 'forgot_password' => 'Tôi đã quên mật khẩu của mình', + 'register_membership' => 'Đăng ký thành viên mới', + ], + + 'registration' => [ + 'title' => 'Đăng ký thành viên mới', + 'i_agree' => 'Tôi đồng ý', + 'terms' => 'các điều khoản', + 'have_membership' => 'Tôi đã có thành viên', + ], + + 'forgot_password' => [ + 'title' => 'Nhập Email để đặt lại mật khẩu', + 'send_pwd_reset' => 'Gửi liên kết đặt lại mật khẩu', + ], + + 'reset_password' => [ + 'title' => 'Đặt lại mật khẩu của bạn', + 'reset_pwd_btn' => 'Đặt lại mật khẩu', + ], + + 'emails' => [ + 'password' => [ + 'reset_link' => 'Nhấn vào đây để đặt lại mật khẩu của bạn', + ], + ], + + 'app' => [ + 'member_since' => 'Thành viên từ', + 'messages' => 'Tin nhắn', + 'settings' => 'Cài đặt', + 'lock_account' => 'Khóa tài khoản', + 'profile' => 'Hồ sơ', + 'online' => 'Trực tuyến', + 'search' => 'Tìm kiếm', + 'create' => 'Tạo', + 'export' => 'Xuất', + 'print' => 'In', + 'reset' => 'Cài lại', + 'reload' => 'Tải lại', + ], +]; diff --git a/src/resources/lang/vi/crud.php b/src/resources/lang/vi/crud.php new file mode 100644 index 0000000..67a7325 --- /dev/null +++ b/src/resources/lang/vi/crud.php @@ -0,0 +1,17 @@ + 'Thêm mới', + 'cancel' => 'Hủy', + 'save' => 'Lưu', + 'edit' => 'Sửa', + 'detail' => 'Chi tiết', + 'back' => 'Quay lại', + 'action' => 'Hành động', + 'id' => 'Id', + 'created_at' => 'Ngày tạo', + 'updated_at' => 'Ngày cập nhật', + 'deleted_at' => 'Ngày xóa', + 'are_you_sure' => 'Bạn chắc chắn ?', +]; diff --git a/src/resources/lang/vi/messages.php b/src/resources/lang/vi/messages.php new file mode 100644 index 0000000..ced9db7 --- /dev/null +++ b/src/resources/lang/vi/messages.php @@ -0,0 +1,11 @@ + ':model đã lấy thành công.', + 'saved' => ':model đã lưu thành công.', + 'updated' => ':model đã cập nhật.', + 'deleted' => ':model đã xóa.', + 'not_found' => ':model không thấy', + +]; diff --git a/src/resources/lang/vi/pagination.php b/src/resources/lang/vi/pagination.php new file mode 100644 index 0000000..462d085 --- /dev/null +++ b/src/resources/lang/vi/pagination.php @@ -0,0 +1,19 @@ + '« Trước', + 'next' => 'Tiếp »', + +]; diff --git a/src/resources/lang/vi/passwords.php b/src/resources/lang/vi/passwords.php new file mode 100644 index 0000000..15af954 --- /dev/null +++ b/src/resources/lang/vi/passwords.php @@ -0,0 +1,22 @@ + 'Mật khẩu của bạn đã được thiết lập lại!', + 'sent' => 'Chúng tôi đã gửi email liên kết đặt lại mật khẩu của bạn!', + 'throttled' => 'Vui lòng đợi trước khi thử lại.', + 'token' => 'Mã thông báo đặt lại mật khẩu này không hợp lệ.', + 'user' => "Chúng tôi không thể tìm thấy người dùng có địa chỉ email đó.", + +]; diff --git a/src/resources/lang/vi/validation.php b/src/resources/lang/vi/validation.php new file mode 100644 index 0000000..5d30fcb --- /dev/null +++ b/src/resources/lang/vi/validation.php @@ -0,0 +1,147 @@ + 'Thông tin :attribute phải được chấp nhận.', + 'active_url' => 'Thông tin :attribute không phải là một URL hợp lệ.', + 'after' => 'Thông tin :attribute phải là một ngày sau :date.', + 'after_or_equal' => 'Thông tin :attribute phải là một ngày sau hoặc bằng :date.', + 'alpha' => 'Thông tin :attribute chỉ có thể chứa các chữ cái.', + 'alpha_dash' => 'Thông tin :attribute chỉ có thể chứa các chữ cái, số, dấu gạch ngang và dấu gạch dưới.', + 'alpha_num' => 'Thông tin :attribute chỉ có thể chứa các chữ cái và số.', + 'array' => 'Thông tin :attribute phải là một mảng.', + 'before' => 'Thông tin :attribute phải là một ngày trước :date.', + 'before_or_equal' => 'Thông tin :attribute phải là một ngày trước hoặc bằng :date.', + 'between' => [ + 'numeric' => 'Thông tin :attribute phải ở giữa :min và :max.', + 'file' => 'Thông tin :attribute phải ở giữa :min và :max kilobytes.', + 'string' => 'Thông tin :attribute phải ở giữa :min và :max ký tự.', + 'array' => 'Thông tin :attribute phải ở giữa :min và :max.', + ], + 'boolean' => 'Thông tin :attribute trường phải đúng hoặc sai.', + 'confirmed' => 'Thông tin :attribute nhận đinh không phù hợp.', + 'date' => 'Thông tin :attribute không phải là ngày hợp lệ.', + 'date_equals' => 'Thông tin :attribute phải là một ngày bằng :date.', + 'date_format' => 'Thông tin :attribute không phù hợp với định dạng :format.', + 'different' => 'Thông tin :attribute và :other phải khác nhau.', + 'digits' => 'Thông tin :attribute phải :digits chữ số.', + 'digits_between' => 'Thông tin :attribute phải ở giữa :min và :max chữ số.', + 'dimensions' => 'Thông tin :attribute có kích thước hình ảnh không hợp lệ.', + 'distinct' => 'Thông tin :attribute trường có giá trị trùng lặp.', + 'email' => 'Thông tin :attribute phải là một địa chỉ email hợp lệ.', + 'ends_with' => 'Thông tin :attribute phải kết thúc bằng một trong những điều sau đây: :values', + 'exists' => 'Thông tin :attribute không tồn tại.', + 'file' => 'Thông tin :attribute phải là một file.', + 'filled' => 'Thông tin :attribute trường phải có giá trị.', + 'gt' => [ + 'numeric' => 'Thông tin :attribute phải lớn hơn :value.', + 'file' => 'Thông tin :attribute phải lớn hơn :value kilobytes.', + 'string' => 'Thông tin :attribute phải lớn hơn :value ký tự.', + 'array' => 'Thông tin :attribute phải có nhiều hơn :value thành phần.', + ], + 'gte' => [ + 'numeric' => 'Thông tin :attribute phải lớn hơn hoặc bằng :value.', + 'file' => 'Thông tin :attribute phải lớn hơn hoặc bằng :value kilobytes.', + 'string' => 'Thông tin :attribute phải lớn hơn hoặc bằng :value ký tự.', + 'array' => 'Thông tin :attribute phải có :value hoặc nhiều hơn.', + ], + 'image' => 'Thông tin :attribute phải là một ảnh.', + 'in' => 'Thông tin :attribute sai.', + 'in_array' => 'Thông tin :attribute trường không có trong :other.', + 'integer' => 'Thông tin :attribute phải là một số.', + 'ip' => 'Thông tin :attribute phải là một giá trị IP địa chỉ.', + 'ipv4' => 'Thông tin :attribute phải là một giá trị IPv4 địa chỉ.', + 'ipv6' => 'Thông tin :attribute phải là một giá trị IPv6 địa chỉ.', + 'json' => 'Thông tin :attribute phải là một giá trị JSON chuỗi.', + 'lt' => [ + 'numeric' => 'Thông tin :attribute phải nhỏ hơn :value.', + 'file' => 'Thông tin :attribute phải nhỏ hơn :value kilobytes.', + 'string' => 'Thông tin :attribute phải nhỏ hơn :value ký tự.', + 'array' => 'Thông tin :attribute phải ít hơn :value thành phần.', + ], + 'lte' => [ + 'numeric' => 'Thông tin :attribute phải nhỏ hơn hoặc bằng :value.', + 'file' => 'Thông tin :attribute phải nhỏ hơn hoặc bằng :value kilobytes.', + 'string' => 'Thông tin :attribute phải nhỏ hơn hoặc bằng :value ký tự.', + 'array' => 'Thông tin :attribute không có nhiều hơn :value thành phần.', + ], + 'max' => [ + 'numeric' => 'Thông tin :attribute không thể lớn hơn :max.', + 'file' => 'Thông tin :attribute không thể lớn hơn :max kilobytes.', + 'string' => 'Thông tin :attribute không thể lớn hơn :max ký tự.', + 'array' => 'Thông tin :attribute không thể có nhiều hơn :max thành phần.', + ], + 'mimes' => 'Thông tin :attribute phải là một tập tin: :values.', + 'mimetypes' => 'Thông tin :attribute phải là một tập tin: :values.', + 'min' => [ + 'numeric' => 'Thông tin :attribute ít nhất phải lớn hơn :min.', + 'file' => 'Thông tin :attribute ít nhất phải lớn hơn :min kilobytes.', + 'string' => 'Thông tin :attribute ít nhất phải lớn hơn :min ký tự.', + 'array' => 'Thông tin :attribute phải có ít nhất phải lớn hơn:min thành phần.', + ], + 'not_in' => 'Thông tin selected :attribute phải hợp lệ.', + 'not_regex' => 'Thông tin :attribute định dạng phải hợp lệ.', + 'numeric' => 'Thông tin :attribute phải là một số.', + 'present' => 'Thông tin :attribute trường phải có mặt.', + 'regex' => 'Thông tin :attribute định dạng phải hợp lệ.', + 'required' => 'Thông tin :attribute không được để trống.', + 'required_if' => 'Thông tin :attribute trường phải có khi :other là :value.', + 'required_unless' => 'Thông tin :attribute trường phải có khi không có :other trong :values.', + 'required_with' => 'Thông tin :attribute trường phải có khi :values là có mặt.', + 'required_with_all' => 'Thông tin :attribute trường phải có khi :values là có mặt.', + 'required_without' => 'Thông tin :attribute trường phải có khi :values không có mặt.', + 'required_without_all' => 'Thông tin :attribute trường phải có khi không :values có mặt.', + 'same' => 'Thông tin :attribute và :other must match.', + 'size' => [ + 'numeric' => 'Thông tin :attribute phải là :size.', + 'file' => 'Thông tin :attribute phải là :size kilobytes.', + 'string' => 'Thông tin :attribute phải là :size ký tự.', + 'array' => 'Thông tin :attribute phải chứa :size thành phần.', + ], + 'starts_with' => 'Thông tin :attribute phải bắt đầu với một trong những điều sau đây: :values', + 'string' => 'Thông tin :attribute phải là một chuỗi.', + 'timezone' => 'Thông tin :attribute phải là một vùng.', + 'unique' => 'Thông tin :attribute đã tồn tại .', + 'uploaded' => 'Thông tin :attribute lỗi khi tải lên', + 'url' => 'Thông tin :attribute định dạng phải hợp lệ.', + 'uuid' => 'Thông tin :attribute phải là một giá trị UUID.', + + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ + 'custom' => [ + 'attribute-name' => [ + 'rule-name' => 'custom-message', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | the following language lines are used to swap our attribute placeholder + | with something more reader friendly such as "E-Mail Address" instead + | of "email". This simply helps us make our message more expressive. + | + */ + 'attributes' => [ + ], +];