Browse Source

add lang for zh

master
filesite 6 days ago
parent
commit
13da7c70c8
  1. 6
      i18n.mjs
  2. 39
      i18n/zh.json
  3. 2
      public/en-us/index.html
  4. 2
      public/index.html
  5. 2
      public/template/index.html
  6. 133
      public/zh/index.html
  7. 23
      test/i18n.test.mjs

6
i18n.mjs

@ -46,7 +46,7 @@ class I18N { @@ -46,7 +46,7 @@ class I18N {
const _self = this;
const langFiles = await _self.getLangFiles();
//console.log('Lang json files', langFiles);
console.log('Lang json files', langFiles);
if (langFiles && langFiles.length > 0) {
try {
@ -79,12 +79,12 @@ class I18N { @@ -79,12 +79,12 @@ class I18N {
//判断语言代码格式是否符合国际标准
isIosLangCode(lang) {
return /^[a-z]{2}(?:\-[a-z]{2})$/i.test(lang);
return /^[a-z]{2}(\-[a-z]{2})?$/i.test(lang);
}
//判断是否是语言包文件
isIosLangFile(filename) {
return /^[a-z]{2}(?:\-[a-z]{2})\.json$/i.test(filename);
return /^[a-z]{2}(\-[a-z]{2})?\.json$/i.test(filename);
}
//更新语言包文件内容,合并新的数据到已有内容中

39
i18n/zh.json

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
{
"HeroUnion - Open source web crawler union.": "HeroUnion - 开源网络爬虫联盟。",
"HeroUnion.website": "HeroUnion.website",
"HeroUnion<small> - Open source web crawler union</small>": "HeroUnion<small> - 开源网络爬虫联盟</small>",
"HeroUnion Stats": "HeroUnion状态",
"It's running": "正在运行",
"Tasks Stats": "任务状态",
"Last": "上次",
"Waiting": "等待中",
"Running": "正在运行",
"Total": "总计",
"Done": "已完成",
"Failed": "失败",
"Notify Stats": "通知状态",
"Bot Stats": "机器人状态",
"Idle": "空闲",
"Busy": "繁忙",
"Offline": "离线",
"JSON Data": "JSON数据",
"Covenant of the Alliance": "联盟盟约",
"Please abide by the following conventions and stick to it for a better tomorrow for yourself and the whole society!": "为了您自己和整个社会更美好的明天,请遵守以下约定并坚持下去!",
"Comply with local/national laws and regulations": "遵守当地/国家法律法规",
"Data that requires login or VIP status to access will not be crawled": "需要登录或VIP身份才能访问的数据将不会被抓取",
"Data that is explicitly prohibited from being collected by the target website will not be crawled": "目标网站明确禁止收集的数据将不会被抓取",
"The commercial core data of the target website is not crawled": "目标网站的商业核心数据将不会被抓取",
"Low concurrency, low frequency, does not affect the normal operation of the target website": "低并发、低频率,不影响目标网站的正常运行",
"Bots": "机器人",
"HeroUnion App": "HeroUnion App",
"HeroUnion download": "HeroUnion下载",
"HeroBot download": "HeroBot下载",
"HeroUnion<strong> is only responsible for the scheduling of crawlers and tasks</strong>.": "HeroUnion<strong>仅负责爬虫和任务的调度</strong>。",
"The contracts supported by crawlers and the specific content of tasks have nothing to do with the alliance.": "爬虫支持的合约及任务的具体内容与联盟无关。",
"Website monitor": "网站监控",
"Web Scraper": "网页爬虫",
"Disclaimer": "免责声明",
"Information protected by law will not be crawled": "受法律保护的信息将不会被抓取",
"for example": "例如",
"personal privacy data mobile phone number, ID number, etc.": "个人隐私数据、手机号码、身份证号码等。"
}

2
public/en-us/index.html

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width">
<title>HeroUnion - Open source web crawler union.</title>
<meta name="author" content="HeroUnion.website">
<meta name="description" content="{HeroUnion: Open source web crawler union.}">
<meta name="description" content="HeroUnion - Open source web crawler union.">
<style>
*,body{margin:0;padding:0}
body{padding:8px;max-width:640px;margin:0 auto}

2
public/index.html

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width">
<title>HeroUnion - Open source web crawler union.</title>
<meta name="author" content="HeroUnion.website">
<meta name="description" content="{HeroUnion: Open source web crawler union.}">
<meta name="description" content="HeroUnion - Open source web crawler union.">
<style>
*,body{margin:0;padding:0}
body{padding:8px;max-width:640px;margin:0 auto}

2
public/template/index.html

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width">
<title>{HeroUnion - Open source web crawler union.}</title>
<meta name="author" content="{HeroUnion.website}">
<meta name="description" content="{HeroUnion: Open source web crawler union.}">
<meta name="description" content="{HeroUnion - Open source web crawler union.}">
<style>
*,body{margin:0;padding:0}
body{padding:8px;max-width:640px;margin:0 auto}

133
public/zh/index.html

@ -1,12 +1,12 @@ @@ -1,12 +1,12 @@
<!doctype html>
<html class="no-js" lang="en-US">
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width">
<title>HeroUnion英雄联盟 - 开源网络爬虫联盟</title>
<meta name="author" content="filesite.io">
<meta name="description" content="HeroUnion简称英雄联盟,开源的网络爬虫联盟。">
<title>HeroUnion - 开源网络爬虫联盟</title>
<meta name="author" content="HeroUnion.website">
<meta name="description" content="HeroUnion - 开源网络爬虫联盟。">
<style>
*,body{margin:0;padding:0}
body{padding:8px;max-width:640px;margin:0 auto}
@ -37,23 +37,31 @@ @@ -37,23 +37,31 @@
.danger{background-color:red}
.disable{background-color:gray}
.langswitcher{position:relative}
.langswitcher button{padding:2px 4px;cursor:pointer}
.dropmenu{display:none;position:absolute;right:0;top:28px;padding:5px;width:80px;background-color:#FFF;border:1px solid #EEE}
.dropmenu li{list-style:none;padding:0;margin:3px 0;text-align:center}
@media(max-width:480px) {
h1 small{display:block}
}
</style>
</head>
<body>
<h1 class="text-center">HeroUnion英雄联盟<small> - 开源网络爬虫联盟</small></h1>
<h1 class="text-center">HeroUnion<small> - 开源网络爬虫联盟</small></h1>
<hr class="mt-d5">
<p class="text-right mt-d5">
<a href="/" class="mx-d2">English</a>
<a href="/zh/" class="mx-d2">简体中文</a>
</p>
<div class="text-right mt-d5 langswitcher">
<button data-status="closed">English</button>
<ul class="dropmenu">
<li><a href="/">English</a></li>
<li><a href="/zh/">简体中文</a></li>
</ul>
</div>
<h3 class="mt-2">HeroUnion联盟状态 - 已运行<span class="run_time">...</span></h3>
<h3 class="mt-2">HeroUnion状态 正在运行 <span class="run_time">...</span></h3>
<h4 class="mt-d5">任务状态(最近<span class="cache_time">...</span></h4>
<h4 class="mt-d5">任务状态 (上次 <span class="cache_time">...</span>)</h4>
<div class="stats taskStatus">
<span class="col info">
<strong class="waiting">...</strong>
@ -61,16 +69,16 @@ @@ -61,16 +69,16 @@
</span>
<span class="col warning">
<strong class="running">...</strong>
<label>执行中</label>
<label>正在运行</label>
</span>
<div>
<span class="col">
<strong class="total">...</strong>
<label></label>
<label></label>
</span>
<span class="col success">
<strong class="done">...</strong>
<label>完成</label>
<label>完成</label>
</span>
<span class="col danger">
<strong class="failed">...</strong>
@ -79,15 +87,15 @@ @@ -79,15 +87,15 @@
</div>
</div>
<h4 class="mt-d5">任务通知状态(最近<span class="cache_time">...</span></h4>
<h4 class="mt-d5">通知状态 (上次 <span class="cache_time">...</span>)</h4>
<div class="stats taskNotifyStatus">
<span class="col">
<strong class="total">...</strong>
<label></label>
<label></label>
</span>
<span class="col success">
<strong class="done">...</strong>
<label>完成</label>
<label>完成</label>
</span>
<span class="col danger">
<strong class="failed">...</strong>
@ -95,11 +103,11 @@ @@ -95,11 +103,11 @@
</span>
</div>
<h4 class="mt-d5">爬虫状态</h4>
<h4 class="mt-d5">机器人状态</h4>
<div class="stats heroStatus">
<span class="col">
<strong class="total">...</strong>
<label></label>
<label></label>
</span>
<span class="col success">
<strong class="idle">...</strong>
@ -118,70 +126,77 @@ @@ -118,70 +126,77 @@
<h4 class="mt-d5">JSON数据</h4>
<pre><code id="herounion_stats">...</code></pre>
<h3 class="mt-2">HeroUnion联盟公</h3>
<p class="mt-1">请大家遵守以下公约,为自己、也为全社会有更好的明天一起坚持</p>
<h3 class="mt-2">联盟盟</h3>
<p class="mt-1">为了您自己和整个社会更美好的明天,请遵守以下约定并坚持下去</p>
<ul class="mt-d5">
<li>遵守本地/本国法律、法规</li>
<li>受法律保护的信息不爬(例如:个人隐私数据手机号码、身份证号码等等)</li>
<li>需要登录,或需要VIP身份才能访问的数据不爬</li>
<li>目标网站明确禁止采集的数据不爬</li>
<li>目标网站商业核心数据不爬</li>
<li>低并发,低频率,不影响目标网站正常运行</li>
<li>遵守当地/国家法律法规</li>
<li>受法律保护的信息将不会被抓取 (例如: 个人隐私数据、手机号码、身份证号码等。)</li>
<li>需要登录或VIP身份才能访问的数据将不会被抓取</li>
<li>目标网站明确禁止收集的数据将不会被抓取</li>
<li>目标网站的商业核心数据将不会被抓取</li>
<li>低并发、低频率,不影响目标网站的正常运行</li>
</ul>
<h3 class="mt-2">Hero爬虫列表</h3>
<dl class="mt-d5" id="herobots">
<!--
<dt>爬虫 1 <small>空闲</small></dt>
<dd>
Machete的Hero爬虫
- https://tajian.tv
</dd>
-->
</dl>
<h3 class="mt-2">机器人</h3>
<dl class="mt-d5" id="herobots">...</dl>
<h3 class="mt-2">HeroUnion应用</h3>
<h3 class="mt-2">HeroUnion App</h3>
<ul class="mt-d5">
<li>
<strong>网站监控</strong>
<a href="https://monitor.filesite.io/d/ddntdyyhv943ke/e7bd91-e7ab99-e79b91-e68ea7?orgId=1" target="_blank">Ta荐、FileSite.io监控</a>
<a href="https://github.com/filesite-io/monit-via-herounion" target="_blank">网站监控源码下载</a>
<strong>网站监控:</strong>
<a href="https://monitor.filesite.io/d/ddntdyyhv943ke/e7bd91-e7ab99-e79b91-e68ea7?orgId=1" target="_blank">FileSite.io Monitor</a>,
<a href="https://github.com/filesite-io/monit-via-herounion" target="_blank">Monitor source code download</a>
</li>
<li>
<strong>数据抓取:</strong>
<a href="https://tajian.tv/" target="_blank">Ta荐 - B站、抖音、快手、西瓜视频整理工具</a>
<a href="https://github.com/filesite-io/machete" target="_blank">Machete源码下载</a>
<strong>网页爬虫:</strong>
<a href="https://tajian.tv/" target="_blank">TaJian.tv - video box</a>
<a href="https://github.com/filesite-io/machete" target="_blank">Machete source code download</a>
</li>
</ul>
<h3 class="mt-1">HeroUnion源码下载</h3>
<h3 class="mt-1">HeroUnion下载</h3>
<p><a href="https://github.com/filesite-io/herounion" target="_blank">https://github.com/filesite-io/herounion</a></p>
<h3 class="mt-1">HeroBot - Machete Hero源码下载</h3>
<h3 class="mt-1">HeroBot下载</h3>
<p><a href="https://github.com/filesite-io/machete_hero" target="_blank">https://github.com/filesite-io/machete_hero</a></p>
<footer class="mt-4">
<p>
<strong>免责申明:</strong>
<br>HeroUnion英雄联盟<strong>只负责爬虫和任务的调度</strong>,爬虫所支持的合约以及任务具体内容与联盟无关。
<strong>免责声明:</strong>
<br>HeroUnion<strong>仅负责爬虫和任务的调度</strong>
爬虫支持的合约及任务的具体内容与联盟无关。
</p>
<p class="mt-2 text-center">&copy;copyright <a href="https://herounion.website/" target="_blank">HeroUnion.Website</a></p>
</footer>
<script src="/js/jquery-3.7.1.min.js"></script>
<script type="text/javascript">
var toggleLangSwitcher = function(evt) {
var btn = evt.target;
if (!btn) {return false;}
var status = $(btn).attr('data-status');
if (status == 'closed') {
$('.langswitcher .dropmenu').show();
$(btn).attr('data-status', 'opened');
}else {
$('.langswitcher .dropmenu').hide();
$(btn).attr('data-status', 'closed');
}
};
$('.langswitcher button').click(toggleLangSwitcher);
var formatSeconds = function(secs) {
var str = secs + '秒';
var str = secs + ' seconds';
if (secs > 86400) {
str = Math.floor(secs/86400) + '天';
str = Math.floor(secs/86400) + ' days';
}else if (secs > 3600) {
str = Math.floor(secs/3600) + '小时';
str = Math.floor(secs/3600) + ' hours';
}else if (secs > 300) {
str = Math.floor(secs/60) + '分钟';
str = Math.floor(secs/60) + ' minutes';
}else if (secs > 86400*365) {
str = Math.floor(secs/86400/365) + '年'
+ Math.floor( (secs - Math.floor(secs/86400/365)) / 86400 ) + '天';
str = Math.floor(secs/86400/365) + ' years'
+ Math.floor( (secs - Math.floor(secs/86400/365)) / 86400 ) + ' days';
}
return str;
@ -199,11 +214,11 @@ @@ -199,11 +214,11 @@
var renderHeros = function(heros) {
if (!heros || heros.length == 0) {
$('#herobots').text('暂无爬虫加入联盟。');
$('#herobots').text('There is no bot online.');
return;
}
var txtStatus = {idle: '空闲', busy: '繁忙', offline: '离线'};
var txtStatus = {idle: 'Idle', busy: 'Busy', offline: 'Offline'};
var html = '', item;
for (var index in heros) {
item = heros[index];
@ -211,9 +226,9 @@ @@ -211,9 +226,9 @@
+ txtStatus[item['status']] + '</small></dt>';
html += '<dd>'
+ htmlspecialchars(item['description'])
+ '<br>支持平台:' + JSON.stringify(item['platforms'])
+ ',支持合约:' + JSON.stringify(item['contracts'])
+ ',联系方式:' + htmlspecialchars(item['contact'])
+ '<br>Platforms: ' + JSON.stringify(item['platforms'])
+ ', Contracts: ' + JSON.stringify(item['contracts'])
+ ', Contact: ' + htmlspecialchars(item['contact'])
+ '</dd>';
}

23
test/i18n.test.mjs

@ -2,21 +2,25 @@ @@ -2,21 +2,25 @@
* i18n测试用例
*/
import fs from 'node:fs';
import { readdir, readFile, writeFile } from 'node:fs/promises';
import test from 'node:test';
import assert from 'node:assert';
import common from '../common.mjs';
import I18N from '../i18n.mjs';
/*
//根据模板文件生成默认语言包
test('Init test', async (t) => {
const i18n = new I18N();
const res = await i18n.init();
assert.ok(res);
});
*/
//根据语言包生成对应语言的html
test('Build test', async (t) => {
const i18n = new I18N();
const res = await i18n.build();
@ -24,3 +28,18 @@ test('Build test', async (t) => { @@ -24,3 +28,18 @@ test('Build test', async (t) => {
assert.ok(res);
});
/*
test('Lang file content get test', async (t) => {
const i18n = new I18N();
let langFiles = await i18n.getLangFiles('en-us');
const langJson = await readFile(i18n.langDir + langFiles[0], { encoding: 'utf8' });
if (langJson) {
let langData = JSON.parse(langJson);
for (const key in langData) {
console.log(key);
}
}
assert.ok(langJson);
});
*/

Loading…
Cancel
Save