Skip to content

Commit

Permalink
Added localization framework to mssql-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Lee committed Aug 22, 2019
1 parent 595e2ad commit 68d0020
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
19 changes: 19 additions & 0 deletions mssqlcli/i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from importlib import import_module
import gettext
import os

CLI_NAME = 'mssql-cli'
MODULE = 'mssqlcli'

def translate():
"""
Gets the localized translation of message, based on the current global
domain, language, and locale directory of the module.
:param mod: The module namespace containing the locale for translation.
:return: The localized translation of message, based on the current global
domain, language, and locale directory alias.
"""
modulePath = os.path.dirname(import_module(MODULE).__file__)
localedir = os.path.join(modulePath, 'locale')
domain = CLI_NAME
return gettext.translation(domain, localedir, fallback=True).gettext
7 changes: 5 additions & 2 deletions mssqlcli/jsonrpc/contracts/connectionservice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging

from mssqlcli.jsonrpc.contracts import Request
from mssqlcli.i18n import translate

import logging

_ = translate()
logger = logging.getLogger(u'mssqlcli.connectionservice')


Expand Down Expand Up @@ -50,7 +53,7 @@ def get_response(self):
u'ownerUri': self.owner_uri,
u'connectionId': None,
u'messages': str(error),
u'errorMessage': u'Connection request encountered an exception',
u'errorMessage': _(u'Connection request encountered an exception'),
u'errorNumber': None
}
})
Expand Down
48 changes: 26 additions & 22 deletions mssqlcli/mssqlclioptionsparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import os

from .config import config_location
from mssqlcli.i18n import translate


_ = translate()

MSSQL_CLI_USER = u'MSSQL_CLI_USER'
MSSQL_CLI_PASSWORD = u'MSSQL_CLI_PASSWORD'
Expand All @@ -15,139 +19,139 @@
def create_parser():
args_parser = argparse.ArgumentParser(
prog=u'mssql-cli',
description=u'Microsoft SQL Server CLI. ' +
u'Version {}'.format(mssqlcli.__version__))
description=u'Microsoft SQL Server CLI Version {}'\
.format(mssqlcli.__version__))

args_parser.add_argument(
u'-U', u'--username',
dest=u'username',
default=os.environ.get(MSSQL_CLI_USER, None),
metavar=u'',
help=u'Username to connect to the database')
help=_(u'Username to connect to the database'))

args_parser.add_argument(
u'-P', u'--password',
dest=u'password',
default=os.environ.get(MSSQL_CLI_PASSWORD, None),
metavar=u'',
help=u'If not supplied, defaults to value in environment variable MSSQL_CLI_PASSWORD.')
help=_(u'If not supplied, defaults to value in environment variable MSSQL_CLI_PASSWORD.'))

args_parser.add_argument(
u'-d', u'--database',
dest=u'database',
default=os.environ.get(MSSQL_CLI_DATABASE, None),
metavar=u'',
help=u'database name to connect to.')
help=_(u'Database name to connect to'))

args_parser.add_argument(
u'-S', u'--server',
dest=u'server',
default=os.environ.get(MSSQL_CLI_SERVER, u'localhost'),
metavar=u'',
help=u'SQL Server instance name or address.')
help=_(u'SQL Server instance name or address.'))

args_parser.add_argument(
u'-E', u'--integrated',
dest=u'integrated_auth',
action=u'store_true',
default=False,
help=u'Use integrated authentication on windows.')
help=_(u'Use integrated authentication on windows.'))

args_parser.add_argument(
u'-v', u'--version',
dest=u'version',
action=u'store_true',
default=False,
help=u'Version of mssql-cli.')
help=_(u'Version of mssql-cli'))

args_parser.add_argument(
u'--mssqlclirc',
dest=u'mssqlclirc_file',
default=os.environ.get(MSSQL_CLI_RC, config_location() + 'config'),
metavar=u'',
help=u'Location of mssqlclirc config file.')
help=_(u'Location of mssqlclirc config file'))

args_parser.add_argument(
u'--row-limit',
dest=u'row_limit',
default=os.environ.get(MSSQL_CLI_ROW_LIMIT, None),
metavar=u'',
help=u'Set threshold for row limit prompt. Use 0 to disable prompt.')
help=_(u'Set threshold for row limit prompt. Use 0 to disable prompt.'))

args_parser.add_argument(
u'--less-chatty',
dest=u'less_chatty',
action=u'store_true',
default=False,
help=u'Skip intro on startup and goodbye on exit.')
help=_(u'Skip intro on startup and goodbye on exit.'))

args_parser.add_argument(
u'--auto-vertical-output',
dest=u'auto_vertical_output',
action=u'store_true',
default=False,
help=u'Automatically switch to vertical output mode if the result is wider than the terminal width.')
help=_(u'Automatically switch to vertical output mode if the result is wider than the terminal width.'))

args_parser.add_argument(
u'-N', u'--encrypt',
dest=u'encrypt',
action=u'store_true',
default=False,
help=u'SQL Server uses SSL encryption for all data if the server has a certificate installed.')
help=_(u'SQL Server uses SSL encryption for all data if the server has a certificate installed.'))

args_parser.add_argument(
u'-C', u'--trust-server-certificate',
dest=u'trust_server_certificate',
action=u'store_true',
default=False,
help=u'The channel will be encrypted while bypassing walking the certificate chain to validate trust.')
help=_(u'The channel will be encrypted while bypassing walking the certificate chain to validate trust.'))

args_parser.add_argument(
u'-l', u'--connect-timeout',
dest=u'connection_timeout',
default=0,
metavar=u'',
help=u'Time in seconds to wait for a connection to the server before terminating request.')
help=_(u'Time in seconds to wait for a connection to the server before terminating request.'))

args_parser.add_argument(
u'-K', u'--application-intent',
dest=u'application_intent',
metavar=u'',
help=u'Declares the application workload type when connecting to a database in a SQL Server Availability Group.')
help=_(u'Declares the application workload type when connecting to a database in a SQL Server Availability Group.'))

args_parser.add_argument(
u'-M', u'--multi-subnet-failover',
dest=u'multi_subnet_failover',
action=u'store_true',
default=False,
help=u'If application is connecting to AlwaysOn AG on different subnets, setting this provides faster '
u'detection and connection to currently active server.')
help=_(u'If application is connecting to AlwaysOn AG on different subnets, setting this provides faster \
detection and connection to currently active server.'))

args_parser.add_argument(
u'-a', u'--packet-size',
dest=u'packet_size',
default=0,
metavar=u'',
help=u'Size in bytes of the network packets used to communicate with SQL Server.')
help=_(u'Size in bytes of the network packets used to communicate with SQL Server.'))

args_parser.add_argument(
u'-A', u'--dac-connection',
dest=u'dac_connection',
action=u'store_true',
default=False,
help=u'Connect to SQL Server using the dedicated administrator connection.')
help=_(u'Connect to SQL Server using the dedicated administrator connection.'))

args_parser.add_argument(
u'--enable-sqltoolsservice-logging',
dest=u'enable_sqltoolsservice_logging',
action=u'store_true',
default=False,
help=u'Enables diagnostic logging for the SqlToolsService.')
help=_(u'Enables diagnostic logging for the SqlToolsService.'))

args_parser.add_argument(
u'--prompt',
dest=u'prompt',
metavar=u'',
help=u'Prompt format (Default: \\d> ')
help=_(u'Prompt format (Default: \\d> '))

return args_parser

0 comments on commit 68d0020

Please sign in to comment.