knadh / dns.toys

A DNS server that offers useful utilities and services over the DNS protocol. Weather, world time, unit conversion etc.
https://www.dns.toys
MIT License
2.48k stars 135 forks source link

Add support for English to Other Language translation support #34

Open sandyydk opened 1 year ago

sandyydk commented 1 year ago

I propose adding support for translation from English to any other language. This can be useful while trying to convey something in other languages or just for fun. This is intended not be used to translate entire text or document but only for small use cases like wanting to translate say a number 50 in English to Hindi and for such scenarios.

The feature would use .translate to initiate it. It should accept the text in English to translate and the target language to which it should be translated. The format could be something like

dig hello-hindi.translate @dns.toys

or if we intend to support multiple words with a size limit then it could be like

dig hello_world.translate @dns.toys

where multiple words are separated by an "underscore". Hopefully underscore is a valid character in DNS.

The feature should consist of two services, .dice and .random. The first service should accept requests in the standard format kdn(+m.)dice, where k, n and m are numbers. For example:

Do let me know if this makes any sense. @knadh I can work on this if this is approved and this is my first try at contributing to open source. If there's something else I can pick up would be glad to try it out as well. Thanks in advance.

knadh commented 1 year ago

Thanks for the suggestion @sandyydk. Where would the data for translation come from?

sandyydk commented 1 year ago

Thanks for the suggestion @sandyydk. Where would the data for translation come from?

We could get it from Google translate by forming the URL this way for example

https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=hi&dj=1&dt=t&ie=UTF-8&q='how are you'

This repo shows a sample implementation

https://github.com/bregydoc/gtranslate

This is a hacky way to do it. Been using it for some time just to play around. API keys of say Google or Microsoft lets you make 50k requests per month after which it should be blocked.