当前位置: 首页>>代码示例>>Python>>正文


Python locales.getLocale函数代码示例

本文整理汇总了Python中zope.i18n.locales.locales.getLocale函数的典型用法代码示例。如果您正苦于以下问题:Python getLocale函数的具体用法?Python getLocale怎么用?Python getLocale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getLocale函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_locale_dates

def get_locale_dates(request=_marker, locale=_marker):
    """Return the date formatter given the request.
    """
    local_info = locale
    if local_info is _marker:
        local_info = get_locale_info(request)
    try:
        return locales.getLocale(*local_info.split('-')).dates
    except LoadLocaleError:
        return locales.getLocale('en').dates
开发者ID:infrae,项目名称:z3locales,代码行数:10,代码来源:__init__.py

示例2: first_weekday_setup

def first_weekday_setup(context):
    """Set the first day of the week based on the portal's locale.
    """
    reg = getUtility(IRegistry)
    if reg.get('plone.first_weekday') is not None:
        # don't overwrite if it's already set
        return

    first = 6
    try:
        site = getSite()
        # find the locale implied by the portal's language
        language = site.Language()
        parts = (language.split('-') + [None, None])[:3]
        locale = locales.getLocale(*parts)
        # look up first day of week
        gregorian_calendar = locale.dates.calendars.get(u'gregorian', None)
        if gregorian_calendar is not None:
            day = gregorian_calendar.week.get('firstDay', 7)
            first = 6 if day == 0 else day - 1
    except LoadLocaleError:
        # If we cannot get the locale, just Sunday as first weekday
        pass

    # save setting
    reg['plone.first_weekday'] = first
开发者ID:mingtak,项目名称:Products.CMFPlone_for_tpa,代码行数:26,代码来源:setuphandlers.py

示例3: first_weekday_setup

def first_weekday_setup(context):
    """Set the first day of the week based on the portal's locale.
    """
    reg = getUtility(IRegistry)
    settings = reg.forInterface(IEventSettings, prefix="plone.app.event")
    if settings.first_weekday is not None:
        # don't overwrite if it's already set
        return

    first = 6
    try:
        site = getSite()
        # find the locale implied by the portal's language
        language = site.Language()
        parts = (language.split('-') + [None, None])[:3]
        locale = locales.getLocale(*parts)
        # look up first day of week
        gregorian_calendar = locale.dates.calendars.get(u'gregorian', None)
        if gregorian_calendar is not None:
            first = wkday_to_mon0(gregorian_calendar.week.get('firstDay', 7))
    except LoadLocaleError:
        # If we cannot get the locale, just Sunday as first weekday
        pass
    # save setting
    settings.first_weekday = first
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:25,代码来源:setuphandlers.py

示例4: folderitems

    def folderitems(self):
        mtool = getToolByName(self.context, 'portal_membership')
        member = mtool.getAuthenticatedMember()
        roles = member.getRoles()
        self.allow_edit = 'LabManager' in roles or 'Manager' in roles

        items = BikaListingView.folderitems(self)
        for x in range(len(items)):
            if not items[x].has_key('obj'):
                continue
            obj = items[x]['obj']

            cat = obj.getCategoryTitle()
            # Category (upper C) is for display column value
            items[x]['Category'] = cat
            if self.do_cats:
                # category is for bika_listing to groups entries
                items[x]['category'] = cat
                if cat not in self.categories:
                    self.categories.append(cat)

            analyses = [a.UID() for a in self.field_value]
            items[x]['selected'] = items[x]['uid'] in analyses

            items[x]['class']['Title'] = 'service_title'

            calculation = obj.getCalculation()
            items[x]['Calculation'] = calculation and calculation.Title()

            locale = locales.getLocale('en')
            currency = self.context.bika_setup.getCurrency()
            symbol = locale.numbers.currencies[currency].symbol
            items[x]['Price'] = "%s %s" % (symbol, obj.getPrice())
            items[x]['class']['Price'] = 'nowrap'

            after_icons = ''
            if obj.getAccredited():
                after_icons += "<img\
                    src='%s/++resource++bika.lims.images/accredited.png'\
                    title='%s'>" % (self.context.absolute_url(),
                                    _("Accredited"))
            if obj.getReportDryMatter():
                after_icons += "<img\
                    src='%s/++resource++bika.lims.images/dry.png'\
                    title='%s'>" % (self.context.absolute_url(),
                                    _("Can be reported as dry matter"))
            if obj.getAttachmentOption() == 'r':
                after_icons += "<img\
                    src='%s/++resource++bika.lims.images/attach_reqd.png'\
                    title='%s'>" % (self.context.absolute_url(),
                                    _("Attachment required"))
            if obj.getAttachmentOption() == 'n':
                after_icons += "<img\
                    src='%s/++resource++bika.lims.images/attach_no.png'\
                    title='%s'>" % (self.context.absolute_url(),
                                    _('Attachment not permitted'))
            if after_icons:
                items[x]['after']['Title'] = after_icons

        return items
