我在我的html文本文件中有很多数据框架,比如[COMPANY],我想在Deepl翻译我的文本时排除它。我在api中使用Deepl Java,不允许更改数据帧格式。
知道如何将dfTEXT排除在翻译之外吗?
示例文本:
Dear client,
Please find enclosed [EVENT] for the order you wish to execute for your account [ACCOUNT_NAME_TEXT].
Kind regards,
[COMPANY_NAME]html文件
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Dear client,</p>
<p>Please find enclosed the Events for the order you wish to execute for your account [ACCOUNT_NAME_TEXT].</p>
<p> </p>
<p>Kind regards,</p>
<p>[COMPANY_NAME]</p>
</body>
</html>发布于 2022-10-13 08:40:02
现在,我解决了这个问题,在翻译并将其设置为原始标记之前,我将df[TEXT]解析为忽略标记。参见下面的方法,它可以帮助具有相同请求的人。
private static final String BEGIN_IGNORE_TAG = "<loveIgnoreTag>";
private static final String END_IGNORE_TAG = "</loveIgnoreTag>";
public String translate( String source , String target, String text )
throws DeepLException, InterruptedException
{
//https://www.deepl.com/docs-api/xml/ignored-tags/
ArrayList<String> ignoreTags = new ArrayList<>( ) ;
ignoreTags.add( "loveIgnoreTag" );
text = parseToIgnoreTage(text);
TextTranslationOptions translationOptions = new TextTranslationOptions( )
.setTagHandling( "xml" )
.setFormality( Formality.PreferMore )
.setPreserveFormatting( true )
.setIgnoreTags( () -> ignoreTags.iterator( ) )
.setSentenceSplittingMode( SentenceSplittingMode.All );
TextResult result = translator.translateText( text, source, target, translationOptions );
String translationResult = parseToDataFrame(result.getText( ));
return translationResult;
}
private String parseToIgnoreTage( String text )
{
text = text.replace( "[", BEGIN_IGNORE_TAG ).replace( "]", END_IGNORE_TAG );
return text;
}
private String parseToDataFrame( String result )
{
result = result.replace(BEGIN_IGNORE_TAG,"[" ).replace( END_IGNORE_TAG, "]" );
return result;
}https://stackoverflow.com/questions/74039527
复制相似问题