Skip to content
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

Update logging messages to use gettext #453

Merged
merged 2 commits into from
Feb 10, 2018

Conversation

FabioRosado
Copy link
Member

Description

This is another part of #422 most logging messages will now be translated - some were causing texts to fail (mostly in opsdroid.loader) so i had to leave them untouched.

I've replaced the logging formating from: logging.info(msg, arg) to logging.info(msg % arg) I'm not sure if this is the best approach. It's possible to just translate the text from the logging by using the format: logging.info(_(msg), arg) let me know if this is preferred than the one I've used in this PR and i'll replace them again.

Status

READY | UNDER DEVELOPMENT | ON HOLD

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

  • Tox
  • Pycharm tests
  • Ran opsdroid

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@codecov
Copy link

codecov bot commented Feb 10, 2018

Codecov Report

Merging #453 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #453   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          18     18           
  Lines        1095   1095           
=====================================
  Hits         1095   1095
Impacted Files Coverage Δ
opsdroid/parsers/crontab.py 100% <100%> (ø) ⬆️
opsdroid/web.py 100% <100%> (ø) ⬆️
opsdroid/parsers/recastai.py 100% <100%> (ø) ⬆️
opsdroid/memory.py 100% <100%> (ø) ⬆️
opsdroid/loader.py 100% <100%> (ø) ⬆️
opsdroid/matchers.py 100% <100%> (ø) ⬆️
opsdroid/parsers/witai.py 100% <100%> (ø) ⬆️
opsdroid/parsers/dialogflow.py 100% <100%> (ø) ⬆️
opsdroid/parsers/rasanlu.py 100% <100%> (ø) ⬆️
opsdroid/__main__.py 100% <100%> (ø) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce39d10...535c80c. Read the comment docs.

@anxodio
Copy link
Contributor

anxodio commented Feb 10, 2018

Hi Fabio!

There is a problem with logging.info(msg % arg), I will try to explain it. For example, in this code example:

_LOGGER.debug(_("Adding database: %s" % name))

Let's say that name=opsdroid. So Python will format the string to Adding database: opsdroid, and then that text will be passed to gettext to be translated. That's a problem, because we need to translate the text with the %s, not with the final text.

So I think the solution is something like:

_LOGGER.debug(_("Adding database: %s"), name))

There, Python will first call gettext with Adding database: %s that will be translated (for example to catalan Afegint base de dades: %s). Then, the string will be formatted and name will replace %s.

@jacobtomlinson
Copy link
Member

Thanks @anxodio that's a good point. It doesn't usually cause problems as we use .format() and they string is formatted after translation. But with logging you must use % or comma separated variables.

@FabioRosado are you ok to update this?

@FabioRosado
Copy link
Member Author

Awesome thanks for the great explanation @anxodio ! I was unsure if this was the right approach that's why I asked. I'll revert the changes to follow the _LOGGER.debug(_("Adding database: %s"), name)) style 👍

@FabioRosado FabioRosado merged commit bc251c8 into opsdroid:master Feb 10, 2018
@FabioRosado FabioRosado deleted the gettext branch February 10, 2018 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants