Localise readline
This commit is contained in:
parent
69cbad353a
commit
4dba82aaaa
@ -24,6 +24,7 @@ import os.path
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
from relational import relation, parser, rtypes
|
from relational import relation, parser, rtypes
|
||||||
from relational import maintenance
|
from relational import maintenance
|
||||||
@ -122,7 +123,7 @@ def load_relation(filename: str, defname: Optional[str]) -> Optional[str]:
|
|||||||
'''
|
'''
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
print(colorize(
|
print(colorize(
|
||||||
f'{filename} is not a file', ERROR_COLOR), file=sys.stderr)
|
_(f'{filename} is not a file'), ERROR_COLOR), file=sys.stderr)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if defname is None:
|
if defname is None:
|
||||||
@ -132,14 +133,14 @@ def load_relation(filename: str, defname: Optional[str]) -> Optional[str]:
|
|||||||
defname = defname[:-4]
|
defname = defname[:-4]
|
||||||
|
|
||||||
if not rtypes.is_valid_relation_name(defname):
|
if not rtypes.is_valid_relation_name(defname):
|
||||||
print(colorize(
|
print(colorize(_(
|
||||||
"%s is not a valid relation name" % defname, ERROR_COLOR), file=sys.stderr)
|
'%s is not a valid relation name') % defname, ERROR_COLOR), file=sys.stderr)
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
ui.load(filename, defname)
|
ui.load(filename, defname)
|
||||||
|
|
||||||
completer.add_completion(defname)
|
completer.add_completion(defname)
|
||||||
printtty(colorize("Loaded relation %s" % defname, COLOR_GREEN))
|
printtty(colorize(_('Loaded relation %s' % defname, COLOR_GREEN))
|
||||||
return defname
|
return defname
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(colorize(str(e), ERROR_COLOR), file=sys.stderr)
|
print(colorize(str(e), ERROR_COLOR), file=sys.stderr)
|
||||||
@ -157,14 +158,14 @@ def survey() -> None:
|
|||||||
post[i] = a
|
post[i] = a
|
||||||
response = maintenance.send_survey(post)
|
response = maintenance.send_survey(post)
|
||||||
if response == -1:
|
if response == -1:
|
||||||
print('Yeah, not sending that.')
|
print(_('Yeah, not sending that.'))
|
||||||
|
|
||||||
|
|
||||||
def help(command: str) -> None:
|
def help(command: str) -> None:
|
||||||
'''Prints help on the various functions'''
|
'''Prints help on the various functions'''
|
||||||
p = command.split(' ', 1)
|
p = command.split(' ', 1)
|
||||||
if len(p) == 1:
|
if len(p) == 1:
|
||||||
print(
|
print(_(
|
||||||
'HELP [command]\n'
|
'HELP [command]\n'
|
||||||
'\n'
|
'\n'
|
||||||
'Comments are obtained starting with a ;\n'
|
'Comments are obtained starting with a ;\n'
|
||||||
@ -179,20 +180,20 @@ def help(command: str) -> None:
|
|||||||
'To insert relational operators, type _OPNAME, they will be internally replaced with the correct symbol.\n'
|
'To insert relational operators, type _OPNAME, they will be internally replaced with the correct symbol.\n'
|
||||||
'\n'
|
'\n'
|
||||||
'Rember: completion is enabled and can be very helpful if you can\'t remember something.'
|
'Rember: completion is enabled and can be very helpful if you can\'t remember something.'
|
||||||
)
|
))
|
||||||
return
|
return
|
||||||
cmd = p[1]
|
cmd = p[1]
|
||||||
|
|
||||||
cmdhelp = {
|
cmdhelp = {
|
||||||
'QUIT': 'Quits the program',
|
'QUIT': _('Quits the program'),
|
||||||
'LIST': 'Lists the relations loaded',
|
'LIST': _('Lists the relations loaded'),
|
||||||
'LOAD': 'LOAD filename [relationame]\nLoads a relation into memory',
|
'LOAD': _('LOAD filename [relationame]\nLoads a relation into memory'),
|
||||||
'UNLOAD': 'UNLOAD relationame\nUnloads a relation from memory',
|
'UNLOAD': _('UNLOAD relationame\nUnloads a relation from memory'),
|
||||||
'SAVE': 'SAVE filename relationame\nSaves a relation in a file',
|
'SAVE': _('SAVE filename relationame\nSaves a relation in a file'),
|
||||||
'HELP': 'Prints the help on a command',
|
'HELP': _('Prints the help on a command'),
|
||||||
'SURVEY': 'Fill and send a survey',
|
'SURVEY': _('Fill and send a survey'),
|
||||||
}
|
}
|
||||||
print(cmdhelp.get(cmd, 'Unknown command: %s' % cmd))
|
print(cmdhelp.get(cmd, _('Unknown command: %s') % cmd))
|
||||||
|
|
||||||
|
|
||||||
def exec_line(command: str) -> None:
|
def exec_line(command: str) -> None:
|
||||||
@ -218,7 +219,7 @@ def exec_line(command: str) -> None:
|
|||||||
elif command.startswith('LOAD '): # Loads a relation
|
elif command.startswith('LOAD '): # Loads a relation
|
||||||
pars = command.split(' ')
|
pars = command.split(' ')
|
||||||
if len(pars) == 1:
|
if len(pars) == 1:
|
||||||
print(colorize("Missing parameter", ERROR_COLOR))
|
print(colorize(_("Missing parameter"), ERROR_COLOR))
|
||||||
return
|
return
|
||||||
|
|
||||||
filename = pars[1]
|
filename = pars[1]
|
||||||
@ -230,18 +231,18 @@ def exec_line(command: str) -> None:
|
|||||||
elif command.startswith('UNLOAD '):
|
elif command.startswith('UNLOAD '):
|
||||||
pars = command.split(' ')
|
pars = command.split(' ')
|
||||||
if len(pars) < 2:
|
if len(pars) < 2:
|
||||||
print(colorize("Missing parameter", ERROR_COLOR))
|
print(colorize(_("Missing parameter"), ERROR_COLOR))
|
||||||
elif len(pars) > 2:
|
elif len(pars) > 2:
|
||||||
print(colorize("Too many parameter", ERROR_COLOR))
|
print(colorize(_("Too many parameter"), ERROR_COLOR))
|
||||||
if pars[1] in ui.relations:
|
if pars[1] in ui.relations:
|
||||||
ui.unload(pars[1])
|
ui.unload(pars[1])
|
||||||
completer.remove_completion(pars[1])
|
completer.remove_completion(pars[1])
|
||||||
else:
|
else:
|
||||||
print(colorize("No such relation %s" % pars[1], ERROR_COLOR))
|
print(colorize(_("No such relation %s") % pars[1], ERROR_COLOR))
|
||||||
elif command.startswith('SAVE '):
|
elif command.startswith('SAVE '):
|
||||||
pars = command.split(' ')
|
pars = command.split(' ')
|
||||||
if len(pars) != 3:
|
if len(pars) != 3:
|
||||||
print(colorize("Missing parameter", ERROR_COLOR))
|
print(colorize(_("Missing parameter"), ERROR_COLOR))
|
||||||
return
|
return
|
||||||
|
|
||||||
filename = pars[1]
|
filename = pars[1]
|
||||||
@ -318,9 +319,9 @@ def exec_query(command: str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def main(files=[]):
|
def main(files=[]):
|
||||||
printtty(colorize('> ', PROMPT_COLOR) + "; Type HELP to get the HELP")
|
printtty(colorize('> ', PROMPT_COLOR) + _("; Type HELP to get the HELP"))
|
||||||
printtty(colorize('> ', PROMPT_COLOR) +
|
printtty(colorize('> ', PROMPT_COLOR) +
|
||||||
"; Completion is activated using the tab (if supported by the terminal)")
|
_("; Completion is activated using the tab (if supported by the terminal)"))
|
||||||
|
|
||||||
for i in files:
|
for i in files:
|
||||||
load_relation(i, None)
|
load_relation(i, None)
|
||||||
|
Loading…
Reference in New Issue
Block a user