Browse Source

Merge branch 'Byaidu:main' into main

imClumsyPanda 1 year ago
parent
commit
1f9ca69e80
5 changed files with 19 additions and 17 deletions
  1. 5 5
      docs/README_ja-JP.md
  2. 5 5
      docs/README_zh-CN.md
  3. 3 0
      pdf2zh/cache.py
  4. 1 2
      pdf2zh/translator.py
  5. 5 5
      test/test_translator.py

+ 5 - 5
docs/README_ja-JP.md

@@ -2,7 +2,7 @@
 
 [English](../README.md) | [简体中文](README_zh-CN.md) | 日本語
 
-<img src="./docs/images/banner.png" width="320px"  alt="PDF2ZH"/>  
+<img src="./images/banner.png" width="320px"  alt="PDF2ZH"/>  
 
 <h2 id="title">PDFMathTranslate</h2>
 
@@ -56,7 +56,7 @@
 <h2 id="preview">プレビュー</h2>
 
 <div align="center">
-<img src="./docs/images/preview.gif" width="80%"/>
+<img src="./images/preview.gif" width="80%"/>
 </div>
 
 <h2 id="demo">公共サービス 🌟</h2>
@@ -122,9 +122,9 @@ Python環境を事前にインストールする必要はありません
     http://localhost:7860/
     ```
 
-    <img src="./docs/images/gui.gif" width="500"/>
+    <img src="./images/gui.gif" width="500"/>
 
-詳細については、[GUIのドキュメント](./docs/README_GUI.md) を参照してください。
+詳細については、[GUIのドキュメント](./README_GUI.md) を参照してください。
 
 <h3 id="docker">方法4. Docker</h3>
 
@@ -158,7 +158,7 @@ Python環境を事前にインストールする必要はありません
 
 コマンドラインで翻訳コマンドを実行し、現在の作業ディレクトリに翻訳されたドキュメント `example-mono.pdf` とバイリンガルドキュメント `example-dual.pdf` を生成します。デフォルトではGoogle翻訳サービスを使用します。
 
-<img src="./docs/images/cmd.explained.png" width="580px"  alt="cmd"/>  
+<img src="./images/cmd.explained.png" width="580px"  alt="cmd"/>  
 
 以下の表に、参考のためにすべての高度なオプションをリストしました:
 

+ 5 - 5
docs/README_zh-CN.md

@@ -2,7 +2,7 @@
 
 [English](../README.md) | 简体中文 | [日本語](README_ja-JP.md)
 
-<img src="./docs/images/banner.png" width="320px"  alt="PDF2ZH"/>  
+<img src="./images/banner.png" width="320px"  alt="PDF2ZH"/>  
 
 <h2 id="title">PDFMathTranslate</h2>
 
@@ -56,7 +56,7 @@
 <h2 id="preview">效果预览</h2>
 
 <div align="center">
-<img src="./docs/images/preview.gif" width="80%"/>
+<img src="./images/preview.gif" width="80%"/>
 </div>
 
 <h2 id="demo">在线演示 🌟</h2>
@@ -121,9 +121,9 @@ set HF_ENDPOINT=https://hf-mirror.com
     http://localhost:7860/
     ```
 
-    <img src="./docs/images/gui.gif" width="500"/>
+    <img src="./images/gui.gif" width="500"/>
 
-查看 [documentation for GUI](./docs/README_GUI.md) 获取细节说明
+查看 [documentation for GUI](/README_GUI.md) 获取细节说明
 
 <h3 id="docker">方法四、容器化部署</h3>
 
@@ -157,7 +157,7 @@ set HF_ENDPOINT=https://hf-mirror.com
 
 在命令行中执行翻译命令,在当前工作目录下生成译文文档 `example-mono.pdf` 和双语对照文档 `example-dual.pdf`,默认使用 Google 翻译服务
 
-<img src="./docs/images/cmd.explained.png" width="580px"  alt="cmd"/>  
+<img src="./images/cmd.explained.png" width="580px"  alt="cmd"/>  
 
 我们在下表中列出了所有高级选项,以供参考:
 

+ 3 - 0
pdf2zh/cache.py

@@ -45,6 +45,9 @@ class TranslationCache:
         return obj
 
     def __init__(self, translate_engine: str, translate_engine_params: dict = None):
+        assert (
+            len(translate_engine) < 20
+        ), "current cache require translate engine name less than 20 characters"
         self.translate_engine = translate_engine
         self.replace_params(translate_engine_params)
 

+ 1 - 2
pdf2zh/translator.py

@@ -79,8 +79,7 @@ class BaseTranslator:
                 return cache
 
         translation = self.do_translate(text)
-        if not (self.ignore_cache or ignore_cache):
-            self.cache.set(text, translation)
+        self.cache.set(text, translation)
         return translation
 
     def do_translate(self, text):

+ 5 - 5
test/test_translator.py

@@ -50,17 +50,17 @@ class TestTranslator(unittest.TestCase):
         self.assertNotEqual(first_result, second_result)
 
         # Test cache with ignore_cache=True
-        no_cache_result = translator.translate(text, ignore_cache=True)
-        self.assertNotEqual(first_result, no_cache_result)
+        no_cache_result1 = translator.translate(text, ignore_cache=True)
+        self.assertNotEqual(first_result, no_cache_result1)
 
         translator.ignore_cache = True
-        no_cache_result = translator.translate(text)
-        self.assertNotEqual(first_result, no_cache_result)
+        no_cache_result2 = translator.translate(text)
+        self.assertNotEqual(no_cache_result1, no_cache_result2)
 
         # Test cache with ignore_cache=False
         translator.ignore_cache = False
         cache_result = translator.translate(text)
-        self.assertEqual(second_result, cache_result)
+        self.assertEqual(no_cache_result2, cache_result)
 
         # Test cache with another parameter
         translator.add_cache_impact_parameters("test2", "value2")