问题
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'
回答1:
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
来源:https://stackoverflow.com/questions/54197748/why-is-google-translator-skipping-some-text-in-python