Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinhPhan96 committed Jan 17, 2020
0 parents commit aa528bf
Show file tree
Hide file tree
Showing 19 changed files with 592 additions and 0 deletions.
1 change: 1 addition & 0 deletions .styleci.yml
@@ -0,0 +1 @@
preset: laravel
8 changes: 8 additions & 0 deletions changelog.md
@@ -0,0 +1,8 @@
# Changelog

All notable changes to `Translate` will be documented in this file.

## Version 1.0

### Added
- Everything
43 changes: 43 additions & 0 deletions 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"
}
}
}
}
5 changes: 5 additions & 0 deletions config/translate.php
@@ -0,0 +1,5 @@
<?php

return [
//
];
27 changes: 27 additions & 0 deletions contributing.md
@@ -0,0 +1,27 @@
# Contributing

Contributions are welcome and will be fully credited.

Contributions are accepted via Pull Requests on [Github](https://github.com/thinhpd/translate).

# Things you could do
If you want to contribute but do not know where to start, this list provides some starting points.
- Add license text
- Remove rewriteRules.php
- Set up TravisCI, StyleCI, ScrutinizerCI
- Write a comprehensive ReadMe

## Pull Requests

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.


**Happy coding**!
5 changes: 5 additions & 0 deletions license.md
@@ -0,0 +1,5 @@
# The license

Copyright (c) author name <author email>

...Add your license text here...
22 changes: 22 additions & 0 deletions phpunit.xml
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Package">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src/</directory>
</whitelist>
</filter>
</phpunit>
30 changes: 30 additions & 0 deletions 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');
```
18 changes: 18 additions & 0 deletions src/Facades/Translate.php
@@ -0,0 +1,18 @@
<?php

namespace Thinhpd\Translate\Facades;

use Illuminate\Support\Facades\Facade;

class Translate extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'translate';
}
}
8 changes: 8 additions & 0 deletions src/Translate.php
@@ -0,0 +1,8 @@
<?php

namespace Thinhpd\Translate;

class Translate
{
// Build wonderful things
}
90 changes: 90 additions & 0 deletions src/TranslateServiceProvider.php
@@ -0,0 +1,90 @@
<?php

namespace Thinhpd\Translate;

use Illuminate\Support\ServiceProvider;

class TranslateServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
// $this->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([]);
}
}
23 changes: 23 additions & 0 deletions src/app/Http/Controllers/LangController.php
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\App;

class LangController extends Controller
{
private $langActive = [
'vi',
'en',
];
public function changeLang(Request $request, $lang)
{
if (in_array($lang, $this->langActive)) {
$request->session()->put(['lang' => $lang]);
return redirect()->back();
}
}
}
25 changes: 25 additions & 0 deletions src/app/Http/Middleware/Localization.php
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;

class Localization
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($lang = $request->session()->get('lang')) {
\App::setLocale($lang);
}
return $next($request);
}
}
71 changes: 71 additions & 0 deletions src/resources/lang/vi/auth.php
@@ -0,0 +1,71 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Authentication Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used during authentication for various
| messages that we need to display to the user. You are free to modify
| these language lines according to your application's requirements.
|
*/

'failed' => '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',
],
];

0 comments on commit aa528bf

Please sign in to comment.