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


Python utils.to_language函数代码示例

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


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

示例1: test_extract

 def test_extract(self):
     obj, doc = self._get_doc()
     eq_(doc['id'], obj.id)
     eq_(doc['guid'], obj.guid)
     eq_(doc['app_slug'], obj.app_slug)
     eq_(doc['category'], [])
     eq_(doc['default_locale'], obj.default_locale)
     eq_(doc['description'], list(
         set(s for _, s in obj.translations[obj.description_id])))
     eq_(doc['description_translations'],
         [{'lang': to_language(l), 'string': s}
          for l, s in obj.translations[obj.description_id]])
     eq_(doc['device'], [])
     eq_(doc['name'], list(
         set(s for _, s in obj.translations[obj.name_id])))
     eq_(doc['name_translations'],
         [{'lang': to_language(l), 'string': s}
          for l, s in obj.translations[obj.name_id]])
     eq_(doc['promo_img_hash'], obj.promo_img_hash)
     eq_(doc['status'], obj.status)
     eq_(doc['trending'], 0)
     eq_(doc['is_escalated'], False)
     eq_(doc['latest_version']['status'], mkt.STATUS_PUBLIC)
     eq_(doc['latest_version']['has_editor_comment'], False)
     eq_(doc['latest_version']['has_info_request'], False)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:25,代码来源:test_indexers.py

示例2: parse

    def parse(self):
        """Parse archive and return extension data as expected by the models.

        May raise forms.ValidationError."""
        raw_data = self.manifest_contents
        data = {}

        required_fields = ('name', 'version')
        for field in required_fields:
            if not raw_data.get(field):
                raise forms.ValidationError(
                    _(u'The "%s" field is missing or empty in the'
                      u' add-on manifest.' % field))
            data[field] = raw_data[field]

        extra_fields = ('description',)
        for field in extra_fields:
            if field in raw_data:
                data[field] = raw_data[field]

        default_locale = raw_data.get('default_locale')
        if default_locale:
            # We actually need language (e.g. "en-US") for translations, not
            # locale (e.g. "en_US"). The extension contains locales though, not
            # languages, so transform the field in the manifest before adding
            # it to the data we'll pass to the model.
            data['default_language'] = to_language(default_locale)

        data['manifest'] = self.manifest_contents
        return data
开发者ID:demagu-sr,项目名称:zamboni,代码行数:30,代码来源:utils.py

示例3: get_mail_context

def get_mail_context(note):
    """
    Get context data for comm emails, specifically for review action emails.
    """
    app = note.thread.webapp

    if app.name and app.name.locale != app.default_locale:
        # We need to display the name in some language that is relevant to the
        # recipient(s) instead of using the reviewer's. webapp.default_locale
        # should work.
        lang = to_language(app.default_locale)
        with translation.override(lang):
            app = Webapp.with_deleted.get(id=app.id)
    elif not app.name:
        # For deleted apps.
        app.name = app.app_slug

    return {
        'mkt': mkt,
        'app': app,
        'comm': comm,
        'note': note,
        'review_url': absolutify(reverse('reviewers.apps.review',
                                 args=[app.app_slug])),
        'settings': settings
    }
开发者ID:shahbaz17,项目名称:zamboni,代码行数:26,代码来源:utils_mail.py

示例4: get_mail_context