开发者ID:rockfruit,项目名称:bika.sanbi,代码行数:60,代码来源:projectanalyseswidget.py

示例5: currency_format

def currency_format(context, locale):
    locale = locales.getLocale(locale)
    currency = context.bika_setup.getCurrency()
    symbol = locale.numbers.currencies[currency].symbol
    def format(val):
        return '%s %0.2f' % (symbol, val)
    return format
开发者ID:ChamaraPhilipsuom,项目名称:Bika-LIMS,代码行数:7,代码来源:__init__.py

示例6: _set_language_de

    def _set_language_de(self):
        """This Function is used to set the language of the plone site.
        We need this, because we wan't to make sure that the language is
        inherited when there isn't one forced.
        """
        locale = locales.getLocale('de')
        target_language = locale.id.language

        # If we get a territory, we enable the combined language codes
        use_combined = False
        if locale.id.territory:
            use_combined = True
            target_language += '_' + locale.id.territory

            # As we have a sensible language code set now, we disable the
            # start neutral functionality

        tool = getToolByName(self.portal, "portal_languages")

        tool.manage_setLanguageSettings(
            target_language,
            [target_language],
            setUseCombinedLanguageCodes=use_combined,
            startNeutral=False)
        transaction.commit()
开发者ID:4teamwork,项目名称:ftw.subsite,代码行数:25,代码来源:test_forcelanguage.py

示例7: get_locale

def get_locale(request):
    """
    return locale based on HTTP request header ACCEPT_LANGUAGES.

    We need languages to get locale, and the locale on the request
    object gets this wrong (removes territory part of locale). This
    does essentially what ZPublisher.HTTPRequest does to load a
    locale, but with a fixed (predictable, correct) adapter.

    zope.publisher.browser.BrowserLangauges is an adapter with
    fixed behavior to correctly get languages.  Other adapters in
    Plone packages (e.g. PTSLanguages) may interfere with
    ZPublisher.HTTPRequest.locales loading territory, so we prefer
    a fixed adapter rather than an adapter looked-up by registration
    via IUserPreferredLanguages.
    """
    locale = None
    languages = BrowserLanguages(request).getPreferredLanguages()
    for lang in languages:
        parts = (lang.split("-") + [None, None])[:3]
        try:
            locale = locales.getLocale(*parts)
            break
        except LoadLocaleError:
            pass
    return locale
开发者ID:upiq,项目名称:uu.smartdate,代码行数:26,代码来源:locale.py

示例8: getLocale

def getLocale(request):
    envadapter = IUserPreferredLanguages(request, None)
    if envadapter is None:
        return None

    langs = envadapter.getPreferredLanguages()
    for httplang in langs:
        parts = (httplang.split('-') + [None, None])[:3]
        try:
            return locales.getLocale(*parts)
        except LoadLocaleError:
            # Just try the next combination
            pass
    else:
        # No combination gave us an existing locale, so use the default,
        # which is guaranteed to exist
        return locales.getLocale(None, None, None)
开发者ID:goschtl,项目名称:zope,代码行数:17,代码来源:form.py

示例9: _get_locales_info

def _get_locales_info(portal):
    language = portal.Language()
    parts = (language.split('-') + [None, None])[:3]
    locale = locales.getLocale(*parts)

    # If we get a territory, we enable the combined language codes
    if locale.id.territory:
        return locale.id.language + '_' + locale.id.territory, True, locale

    return locale.id.language, False, locale
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:10,代码来源:setuphandlers.py

示例10: formatDateTime

 def formatDateTime(self, instance, dt):
     if not dt:
         return u''
     dt = timezoneAdjuster(instance, dt)
     site = self._site(instance)
     locale = ILocaleFactory(site)
     locale = locales.getLocale(locale, locale)
     if not self.show_hm:
         return ltimefmt(dt, locale, category="date", length="short")
     return ltimefmt(dt, locale, category="dateTime", length="short")
开发者ID:collective,项目名称:Products.IntelliDateTime,代码行数:10,代码来源:widget.py

示例11: setupLocale

    def setupLocale(self):
        envadapter = IUserPreferredLanguages(self, None)
        if envadapter is None:
            self._locale = None
            return

        langs = envadapter.getPreferredLanguages()
        for httplang in langs:
            parts = (httplang.split("-") + [None, None])[:3]
            try:
                self._locale = locales.getLocale(*parts)
                return
            except LoadLocaleError:
                # Just try the next combination
                pass
        else:
            # No combination gave us an existing locale, so use the default,
            # which is guaranteed to exist
            self._locale = locales.getLocale(None, None, None)
开发者ID:pigaov10,项目名称:plone4.3,代码行数:19,代码来源:http.py

示例12: _get_locales_info

def _get_locales_info(portal):
    language = portal.Language()
    parts = (language.split('-') + [None, None])[:3]
    locale = locales.getLocale(*parts)
    # If we get a territory, we enable the combined language codes
    use_combined = False
    if locale.id.territory:
        use_combined = True
        target_language += '_' + locale.id.territory
    return locale.id.language, use_combined, locale
