Skip to content

Commit

Permalink
[FIX] SyntaxError: name '_' is used prior to global declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien LANGE committed Feb 8, 2018
1 parent 0e60f23 commit 942a426
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions odoo_sentinel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ def __init__(self, stdscr, options):
"""
Initialize the sentinel program
"""
# Replace global dummy lambda by the translations gettext method
# The install method of gettext doesn't replace the function if exists
global _

# Initialize translations
lang = self.connection.env.context.get('lang', I18N_DEFAULT)
gettext.install(I18N_DOMAIN)
try:
language = gettext.translation(
I18N_DOMAIN, I18N_DIR, languages=[lang])
except:
language = gettext.translation(
I18N_DOMAIN, I18N_DIR, languages=[I18N_DEFAULT])

_ = language.gettext

if options.profile in odoorpc.ODOO.list(rc_file=options.config_file):
# Try to autodetect an OdooRPC configuration
self.connection = odoorpc.ODOO.load(options.profile)
Expand All @@ -71,21 +87,6 @@ def __init__(self, stdscr, options):
if options.test_file:
self.test_file = open(os.path.expanduser(options.test_file), 'r')

# Initialize translations
lang = self.connection.env.context.get('lang', I18N_DEFAULT)
gettext.install(I18N_DOMAIN)
try:
language = gettext.translation(
I18N_DOMAIN, I18N_DIR, languages=[lang])
except:
language = gettext.translation(
I18N_DOMAIN, I18N_DIR, languages=[I18N_DEFAULT])

# Replace global dummy lambda by the translations gettext method
# The install method of gettext doesn't replace the function if exists
global _
_ = language.gettext

# Initialize window
self.screen = stdscr
self._set_screen_size()
Expand Down Expand Up @@ -838,7 +839,7 @@ def _menu_display(self, entries, highlighted, title=None):
nb_lines, self.window_width - 1, curses.ACS_DARROW)

# Diplays number of the selected entry
self._display(_('Selected : %d') % highlighted, y=self.window_height-1,
self._display(_('Selected : %d') % highlighted, y=self.window_height - 1,
color='info', modifier=curses.A_BOLD)

# Set the cursor position
Expand Down Expand Up @@ -877,5 +878,6 @@ def main():

curses.wrapper(Sentinel, args)


if __name__ == '__main__':
main()

0 comments on commit 942a426

Please sign in to comment.