def get_mail_context(note, user_id):
    """
    Get context data for comm emails, specifically for review action emails.
    """
    obj = note.thread.obj

    # grep: comm-content-type.
    if obj.name and obj.__class__ == Webapp:
        # We need to display the name in some language that is relevant to the
        # recipient(s) instead of using the reviewer's. addon.default_locale
        # should work.
        lang = to_language(obj.default_locale)
        with translation.override(lang):
            obj = Webapp.with_deleted.get(id=obj.id)
    elif not obj.name:
        # For deleted objects.
        obj.name = obj.app_slug if hasattr(obj, 'app_slug') else obj.slug

    if user_id:
        UserProfile.objects.get(id=user_id)

    # grep: comm-content-type.
    manage_url = ''
    obj_type = ''
    thread_url = ''
    if obj.__class__ == Webapp:
        manage_url = absolutify(obj.get_dev_url('versions'))
        obj_type = 'app'
        thread_url = absolutify(reverse('commonplace.commbadge.show_thread',
                                        args=[note.thread.id]))
    elif obj.__class__ == Extension:
        manage_url = absolutify(reverse('commonplace.content.addon_manage',
                                        args=[obj.slug]))
        # Not "Firefox OS add-on" for a/an consistency with "app".
        obj_type = 'add-on'
        if user_id:
            user = UserProfile.objects.get(id=user_id)
            if acl.action_allowed_user(user, 'ContentTools', 'AddonReview'):
                thread_url = absolutify(
                    reverse('commonplace.content.addon_review',
                            args=[obj.slug]))
            else:
                thread_url = manage_url

    return {
        'mkt': mkt,
        'comm': comm,
        'is_app': obj.__class__ == Webapp,
        'is_extension': obj.__class__ == Extension,
        'manage_url': manage_url,
        'note': note,
        'obj': obj,
        'obj_type': obj_type,
        'settings': settings,
        'thread_url': thread_url
    }
开发者ID:Witia1,项目名称:zamboni,代码行数:56,代码来源:utils_mail.py

示例5: localized_properties

    def localized_properties(self):
        props = {}

        for attr in ('name', 'description'):
            tr_object = getattr(self.webapp, attr)
            for tr in Translation.objects.filter(id=tr_object.id):
                language = to_language(tr.locale)
                props.setdefault(language, {})
                props[language][attr] = tr.localized_string

        return props
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:11,代码来源:webpay_jwt.py

示例6: test_extract

 def test_extract(self):
     obj, doc = self._get_doc()
     eq_(doc["id"], obj.id)
     eq_(doc["guid"], obj.guid)
     eq_(doc["app_slug"], obj.app_slug)
     eq_(doc["category"], [])
     eq_(doc["default_locale"], obj.default_locale)
     eq_(doc["description"], list(set(s for _, s in obj.translations[obj.description_id])))
     eq_(
         doc["description_translations"],
         [{"lang": to_language(l), "string": s} for l, s in obj.translations[obj.description_id]],
     )
     eq_(doc["device"], [])
     eq_(doc["name"], list(set(s for _, s in obj.translations[obj.name_id])))
     eq_(doc["name_translations"], [{"lang": to_language(l), "string": s} for l, s in obj.translations[obj.name_id]])
     eq_(doc["status"], obj.status)
     eq_(doc["trending"], 0)
     eq_(doc["is_escalated"], False)
     eq_(doc["latest_version"]["status"], mkt.STATUS_PUBLIC)
     eq_(doc["latest_version"]["has_editor_comment"], False)
     eq_(doc["latest_version"]["has_info_request"], False)
开发者ID:Hitechverma,项目名称:zamboni,代码行数:21,代码来源:test_indexers.py

示例7: set_default_locale

 def set_default_locale(self, instance, row):
     lang = to_language(self.clean_string(row['Language of Meta Data']))
     if not lang or lang == 'english':
         # Exception because 'en-US' is set as 'English (US)'.
         lang = 'en-US'
     elif lang == 'chinese':
         # Consider 'chinese' without more information as simplified
         # chinese, zh-CN.
         lang = 'zh-CN'
     elif lang == 'portuguese':
         # We don't support pt-PT in Marketplace, use pt-BR.
         lang = 'pt-BR'
     if lang not in self.languages:
         lang = self.reversed_languages.get(lang)
         if lang is None:
             raise ParsingError(
                 u'Website %s has unknown language set for its metadata: %s'
                 % (row['Unique Moz ID'], row['Language of Meta Data']))
     instance.default_locale = lang
开发者ID:ujdhesa,项目名称:zamboni,代码行数:19,代码来源:import_websites_from_csv.py

示例8: get_context_data

 def get_context_data(self):
     # We need to display the name in some language that is relevant to the
     # recipient(s) instead of using the reviewer's. addon.default_locale
     # should work.
     if self.addon.name.locale != self.addon.default_locale:
         lang = to_language(self.addon.default_locale)
         with translation.override(lang):
             app = Webapp.objects.get(id=self.addon.id)
     else:
         app = self.addon
     return {'name': app.name,
             'reviewer': self.request.user.name,
             'detail_url': absolutify(
                 app.get_url_path()),
             'review_url': absolutify(reverse('reviewers.apps.review',
                                              args=[app.app_slug])),
             'status_url': absolutify(app.get_dev_url('versions')),
             'comments': self.data['comments'],
             'MKT_SUPPORT_EMAIL': settings.MKT_SUPPORT_EMAIL,
             'SITE_URL': settings.SITE_URL}