开发者ID:tisto,项目名称:plone.app.contenttypes,代码行数:10,代码来源:setuphandlers.py

示例13: setup_language

def setup_language(portal):
    """When installing plone, the language is set when creating
    example content.
    If the content creation profile ``Products.CMFPlone:plone-content``
    is not installed, the lanuage is not set up properly.

    This setup handler allows to only setup the language but not
    create example content by putting a ``inflator-setup-language.txt``
    in a generic setup profile which is used on initialization.

    The code of this function is copied from
    ``Products.CMFPlone.setuphandlers.setupPortalContent``.
    """
    language = portal.Language()
    parts = (language.split('-') + [None, None])[:3]
    locale = locales.getLocale(*parts)
    target_language = base_language = locale.id.language

    # If we get a territory, we enable the combined language codes
    use_combined = False
    if locale.id.territory:
        use_combined = True
        target_language += '_' + locale.id.territory

    # As we have a sensible language code set now, we disable the
    # start neutral functionality
    tool = getToolByName(portal, "portal_languages")

    tool.manage_setLanguageSettings(language,
        [language],
        setUseCombinedLanguageCodes=use_combined,
        startNeutral=False)

    # Set the first day of the week, defaulting to Sunday, as the
    # locale data doesn't provide a value for English. European
    # languages / countries have an entry of Monday, though.
    calendar = getToolByName(portal, "portal_calendar", None)
    if calendar is not None:
        first = 6
        gregorian = locale.dates.calendars.get(u'gregorian', None)
        if gregorian is not None:
            first = gregorian.week.get('firstDay', None)
            # on the locale object we have: mon : 1 ... sun : 7
            # on the calendar tool we have: mon : 0 ... sun : 6
            if first is not None:
                first = first - 1

        calendar.firstweekday = first

    # Enable visible_ids for non-latin scripts

    # See if we have an url normalizer
    normalizer = queryUtility(IURLNormalizer, name=target_language)
    if normalizer is None:
        normalizer = queryUtility(IURLNormalizer, name=base_language)
开发者ID:erral,项目名称:ftw.inflator,代码行数:55,代码来源:hooks.py

示例14: __call__

 def __call__(self):
     context = self.context
     workflow = getToolByName(context, 'portal_workflow')
     # Gather relted objects
     batch = context.aq_parent
     client = context.getClient()
     analysis_request = context.getAnalysisRequest() if context.getAnalysisRequest() else None
     # Gather general data
     self.invoiceId = context.getId()
     self.invoiceDate = self.ulocalized_time(context.getInvoiceDate())
     self.subtotal = '%0.2f' % context.getSubtotal()
     self.VATAmount = '%0.2f' % context.getVATAmount()
     self.total = '%0.2f' % context.getTotal()
     # Create the batch range
     start = self.ulocalized_time(batch.getBatchStartDate())
     end = self.ulocalized_time(batch.getBatchEndDate())
     self.batchRange = "%s to %s" % (start, end)
     # Gather client data
     self.clientName = client.Title()
     self.clientURL = client.absolute_url()
     self.clientPhone = client.getPhone()
     self.clientFax = client.getFax()
     self.clientEmail = client.getEmailAddress()
     self.clientAccountNumber = client.getAccountNumber()
     # currency info
     locale = locales.getLocale('en')
     self.currency = self.context.bika_setup.getCurrency()
     self.symbol = locale.numbers.currencies[self.currency].symbol
     # Get an available client address in a preferred order
     self.clientAddress = None
     # A list with the items and its invoice values to render in template
     self.items = []
     addresses = (
         client.getBillingAddress(),
         client.getPostalAddress(),
         client.getPhysicalAddress(),
     )
     for address in addresses:
         if address.get('address'):
             self.clientAddress = address
             break
     # Gather the line items
     items = context.invoice_lineitems
     for item in items:
         invoice_data = {
             'invoiceDate': self.ulocalized_time(item.get('ItemDate', '')),
             'description': item.get('ItemDescription', ''),
             'orderNo': item.get('OrderNumber', ''),
             'subtotal': '%0.2f' % item.get('Subtotal', ''),
             'VATAmount': '%0.2f' % item.get('VATAmount', ''),
             'total': '%0.2f' % item.get('Total', ''),
         }
         self.items.append(invoice_data)
     # Render the template
     return self.template()
开发者ID:andersonsmith,项目名称:bika.lims,代码行数:55,代码来源:invoice.py

示例15: _get_locales_info

def _get_locales_info(portal):
    reg = queryUtility(IRegistry, context=portal)
    language = reg['plone.default_language']
    parts = (language.split('-') + [None, None])[:3]
    locale = locales.getLocale(*parts)

    # If we get a territory, we enable the combined language codes
    if locale.id.territory:
        return locale.id.language + '_' + locale.id.territory, True, locale

    return locale.id.language, False, locale
开发者ID:instification,项目名称:plone.app.contenttypes,代码行数:11,代码来源:setuphandlers.py


注:本文中的zope.i18n.locales.locales.getLocale函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。