Skip to content

Commit

Permalink
Fix translation of query for writing. Fix emv lookup. No override of …
Browse files Browse the repository at this point in the history
…gettext
  • Loading branch information
vaeth committed Apr 23, 2018
1 parent fcfbf97 commit 63d08ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog for replacer

*replacer-3.1
Martin Väth <martin at mvath.de>:
- Fix error if REPLACER_NLS or NLS are not set
- Fix error if gettext is found but gettext.install throws
- Fix translation of query for writing

*replacer-3.0
Martin Väth <martin at mvath.de>:
- Support translations (gettext)
Expand Down
24 changes: 13 additions & 11 deletions bin/replacer
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import os
import re
import sys

version = '3.0'
version = '3.1'

# Set localedir to e.g. '/usr/share/locale' to fix the gettext (nls) path.
# If localedir == '', the value is fetched from $REPLACER_NLS or $NLS.
Expand Down Expand Up @@ -40,9 +40,9 @@ except ImportError:
have_gettext = False
if localedir is not None:
if not localedir: # Use $REPLACER_NLS as a fallback
localedir = os.environ['REPLACER_NLS']
localedir = os.environ.get('REPLACER_NLS')
if not localedir: # Use $NLS as a fallback
localedir = os.environ['NLS']
localedir = os.environ.get('NLS')
try:
gettext.install('replacer', localedir=localedir, names=['ngettext'])
have_gettext = True
Expand All @@ -66,17 +66,16 @@ if have_gettext:
return msgid2
return t
else:
def gettext(message):
def _(message):
return message
_ = gettext

def ngettext(msgid1, msgid2, n):
if n == 1:
return msgid1
return msgid2

def pgettext(id, message):
return gettext(message)
return _(message)

def npgettext(id, msgid1, msgid2, n):
return ngettext(msgid1, msgid2, n)
Expand Down Expand Up @@ -832,10 +831,8 @@ class Matcher:


def ask_replace():
msg = P_('replace', 'y(es)/n(o)/r(est of file)/q(uit this file)/a(lways)/'
'A(lways quiet)/s(top all) ')
while True:
key = my_input(msg)
key = my_input(ask_replace.msg)
try:
answer = ask_replace.dictionary[key]
break
Expand All @@ -844,6 +841,9 @@ def ask_replace():
if answer == 's':
sys.exit(0)
return answer
ask_replace.msg = P_(
'replace', 'y(es)/n(o)/r(est of file)/q(uit this file)/a(lways)/'
'A(lways quiet)/s(top all) ')
ask_replace.dictionary = {
P_('replace', 's'): 's',
P_('replace', 'y'): 'y',
Expand All @@ -856,8 +856,7 @@ ask_replace.dictionary = {


def ask_write(filename):
msg = P_('write', 'write changes to {0}? '
'y(es)/n(o)/w(rite always)/s(top all) '.format(filename))
msg = ask_write.msg.format(filename)
while True:
key = my_input(msg)
try:
Expand All @@ -868,6 +867,9 @@ def ask_write(filename):
if answer == 's':
sys.exit(0)
return answer
ask_write.msg = P_(
'write', 'write changes to {0}? '
'y(es)/n(o)/w(rite always)/s(top all) ')
ask_write.dictionary = {
P_('replace', 's'): 's',
P_('replace', 'y'): 'y',
Expand Down

0 comments on commit 63d08ed

Please sign in to comment.