开发者ID:JaredKerim-Mozilla,项目名称:zamboni,代码行数:20,代码来源:utils.py

示例9: extract_manifest_fields

    def extract_manifest_fields(cls, manifest_data, fields=None):
        """Extract the specified `fields` from `manifest_data`, applying
        transformations if necessary. If `fields` is absent, then use
        `cls.manifest_is_source_of_truth_fields`."""
        if fields is None:
            fields = cls.manifest_is_source_of_truth_fields
        data = {k: manifest_data[k] for k in fields if k in manifest_data}

        # Determine default language to use for translations.
        # Web Extensions Manifest contains locales (e.g. "en_US"), not
        # languages (e.g. "en-US"). The field is also called differently as a
        # result (default_locale vs default_language), so we need to transform
        # both the key and the value before adding it to data. A default value
        # needs to be set to correctly generate the translated fields below.
        default_language = to_language(manifest_data.get(
            'default_locale', cls._meta.get_field('default_language').default))
        if 'default_language' in fields:
            data['default_language'] = default_language

        # Be nice and strip leading / trailing whitespace chars from
        # strings.
        for key, value in data.items():
            if isinstance(value, basestring):
                data[key] = value.strip()

        # Translated fields should not be extracted as simple strings,
        # otherwise we end up setting a locale on the translation that is
        # dependent on the locale of the thread. Use dicts instead, always
        # setting default_language as the language for now (since we don't
        # support i18n in web extensions yet).
        for field in cls._meta.translated_fields:
            field_name = field.name
            if field_name in data:
                data[field_name] = {
                    default_language: manifest_data[field_name]
                }

        return data
开发者ID:elysium001,项目名称:zamboni,代码行数:38,代码来源:models.py

示例10: from_upload

    def from_upload(cls, upload, user=None, instance=None):
        """Handle creating/editing the Extension instance and saving it to db,
        as well as file operations, from a FileUpload instance. Can throw
        a ValidationError or SigningError, so should always be called within a
        try/except."""
        if instance is not None:
            # Not implemented yet. Need to deal with versions correctly, we
            # don't know yet if we want to keep older versions around or not,
            # how status changes etc.
            raise NotImplementedError

        parser = ExtensionParser(upload, instance=instance)
        data = parser.parse()
        fields = ('version', 'name', 'default_language')
        default_locale = data.get('default_locale')

        if default_locale:
            # We actually need language (en-US) for translations, not locale
            # (en_US). The extension contains locales though, so transform the
            # field in the manifest before storing in db.
            data['default_language'] = to_language(default_locale)

        # Filter out parsing results to only keep fields we store in db.
        data = dict((k, v) for k, v in data.items() if k in fields)

        # Build a new instance.
        instance = cls(**data)
        instance.manifest = parser.manifest_contents
        instance.save()

        # Now that the instance has been saved, we can add the author,
        # generate a file path, move the file and set it to PENDING.
        instance.authors.add(user)
        instance.handle_file_operations(upload)
        instance.update(status=STATUS_PENDING)
        return instance
开发者ID:shahbaz17,项目名称:zamboni,代码行数:36,代码来源:models.py

示例11: fetch_all_translations

 def fetch_all_translations(self, obj, source, field):
     translations = field.__class__.objects.filter(id=field.id, localized_string__isnull=False)
     return dict((to_language(trans.locale), unicode(trans)) for trans in translations) if translations else None
开发者ID:waseem18,项目名称:zamboni,代码行数:3,代码来源:fields.py

示例12: extract_document


