New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Localize opsdroid #422
Comments
This is a great idea and I basically agree with everything you have said. Here are a few additional thoughts from me:
@match_regex(r'hi|hello|hey|hallo')
@match_regex(r'hola|buenas|saludos', lang='es')
async def hello(opsdroid, config, message):
[...]
@match_regex(r'hi|hello|hey|hallo')
@match_regex(r'hola|buenas|saludos', lang='es')
async def hello(opsdroid, config, message):
message.respond({"en": "Hi", "es": "Hola"}) |
|
|
I like the idea of allowing other people that don't speak english very well to use opsdroid. English should be the fallback language if the parser doesn't support the chosen language, this way everything will work fine - I agree with the warning if the language is not supported. I never played around with the gettext so I'm just going to ask: Will the fact that we mostly use the |
It shouldn't cause any problems. The translated string should contain the same placeholder. "My name is {}".format("Jacob") will become _("My name is {}").format("Jacob") and if the language is set to Spanish then the translated string could be We might want to think about switching our formatting from arg based to kwarg based which will allow translations to omit placeholders if they don't make sense or change the order if that is appropriate. For example in english we would say "The blue car" but in Spanish you might say "El auto azul". The adjective goes in a different place. If we wanted to format the colour and object we would need to have something like _("The {colour} {object}").format(colour=_("blue"), object=_("car")) |
@FabioRosado I found this blog post useful. |
Yeah, I agree totally with the use of .format() if it's possible (I think logging uses old formatting tools with And I think it's easy for the skills developers to use |
Sounds good. So the agreed design is:
As there is quite a bit of work here I'm happy to take multiple PRs to tick off these requirements. This issue will be closed once all are complete. @afibanez I ❤️ pyformat! Thanks for sharing that. |
Sounds awesome! Yeah I was thinking that using something like: I can also give a hand translating things to Portuguese and might even bother the fiancé to help with polish 👍 |
@jacobtomlinson, Is Hindi a good option to add here? I'd love to help adding Hindi translations. |
Absolutely! |
Opsdroid is designed with English in mind. A developer can write his skills (regex and responses) in any other language, but actually it has some complications:
So let's discuss what we need to do to go multilanguage (i already used some @jacobtomlinson ideas)
Breaking changes
The idea of the multi language design is to don't break anything. So if you don't change the language, Opsdroid has to assume english and work as normally.
Configuration
We need a new
language
configuration item, that can be filled with any ISO 693-1 two-letter code. By default it will been
.Core localization
We need to use some Python translation library. In my opinion, we should use the gettext library, it is extended, easy to use, and in standard libraries. Here is a post explaining the usage.
So the rule should be mark as translatable every string that can be read by the end user through the chat (like the Whoops error).
Parser/Matcher localization
Now we have different behaviours:
always
orcrontab
there is no problem.regex
we should add some extra decorators with the locale code at the end (for example@match_regex_es
). The basic decordator will be mandatory, and it will point always to english. And if the configurated language is not defined by a decorator, it will default to english. For example, for theskill-hello
, it can be like:recastai
ordialogflow
requires a language code to be sent in every request. So my proposal is to define a list of accepted languages (defined by the service) and check if the configurated language is in it. If the configurated language it's not suported by the service, fallback to english.luisai
orwitai
don't recieve a language code in the request. Instead, you need to configure the language as a configuration item on the service. So here, if you need various languages, you need various endpoints. So we need to add more configuration items, like:rasanlu
works locally and depends on us. So the point here is to translate the intents files. By defualt, we haveintents.md
pointing to english. We can also add a lang code at the end to translate it, likeintents_es.md
. But the languages that rasa supports are limited, so probably we need to define a list and check it (like inrecastai
ordialogflow
)Skill answer localization
I think we sould bet for
gettext
too. We need to implement an interface thinking in the skills too, and let every skill module to has his own translations.Another time, if it's not translated or
gettext
methods are not used, it will not break and default to english.The text was updated successfully, but these errors were encountered: