Skip to content

Commit

Permalink
Merge pull request #5 from laravel-taiwan/1.x
Browse files Browse the repository at this point in the history
Upgrade to PHP 5.5+ and Laravel 5+
  • Loading branch information
flamerecca authored Oct 12, 2022
2 parents fd7487f + c5af2bd commit 3faa4e6
Show file tree
Hide file tree
Showing 11 changed files with 19,186 additions and 19,174 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
composer.lock
.phpunit.result.cache
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@ Laravel 繁簡轉換

# 安裝方式

1. 在 composer.json中加入 "seta0909/laravel-zhconverter": "*"
2. composer update
3. 在 config/app.php 中加入 'Seta0909\LaravelZhconverter\LaravelZhconverterServiceProvider'
1. 新增套件

```bash
composer require seta0909/laravel-zhconverter
```

2.`config/app.php` 中加入 Provider

```
Seta0909\LaravelZhconverter\LaravelZhconverterServiceProvider
```

# 使用方式

###簡轉繁
簡轉繁:

```
ZhConvert::translate('无疑,这个村子弥漫着一种懒散而颓废的感觉>,这种感觉让我觉得非常的难受,比曾经我见过的那个无限轮回的死村还难受,毕竟无限轮回还有破除的消,这村子里的这种气氛无疑就是一种绝望','TW');
```

繁轉簡:

###繁轉簡
```
ZhConvert::translate('我是一個不大會拒絕人的人,看著這個中年人>,或者是老年人吧,我覺得幾根兒煙也無可厚非,于是我把剩下的半包全部給了他,他接過煙,嘿嘿一笑,也不說聲謝謝,轉身就要走','CN');
```

# 注意事項

1. 目前只支援UTF-8
目前只支援 UTF-8

# 資料來源

繁簡字來源:http://www.mediawiki.org/wiki/MediaWiki
繁簡字來源: http://www.mediawiki.org/wiki/MediaWiki
18 changes: 15 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "4.2.*"
"php": "^5.5 | ^7.0 | ^8.0",
"illuminate/support": "^5 | ^6 | ^7 | ^8 | ^9"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.7",
"phpunit/phpunit": "^5 | ^6 | ^7 | ^8 | ^9"
},
"autoload": {
"psr-0": {
"Seta0909\\LaravelZhconverter\\": "src/"
}
},
"minimum-stability": "stable"
"minimum-stability": "stable",
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": false
}
}
}
18 changes: 18 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<ruleset>
<!-- display progress and sniff -->
<arg value="p"/>
<arg value="s"/>

<!-- use colors in output -->
<arg name="colors"/>

<!-- check the php syntax -->
<rule ref="Generic.PHP.Syntax"/>

<!-- inherit rules from: -->
<rule ref="PSR12"/>

<!-- Paths and file to check -->
<file>src</file>
</ruleset>
18 changes: 0 additions & 18 deletions phpunit.xml

This file was deleted.

13 changes: 13 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
>
<testsuites>
<testsuite name="Unit">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
13 changes: 8 additions & 5 deletions src/Seta0909/LaravelZhconverter/Facades/LaravelZhconverter.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php namespace Seta0909\LaravelZhconverter\Facades;
<?php

namespace Seta0909\LaravelZhconverter\Facades;

use Illuminate\Support\Facades\Facade;

class LaravelZhconverter extends Facade
{

/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'ZhConvert'; }

}
protected static function getFacadeAccessor()
{
return 'ZhConvert';
}
}
52 changes: 18 additions & 34 deletions src/Seta0909/LaravelZhconverter/LaravelZhconverter.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
<?php
namespace Seta0909\LaravelZhconverter;

/**
* Created by PhpStorm.
* User: Seta
* Date: 2015/1/19
* Time: 上午 09:45
*/
namespace Seta0909\LaravelZhconverter;

class LaravelZhconverter
class LaravelZhconverter
{
public static function translate($words, $type)
{
private static $instance;
protected static $cnCode = [];
protected static $twCode = [];
$translated = '';

private static function getInstance()
{
if (!isset(self::$instance)) {
require('ZhConversion.php');
$class = __CLASS__;
self::$instance = new $class();
self::$cnCode = $zh2Hant;
self::$twCode = $zh2Hans;
for ($i = 0; $i < mb_strlen($words); $i++) {
$word = mb_substr($words, $i, 1, "utf-8");
if ($type == 'CN') {
$translated .= isset(ZhConversion::$zh2Hans[$word])
? ZhConversion::$zh2Hans[$word]
: $word;
} else {
$translated .= isset(ZhConversion::$zh2Hant[$word])
? ZhConversion::$zh2Hant[$word]
: $word;
}
}

public static function translate($words, $type)
{
self::getInstance();
$translated = '';
for ($i = 0; $i < mb_strlen($words); $i++) {
$word = mb_substr($words, $i, 1, "utf-8");
if ($type == 'CN') {
$translated .= (isset(self::$twCode[$word])) ? self::$twCode[$word] : $word;
} else {
$translated .= (isset(self::$cnCode[$word])) ? self::$cnCode[$word] : $word;
}
}
return $translated;
}
}
return $translated;
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,15 @@
<?php namespace Seta0909\LaravelZhconverter;
<?php

namespace Seta0909\LaravelZhconverter;

use Illuminate\Support\ServiceProvider;

class LaravelZhconverterServiceProvider 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->package('seta0909/laravel-zhconverter');
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['ZhConvert'] = $this->app->share(function ($app) {
return new LaravelZhconverter;
});
$this->app->booting(function () {
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('ZhConvert', 'Seta0909\LaravelZhconverter\Facades\LaravelZhconverter');
$this->app->singleton(LaravelZhconverter::class, function () {
return new LaravelZhconverter();
});
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('ZhConvert');
}

}
Loading

0 comments on commit 3faa4e6

Please sign in to comment.