#.........这里部分代码省略.........
                         for p in obj.previews.all()]
        try:
            p = obj.addonpremium.price
            d['price_tier'] = p.name
        except AddonPremium.DoesNotExist:
            d['price_tier'] = None

        d['ratings'] = {
            'average': obj.average_rating,
            'count': obj.total_reviews,
        }
        d['region_exclusions'] = obj.get_excluded_region_ids()
        d['reviewed'] = obj.versions.filter(
            deleted=False).aggregate(Min('reviewed')).get('reviewed__min')
        if version:
            d['supported_locales'] = filter(
                None, version.supported_locales.split(','))
        else:
            d['supported_locales'] = []

        d['tags'] = getattr(obj, 'tag_list', [])
        if obj.upsell and obj.upsell.premium.is_published():
            upsell_obj = obj.upsell.premium
            d['upsell'] = {
                'id': upsell_obj.id,
                'app_slug': upsell_obj.app_slug,
                'icon_url': upsell_obj.get_icon_url(128),
                # TODO: Store all localizations of upsell.name.
                'name': unicode(upsell_obj.name),
                'region_exclusions': upsell_obj.get_excluded_region_ids()
            }

        d['versions'] = [dict(version=v.version,
                              resource_uri=reverse_version(v))
                         for v in obj.versions.all()]

        # Handle our localized fields.
        for field in ('description', 'homepage', 'name', 'support_email',
                      'support_url'):
            d['%s_translations' % field] = [
                {'lang': to_language(lang), 'string': string}
                for lang, string
                in obj.translations[getattr(obj, '%s_id' % field)]
                if string]
        if version:
            attach_trans_dict(Version, [version])
            d['release_notes_translations'] = [
                {'lang': to_language(lang), 'string': string}
                for lang, string
                in version.translations[version.releasenotes_id]]
        else:
            d['release_notes_translations'] = None
        attach_trans_dict(Geodata, [geodata])
        d['banner_message_translations'] = [
            {'lang': to_language(lang), 'string': string}
            for lang, string
            in geodata.translations[geodata.banner_message_id]]

        for region in mkt.regions.ALL_REGION_IDS:
            d['popularity_%s' % region] = d['popularity']

        # Bump the boost if the add-on is public.
        if obj.status == amo.STATUS_PUBLIC:
            d['boost'] = max(d['boost'], 1) * 4

        # If the app is compatible with Firefox OS, push suggestion data in the
        # index - This will be used by RocketbarView API, which is specific to
        # Firefox OS.
        if DEVICE_GAIA.id in d['device'] and obj.is_published():
            d['name_suggest'] = {
                'input': d['name'],
                'output': unicode(obj.id),  # We only care about the payload.
                'weight': d['boost'],
                'payload': {
                    'default_locale': d['default_locale'],
                    'icon_hash': d['icon_hash'],
                    'id': d['id'],
                    'manifest_url': d['manifest_url'],
                    'modified': d['modified'],
                    'name_translations': d['name_translations'],
                    'slug': d['app_slug'],
                }
            }

        # Indices for each language. languages is a list of locales we want to
        # index with analyzer if the string's locale matches.
        for analyzer, languages in amo.SEARCH_ANALYZER_MAP.iteritems():
            if (not settings.ES_USE_PLUGINS and
                analyzer in amo.SEARCH_ANALYZER_PLUGINS):
                continue

            d['name_' + analyzer] = list(
                set(string for locale, string in obj.translations[obj.name_id]
                    if locale.lower() in languages))
            d['description_' + analyzer] = list(
                set(string for locale, string
                    in obj.translations[obj.description_id]
                    if locale.lower() in languages))

        return d
开发者ID:JaredKerim-Mozilla,项目名称:zamboni,代码行数:101,代码来源:indexers.py

示例13: check

 def check(a, b):
     eq_(to_language(a), b)
开发者ID:miltonpereira,项目名称:zamboni,代码行数:2,代码来源:test_utils.py

示例14: trans_locale

 def trans_locale(self, locale):
     return to_language(settings.SHORTER_LANGUAGES.get(locale, locale))
开发者ID:elysium001,项目名称:zamboni,代码行数:2,代码来源:utils.py

示例15: _make_language_choices

def _make_language_choices(languages):
    return [(to_language(lang_code), lang_name)
            for lang_code, lang_name in languages.items()]
开发者ID:Jobava,项目名称:zamboni,代码行数:3,代码来源:models.py


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