Comments (14)
Show me Screenshot Pls.
from deeplx.
![截屏2024-04-24 下午2 18 02](https://private-user-images.githubusercontent.com/97672521/325101904-c3f7ae1b-2304-4aef-8d1d-cc216e6391ab.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyNDAzNjgsIm5iZiI6MTcyMTI0MDA2OCwicGF0aCI6Ii85NzY3MjUyMS8zMjUxMDE5MDQtYzNmN2FlMWItMjMwNC00YWVmLThkMWQtY2MyMTZlNjM5MWFiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE3VDE4MTQyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI1YWZlZTI2NTQzMjYyNDUxOGIyMzRjZWVjZmU3ZjRlNTc1NjhkYjMyZTM5NDdhNDAwNWE5NmIwMDlkYjI4MGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.6Q8FpTsUPIGUnC56QRjm84IFRwnd_VFOCdCYW0XtS0c)
Show me Screenshot Pls.
the commands are from README.
At first I thought it was my code's issue. So I tested the command with multiple lines. Which didn't work
from deeplx.
In JSON, strings cannot be written directly across lines. You should use newline characters.
curl -X POST http://localhost:1188/translate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_access_token" \
-d '{
"text": "Hello\nworld!",
"source_lang": "EN",
"target_lang": "DE"
}'
from deeplx.
![image](https://private-user-images.githubusercontent.com/55200481/325103805-11df370b-78cf-4847-a2f3-29cca9ec50fe.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyNDAzNjgsIm5iZiI6MTcyMTI0MDA2OCwicGF0aCI6Ii81NTIwMDQ4MS8zMjUxMDM4MDUtMTFkZjM3MGItNzhjZi00ODQ3LWEyZjMtMjljY2E5ZWM1MGZlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE3VDE4MTQyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgxODE1OGU3MTY3ODBmNWEwNDYyNjQ0M2Q5NDVkOGQ5ZjY4YTY2NjI0MmRmYjFhYTRjMTRjMWY1NjM1MDdlM2ImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.7sNwWKFouewvuc8XHvTyGJNeqX_MEwo7npGYrttLzpE)
If you use this type of API debugging tool, you'll notice that when you paste something that contains line breaks, it's automatically converted to \n
.
from deeplx.
so what should I do if I want to make it able to do multiple lines. Or is it just not possible?
from deeplx.
so what should I do if I want to make it able to do multiple lines. Or is it just not possible?
Is my expression not clear enough? I have already given you quite clear examples above.
from deeplx.
I hope you have some basic knowledge of coding, at least to the extent that you understand what \n
represents. Otherwise, I think you will not be able to use DeepLX properly.
from deeplx.
understand, i need to convert it to \n then reconvert it back to lines
from deeplx.
understand, i need to convert it to \n then reconvert it back to lines
![image](https://private-user-images.githubusercontent.com/55200481/325105542-4070b92f-d463-469c-a4ec-76f0b6e50762.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyNDAzNjgsIm5iZiI6MTcyMTI0MDA2OCwicGF0aCI6Ii81NTIwMDQ4MS8zMjUxMDU1NDItNDA3MGI5MmYtZDQ2My00NjljLWE0ZWMtNzZmMGI2ZTUwNzYyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE3VDE4MTQyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY4OGE2Yzc1MWRjMTc5YmQxMDM2ZTU5MmI5OTUwNTNjMTk0MzUxMmIwNDhhOGYzOGVjYTRlYzg1YjFmYTY0NGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.2YASYy-2y_vvorGcxpW9kSvpyjc-PLTNrQk6CmCWHgg)
It seems you still haven't understood what I meant. If you extract the data
from the Response, printing it will automatically line break because it contains \n
.
from deeplx.
I need to convert it as well right?(like var=var.replace('\n', '\n')
oh, I'm not printing it. I'm displaying it like a widget so, i convert it back (var=var.replace('\n', '\n'))
from deeplx.
I need to convert it as well right?(like var=var.replace('\n', '\n') oh, I'm not printing it. I'm displaying it like a widget so, i convert it back (var=var.replace('\n', '\n'))
Show me your full code.
from deeplx.
text = data["q"]
target_lang = data["target"]
if "source" in data:
source_lang = data["source"]
deeplx_base_url = os.environ.get("DEEPLX_BASE_URL")
if not deeplx_base_url:
return Response(
status_code=500,
content=json.dumps(
{
"error": {
"message": "No DEEPLX_BASE_URL provided",
}
}
),
)
print(text)
text = text.replace('\n', '\\n')
print(text)
body = {
"text": text,
"target_lang": target_lang,
}
if "source" in data:
body["source_lang"] = source_lang
try:
req = ProxyRequest(
deeplx_base_url, "POST", '', json.dumps(body), query_params={}
# deeplx_base_url, "POST", headers, json.dumps(body), query_params={}
)
resp = await pass_through_request(http_client, req, nohttps=True, noheaders=True)
resp = json.loads(resp.content.decode("utf-8"))
try:
translated_text = resp["alternatives"][0]
print(translated_text)
translated_text = translated_text.replace('\\nn', '\n')
print(translated_text)
res = {"data": {"translations": [{"translatedText": translated_text}]}}
except TypeError:
# res = {"error": {"message": "Failed to translate"}}
# res = {"data": {"translations": [{"translatedText": "Failed to translate"}]}}
res = {"data": {"translations": [{"translatedText": text}]}}
if "source" not in raycast_data:
res["data"]["translations"][0]["detectedSourceLanguage"] = resp[
"source_lang"
].lower()
return Response(status_code=200, content=json.dumps(res))
except Exception as e:
logger.error(f"DEEPLX error: {e}")
return Response(
status_code=500,
content=json.dumps(
{
"error": {
"message": "Unknown error",
}
}
),
)
from deeplx.
replace('\n', '\\n')
Why do this?
from deeplx.
because otherwise it will return {"code":404,"message":"No text to translate}
from deeplx.
Related Issues (20)
- 沉浸翻译偶尔报错:Unexpected end of JSON input HOT 1
- the response data is blank HOT 1
- v2/translate 接口似乎没有校验 token HOT 1
- v2/translate 接口的 Authorization 头和官方不一致 HOT 7
- Ability to provide auth keys within file HOT 4
- 临时解决时区问题
- 请求添加对树莓派ARM的二进制程序 HOT 5
- can i use my premium session? HOT 3
- 功能建议:术语表
- 批量翻译返回格式和官方不一致 HOT 2
- 是否可用添加ipv6的代理池
- DeeplX doest work? HOT 3
- Multiple text translation HOT 2
- how avoid translation failed, because of empty result ? HOT 7
- Add to Related Projects HOT 6
- 为什么一下载就被查杀了 HOT 5
- [Feature request] Add an option to listen on a specific ip address instead of 0.0.0.0 HOT 1
- Add new model of deepl HOT 1
- Is the use of proxy IP supported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deeplx.