コード例 #1
0
ファイル: frontend.py プロジェクト: e2pluginss/plexnet
    def run(self, argv=sys.argv):
        """Main entry point of the command-line interface.

        :param argv: list of arguments passed on the command-line
        """
        self.parser = OptionParser(usage=self.usage % ('command', '[args]'),
                                   version=self.version)
        self.parser.disable_interspersed_args()
        self.parser.print_help = self._help
        self.parser.add_option('--list-locales',
                               dest='list_locales',
                               action='store_true',
                               help="print all known locales and exit")
        self.parser.add_option('-v',
                               '--verbose',
                               action='store_const',
                               dest='loglevel',
                               const=logging.DEBUG,
                               help='print as much as possible')
        self.parser.add_option('-q',
                               '--quiet',
                               action='store_const',
                               dest='loglevel',
                               const=logging.ERROR,
                               help='print as little as possible')
        self.parser.set_defaults(list_locales=False, loglevel=logging.INFO)

        options, args = self.parser.parse_args(argv[1:])

        # Configure logging
        self.log = logging.getLogger('babel')
        self.log.setLevel(options.loglevel)
        handler = logging.StreamHandler()
        handler.setLevel(options.loglevel)
        formatter = logging.Formatter('%(message)s')
        handler.setFormatter(formatter)
        self.log.addHandler(handler)

        if options.list_locales:
            identifiers = localedata.list()
            longest = max([len(identifier) for identifier in identifiers])
            format = u'%%-%ds %%s' % (longest + 1)
            for identifier in sorted(localedata.list()):
                locale = Locale.parse(identifier)
                output = format % (identifier, locale.english_name)
                print output.encode(
                    sys.stdout.encoding or getpreferredencoding() or 'ascii',
                    'replace')
            return 0

        if not args:
            self.parser.error('no valid command or option passed. '
                              'Try the -h/--help option for more information.')

        cmdname = args[0]
        if cmdname not in self.commands:
            self.parser.error('unknown command "%s"' % cmdname)

        return getattr(self, cmdname)(args[1:])
コード例 #2
0
ファイル: frontend.py プロジェクト: enyst/plexnet
    def run(self, argv=sys.argv):
        """Main entry point of the command-line interface.

        :param argv: list of arguments passed on the command-line
        """
        self.parser = OptionParser(usage=self.usage % ('command', '[args]'),
                                   version=self.version)
        self.parser.disable_interspersed_args()
        self.parser.print_help = self._help
        self.parser.add_option('--list-locales', dest='list_locales',
                               action='store_true',
                               help="print all known locales and exit")
        self.parser.add_option('-v', '--verbose', action='store_const',
                               dest='loglevel', const=logging.DEBUG,
                               help='print as much as possible')
        self.parser.add_option('-q', '--quiet', action='store_const',
                               dest='loglevel', const=logging.ERROR,
                               help='print as little as possible')
        self.parser.set_defaults(list_locales=False, loglevel=logging.INFO)

        options, args = self.parser.parse_args(argv[1:])

        # Configure logging
        self.log = logging.getLogger('babel')
        self.log.setLevel(options.loglevel)
        handler = logging.StreamHandler()
        handler.setLevel(options.loglevel)
        formatter = logging.Formatter('%(message)s')
        handler.setFormatter(formatter)
        self.log.addHandler(handler)

        if options.list_locales:
            identifiers = localedata.list()
            longest = max([len(identifier) for identifier in identifiers])
            format = u'%%-%ds %%s' % (longest + 1)
            for identifier in sorted(localedata.list()):
                locale = Locale.parse(identifier)
                output = format % (identifier, locale.english_name)
                print output.encode(sys.stdout.encoding or
                                    getpreferredencoding() or
                                    'ascii', 'replace')
            return 0

        if not args:
            self.parser.error('no valid command or option passed. '
                              'Try the -h/--help option for more information.')

        cmdname = args[0]
        if cmdname not in self.commands:
            self.parser.error('unknown command "%s"' % cmdname)

        return getattr(self, cmdname)(args[1:])
コード例 #3
0
def set_available_locales():
    """Set available locales for which we have translations"""
    global AVAILABLE_LOCALES
    locales=['en', 'en_US'] # these are available without translations
    for locale in localedata.list():
        if gettext.find('mediagoblin', TRANSLATIONS_PATH, [locale]):
            locales.append(locale)
    AVAILABLE_LOCALES = locales
コード例 #4
0
def set_available_locales():
    """Set available locales for which we have translations"""
    global AVAILABLE_LOCALES
    locales = ['en', 'en_US']  # these are available without translations
    for locale in localedata.list():
        if gettext.find('mediagoblin', TRANSLATIONS_PATH, [locale]):
            locales.append(locale)
    AVAILABLE_LOCALES = locales
コード例 #5
0
ファイル: main.py プロジェクト: mbchiorean/appengfun
    def get(self):
        
        locals = localedata.list()
        ll = [ Locale(loc) for loc in locals if Locale(loc).display_name != None ]
        ll.sort(key=lambda x: x.english_name)
        user = users.get_current_user()
        usrlocale = UserLocale.gql("WHERE user = :u", u=user).get()
        if usrlocale:
            if usrlocale.dateformat != '' or usrlocale.dateformat != None:
                customdateformat = usrlocale.dateformat
        else:
            customdateformat = None

        context = {'locales':ll,
                   'customdateformat':customdateformat
                   }
        self.render_response('changelocale.html', **context)
コード例 #6
0
ファイル: utils.py プロジェクト: UfSoft/trac-l10n-manager
def _build_locales():
    locales = map(Locale.parse, localedata.list())
    for locale in locales:
        if str(locale) not in AVAILABLE_LOCALES:
            AVAILABLE_LOCALES[str(locale)] = (
                str(locale), locale.english_name, locale.display_name)
コード例 #7
0
ファイル: static.py プロジェクト: Cowoop/cowspa3
import glob
import os
from operator import itemgetter
from pytz import common_timezones
from babel import Locale, localedata

#TODO : Static list of resources won't work for long. Need a way for users to
#       create own resource types apart from system default
resource_types = [dict(name='room', label='Room'), dict(name='phone', label='Phone'), 
        dict(name='printer', label='Printer'), dict(name='other', label='Other')]

#language_map = dict((lang.name, lang.alpha2) for lang in pycountry.languages if hasattr(lang, 'alpha2'))
#languages = [dict(label='English',name=language_map['English']), dict(label='German', name=language_map['German'])]

languages = [dict(name=locale, label=Locale.parse(locale).english_name) for
            locale in [l for l in localedata.list() if Locale.parse(l).english_name is not None]]
languages.sort(key=itemgetter('label'))

countries = [dict(label=country.name ,name=country.numeric) for country in list(pycountry.countries)]
countries_map = dict((country.numeric,country.name) for country in list(pycountry.countries))

currencies = [dict(name=currency.letter ,label=currency.name) for currency in list(pycountry.currencies)]

timezones = [dict(name=el,label=el) for el in common_timezones]

themeroot = 'fe/src/themes'
themedirs = [os.path.basename(name) for name in glob.glob(themeroot + '/*') if os.path.isdir(name)]
themedirs.remove('base')

def themedict(themedir):
    manifest_path = os.path.join(themeroot, themedir, 'manifest')