fix: 忽略更多字符

This commit is contained in:
Zhicheng Wang 2018-03-07 08:48:31 +08:00
parent 4ddf7348a4
commit 151d8824ee
3 changed files with 9 additions and 6 deletions

View File

@ -47,9 +47,9 @@ describe('从对照翻译文件中采集生成字典', () => {
it('从真实的文件中采集(测试)', function () { it('从真实的文件中采集(测试)', function () {
const fs = require('fs'); const fs = require('fs');
const content = fs.readFileSync(dirs.content + 'guide/ajs-quick-reference.md', 'utf-8'); const content = fs.readFileSync(dirs.content + 'guide/forms.md', 'utf-8');
const result = gatherTranslations(content); const result = gatherTranslations(content);
expect(result).eql({original: '# Forms', translation: '# 表单'}); expect(result[0]).eql({original: '# Forms', translation: '# 表单'});
}); });
it('递归查找所有 markdown 文件', function () { it('递归查找所有 markdown 文件', function () {

View File

@ -1,11 +1,10 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { dirs } from './dirs'; import { kernelText, lookup } from './translate';
import { kernelText, lookup, translateDirectory, translateFile } from './translate';
describe('根据字典进行翻译', () => { describe('根据字典进行翻译', () => {
it('抽取核心字符', function () { it('抽取核心字符', function () {
expect(kernelText(' # Forms ABC ')).eql('# Forms ABC'); expect(kernelText(' # Forms ABC. ')).eql('FormsABC');
}); });
it('查字典', () => { it('查字典', () => {

View File

@ -15,7 +15,11 @@ export function lookup(english: string, filename: RegExp = /.*/): DictEntry[] {
} }
export function kernelText(text: string): string { export function kernelText(text: string): string {
return text.replace(/[\s\n]+/g, ' ').trim(); return text
.replace(/[\s\n]+/g, '')
.replace(/^#+/g, '')
.replace(/\.$/g, '')
.trim();
} }
export function translate(content: string): string[] { export function translate(content: string): string[] {