为什么Google翻译会跳过Python中的某些文本? [英] Why is Google translator skipping some text in Python?

查看:116
本文介绍了为什么Google翻译会跳过Python中的某些文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将部分日语和英语部分的文本翻译成英语.我的问题是,在应用翻译功能后,原始文本中的某些文本似乎丢失了.

从代码和输出中可以看到

目前,仅产品HAZMAT的大约20%到30%的SDS是 获得

似乎从输出中丢失了.

代码

translator.translate(   
'At present only SDS of about 20 to 30% of HAZMAT of the product is obtained.  
Chemicals management (Japan) Qn 4.03 Business operators are responsible for ensuring that necessary information is readily recognized at each workplace dealing with substances specified as requiring safety data sheets (SDS) under the Occupational Safety and Health Act , Or make it known to workers handling such substances. 入手済みのSDSはPandashで確認することが出来る。MTEが使用する化学物質についてはSDSが入手されている。PCコメント(2017/07/10)SDSを入手する基準ですが、すべての商品に対して入手する、というのが原則ではあります。ただし、現在販売されているすべての商品に対して一度にSDSを入手することも難しいため、再判定になったときはSDSの提出をお願いし、ご提出いただいております。なお、もしも何らかの事情でSDSをご提出いただけない場合は、MSDS Exemption',  
src='ja', dest='en').text

输出

'Chemicals management (Japan) Qn 4.03 Business operators are responsible for ensuring that each information is readily recognized at each workplace dealing with substances specified as requiring safety data sheets ( SDS) under the Occupational Safety and Health Act, Or make it known hand to such workers. The obtained SDS can be confirmed with Pandash. For chemical substances used by MTE, SDS has been obtained. PC comment (2017/07/10) It is the standard to obtain SDS, but in principle it is to obtain for all items. However, it is difficult to acquire SDS at the same time for all the products currently on sale, so if you decide to reevaluate it, we ask you to submit SDS and submit it. In addition, if you are unable to submit SDS for any reason, MSDS Exemption'

解决方案

这似乎是格式问题,可能是因为文本中有换行符(\n).要解决此问题,请在文本周围加上三引号("""),以允许多行输入.

以下内容似乎可以提供所需的输出:

代码:

from googletrans import Translator

translator = Translator()

translator.translate(
"""At present only SDS of about 20 to 30% of HAZMAT of the product is obtained.
Chemicals management (Japan) Qn 4.03 Business operators are responsible for ensuring that necessary information is readily recognized at each workplace dealing with substances specified as requiring safety data sheets (SDS) under the Occupational Safety and Health Act , Or make it known to workers handling such substances. 入手済みのSDSはPandashで確認することが出来る。MTEが使用する化学物質についてはSDSが入手されている。PCコメント(2017/07/10)SDSを入手する基準ですが、すべての商品に対して入手する、というのが原則ではあります。ただし、現在販売されているすべての商品に対して一度にSDSを入手することも難しいため、再判定になったときはSDSの提出をお願いし、ご提出いただいております。なお、もしも何らかの事情でSDSをご提出いただけない場合は、MSDS Exemption""",
src='ja', dest='en').text

输出:

目前,仅获得产品HAZMAT的约20%至30%的SDS. 化学品管理(日本)Qn 4.03根据《职业安全与健康法》的规定,业务运营商应对每个要求提供安全数据表(SDS)的人员负责,或让从事此类工作的工人知道此事.可以通过Pandash确认获得的SDS.对于MTE使用的化学物质,已获得SDS. PC注释(2017/07/10)这是获取SDS的标准,但原则上是针对所有项目都获取.但是,对于当前正在销售的所有产品,很难同时获取SDS,因此,如果您决定重新评估它,我们请您提交并提交SDS.此外,如果您由于某种原因无法提交SDS,则可以免除MSDS

I am trying to translate text which is partly in Japanese and partly in English into English. My problem is that after applying the translate function, some text from the original text seems to be missing.

As can be seen from the code and output,

At present only SDS of about 20 to 30% of HAZMAT of the product is obtained

seems to be missing from the output.

Code

translator.translate(   
'At present only SDS of about 20 to 30% of HAZMAT of the product is obtained.  
Chemicals management (Japan) Qn 4.03 Business operators are responsible for ensuring that necessary information is readily recognized at each workplace dealing with substances specified as requiring safety data sheets (SDS) under the Occupational Safety and Health Act , Or make it known to workers handling such substances. 入手済みのSDSはPandashで確認することが出来る。MTEが使用する化学物質についてはSDSが入手されている。PCコメント(2017/07/10)SDSを入手する基準ですが、すべての商品に対して入手する、というのが原則ではあります。ただし、現在販売されているすべての商品に対して一度にSDSを入手することも難しいため、再判定になったときはSDSの提出をお願いし、ご提出いただいております。なお、もしも何らかの事情でSDSをご提出いただけない場合は、MSDS Exemption',  
src='ja', dest='en').text

Output

'Chemicals management (Japan) Qn 4.03 Business operators are responsible for ensuring that each information is readily recognized at each workplace dealing with substances specified as requiring safety data sheets ( SDS) under the Occupational Safety and Health Act, Or make it known hand to such workers. The obtained SDS can be confirmed with Pandash. For chemical substances used by MTE, SDS has been obtained. PC comment (2017/07/10) It is the standard to obtain SDS, but in principle it is to obtain for all items. However, it is difficult to acquire SDS at the same time for all the products currently on sale, so if you decide to reevaluate it, we ask you to submit SDS and submit it. In addition, if you are unable to submit SDS for any reason, MSDS Exemption'

解决方案

This seems to be a formatting issue, possibly because there is a line break (\n) character in your text. To solve this, surround your text with triple quotes (""") which allows for multi-line input.

The following seems to give your desired output:

Code:

from googletrans import Translator

translator = Translator()

translator.translate(
"""At present only SDS of about 20 to 30% of HAZMAT of the product is obtained.
Chemicals management (Japan) Qn 4.03 Business operators are responsible for ensuring that necessary information is readily recognized at each workplace dealing with substances specified as requiring safety data sheets (SDS) under the Occupational Safety and Health Act , Or make it known to workers handling such substances. 入手済みのSDSはPandashで確認することが出来る。MTEが使用する化学物質についてはSDSが入手されている。PCコメント(2017/07/10)SDSを入手する基準ですが、すべての商品に対して入手する、というのが原則ではあります。ただし、現在販売されているすべての商品に対して一度にSDSを入手することも難しいため、再判定になったときはSDSの提出をお願いし、ご提出いただいております。なお、もしも何らかの事情でSDSをご提出いただけない場合は、MSDS Exemption""",
src='ja', dest='en').text

Output:

At present only SDS of about 20 to 30% of HAZMAT of the product is obtained. Chemicals management (Japan) Qn 4.03 Business operators are each responsible for each requiring safety data sheets (SDS) under the Occupational Safety and Health Act, Or make it known to workers handling such The obtained SDS can be confirmed with Pandash. For chemical substances used by MTE, SDS has been obtained. PC comment (2017/07/10) It is the standard to obtain SDS, but in principle it is to obtain for all items. However, it is difficult to acquire SDS at the same time for all the products currently on sale, so if you decide to reevaluate it, we ask you to submit SDS and submit it. In addition, if you are unable to submit SDS for any reason, MSDS Exemption

这篇关于为什么Google翻译会跳过Python中的某些文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