浏览代码

wrap getLanguage call with try/catch and fallback to en default

tags/0.9.4
itismadness 4 年前
父节点
当前提交
afb9fc8a4f
共有 1 个文件被更改,包括 17 次插入11 次删除
  1. +17
    -11
      src/Logchecker.php

+ 17
- 11
src/Logchecker.php 查看文件

@@ -3,6 +3,7 @@
namespace OrpheusNET\Logchecker;

use OrpheusNET\Logchecker\Check\Ripper;
use OrpheusNET\Logchecker\Exception\UnknownLanguageException;
use OrpheusNET\Logchecker\Exception\UnknownRipperException;
use OrpheusNET\Logchecker\Parser\EAC\Translator;
use Symfony\Component\Yaml\Yaml;
@@ -366,17 +367,22 @@ class Logchecker
{
if ($this->ripper === Ripper::EAC) {
$translator = new Translator();
$lang = $translator->getLanguage($this->log);
if ($lang['code'] !== 'en') {
$this->language = $lang['code'];
$this->account(
"Translated log from {$lang['name']} ({$lang['name_english']}) to English.",
false,
false,
false,
true
);
$this->log = $translator->translate($this->log, $lang['code']);
try {
$lang = $translator->getLanguage($this->log);
if ($lang['code'] !== 'en') {
$this->language = $lang['code'];
$this->account(
"Translated log from {$lang['name']} ({$lang['name_english']}) to English.",
false,
false,
false,
true
);
$this->log = $translator->translate($this->log, $lang['code']);
}
} catch (UnknownLanguageException $exc) {
$this->language = 'en';
$this->account('Could not determine language. Assuming English.', false, false, false, true);
}
}



正在加载...
取消
保存