重构项目,增加多语言支持。
parent
dd54bbff45
commit
d14fb19829
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "ChineseConvertor",
|
||||
"author": "hyperzlib",
|
||||
"url": "https://github.com/Isekai-Project/mediawiki-extension-LatinizeUrl",
|
||||
"descriptionmsg": "latinizeurl-chinese-convertor-desc",
|
||||
"version": "1.0.1",
|
||||
"license-name": "MIT",
|
||||
"type": "other",
|
||||
"MessagesDirs": {
|
||||
"ChineseConvertor": [
|
||||
"i18n"
|
||||
]
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"LatinizeUrl\\ChineseConvertor": "ChineseConvertor.php"
|
||||
},
|
||||
"Hooks": {
|
||||
"LatinizeUrlGetConvertor": [
|
||||
"LatinizeUrl\\ChineseConvertor::onGetConvertor"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"LatinizeUrlChineseConvertorConfig": {
|
||||
"parser": "inner"
|
||||
}
|
||||
},
|
||||
"manifest_version": 1
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/* Only support api parse yet */
|
||||
namespace LatinizeUrl;
|
||||
|
||||
use Exception;
|
||||
use MediaWiki\Http\HttpRequestFactory;
|
||||
|
||||
class JapaneseConvertor extends BaseConvertor {
|
||||
private $config;
|
||||
private static $standalone = null;
|
||||
|
||||
public static function standalone(){
|
||||
if(!self::$standalone){
|
||||
global $wgLatinizeUrlJapaneseConvertorConfig;
|
||||
self::$standalone = new self($wgLatinizeUrlJapaneseConvertorConfig);
|
||||
}
|
||||
return self::$standalone;
|
||||
}
|
||||
|
||||
public static function onGetConvertor($langCode, &$convertor){
|
||||
if(in_array($langCode, ['ja', 'ja-jp'])){
|
||||
$convertor = self::standalone();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __construct($config){
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function parse($kanji){
|
||||
if(!isset($this->config['url'])){
|
||||
throw new Exception('LatinizeUrl remote api url not set.');
|
||||
}
|
||||
$factory = new HttpRequestFactory();
|
||||
$req = $factory->create($this->config['url'], [
|
||||
'method' => 'POST',
|
||||
'postData' => [
|
||||
'sentence' => $kanji
|
||||
],
|
||||
], __METHOD__);
|
||||
$status = \Status::wrap($req->execute());
|
||||
if(!$status->isOK()){
|
||||
throw new Exception('Cannot use LatinizeUrl remote api.');
|
||||
}
|
||||
$json = \FormatJson::decode($req->getContent(), true);
|
||||
if(isset($json["error"])){
|
||||
throw new Exception('LatinizeUrl remote api error: ' . $json["error"]);
|
||||
}
|
||||
if(!isset($json["status"]) || $json["status"] !== 1){
|
||||
throw new Exception('Cannot use LatinizeUrl remote api.');
|
||||
}
|
||||
return $json["data"];
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "JapaneseConvertor",
|
||||
"author": "hyperzlib",
|
||||
"url": "https://github.com/Isekai-Project/mediawiki-extension-LatinizeUrl",
|
||||
"descriptionmsg": "latinizeurl-japanese-convertor-desc",
|
||||
"version": "1.0.1",
|
||||
"license-name": "MIT",
|
||||
"type": "other",
|
||||
"MessagesDirs": {
|
||||
"JapaneseConvertor": [
|
||||
"i18n"
|
||||
]
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"LatinizeUrl\\JapaneseConvertor": "JapaneseConvertor.php"
|
||||
},
|
||||
"Hooks": {
|
||||
"LatinizeUrlGetConvertor": [
|
||||
"LatinizeUrl\\JapaneseConvertor::onGetConvertor"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"LatinizeUrlJapaneseonvertorConfig": {
|
||||
"parser": "remote"
|
||||
}
|
||||
},
|
||||
"manifest_version": 1
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"latinizeurl-desc": "Latinize none-ASCII chars in url.",
|
||||
"latinizeurl-customurl": "Custom URL",
|
||||
"customurl-legend": "Custom URL",
|
||||
"customurl-url-field-label": "The URL you want to use:",
|
||||
"customurl-url-field-help": "Recommand using ASCII chars. If empty, will convert automatically to ASCII.",
|
||||
"customurl-set-success": "The URL of this page has been set to [[$1|$2]].",
|
||||
"customurl-set-failed": "This URL is invalid."
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"latinizeurl-desc": "한자를 로마자 변환하는 도구.",
|
||||
"latinizeurl-customurl": "URL을 편집",
|
||||
"customurl-legend": "URL을 편집",
|
||||
"customurl-url-field-label": "사용하고자하는 URL :",
|
||||
"customurl-url-field-help": "ASCII 문자를 권장합니다. 입력하지 않으면, 한자에 대응하는 로마자 자동으로 생성됩니다.",
|
||||
"customurl-set-success": "이 페이지의 새로운 URL은 [[$1|$2]].",
|
||||
"customurl-set-failed": "이 URL이 잘못되었습니다."
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace LatinizeUrl;
|
||||
|
||||
abstract class BaseConvertor {
|
||||
abstract public function parse($words);
|
||||
}
|
Loading…
Reference in New Issue