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


Python l10n.L10n类代码示例

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


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

示例1: _prepare_error_response

    def _prepare_error_response(self):
        """
Prepares an error response.

:since: v1.0.0
        """

        errors = self.errors
        self.reset()

        if (not self.are_headers_sent):
            self.init(False, True)

            header = self.get_header("HTTP", True)
            if (header is None): self.set_header("HTTP", "HTTP/2.0 500 Internal Server Error", True)
        #

        self.content = ""

        if (errors is None):
            error = { "title": L10n.get("core_title_error"),
                      "message": (L10n.get("errors_core_unknown_error") if (header is None) else header)
                    }

            self.page_title = error['title']

            self.add_oset_content("core.error", error)
        else:
            for error in errors:
                if (self.page_title is None): self.page_title = error['title']
                self.add_oset_content("core.error", error)
开发者ID:dNG-git,项目名称:pas_http_core,代码行数:31,代码来源:http_xhtml_response.py

示例2: _render_table

    def _render_table(self):
        """
Renders the table and returns a (X)HTML table.

:return: (str) XHTML for the rendered table
:since:  v0.2.00
        """

        if (not isinstance(self.table, Abstract)): raise ValueException("Missing table instance to render")
        if (self.table_id is None): self.table_id = "pas_http_table_{0:d}".format(id(self))

        L10n.init("pas_http_table")

        limit = self.table.get_limit()
        row_count = self.table.get_row_count()

        self.pages = (1 if (row_count == 0) else ceil(float(row_count) / limit))

        pages = (self.page_limit if (self.page_limit > 0) else self.pages)
        self.table.set_offset(0 if (self.page < 1 or self.page > pages) else (self.page - 1) * limit)

        if (self.sort_column_key != ""): self.table.add_sort_definition(self.sort_column_key, self.sort_direction)

        if (self.response.is_supported("html_css_files")): self.response.add_theme_css_file("table_sprite.min.css")

        _return = self._render_table_header()
        _return += self._render_table_rows()
        _return += self._render_table_footer()

        return _return
开发者ID:dNG-git,项目名称:pas_http_table,代码行数:30,代码来源:table_mixin.py

示例3: _prepare_error_response

    def _prepare_error_response(self):
        """
Prepares an error response.

:since: v1.0.0
        """

        errors = self.errors
        self.reset()

        if (not self.are_headers_sent):
            self.init(False, True)

            header = self.get_header("HTTP", True)
            if (header is None): self.set_header("HTTP", "HTTP/2.0 500 Internal Server Error", True)
        #

        self.result = ({ "error": { "title": L10n.get("core_title_error"),
                                    "message": (L10n.get("errors_core_unknown_error")
                                                if (header is None) else
                                                header
                                               )
                                  }
                       }
                       if (errors is None) else
                       { "error": ({ "messages": errors }
                                   if (len(errors) > 1) else
                                   errors[0]
                                  )
                       }
                      )
开发者ID:dNG-git,项目名称:pas_http_core,代码行数:31,代码来源:http_json_response.py

示例4: execute_new

	def execute_new(self, is_save_mode = False):
	#
		"""
Action for "new"

:since: v0.1.00
		"""

		form_id = InputFilter.filter_control_chars(self.request.get_dsd("oform_id", "")).strip()
		form_field_id = InputFilter.filter_control_chars(self.request.get_dsd("oform_field_id", "")).strip()

		L10n.init("pas_http_core_form")

		form = FormProcessor(form_id)
		form.set_form_render_id(Binary.str(hexlify(urandom(16))))

		if (is_save_mode): form.set_input_available()

		self._apply_new_form(form)

		if (is_save_mode and form.check()):
		#
			entry_data = self._save_new_form(form)

			form_store = form.get_form_store()
			form_store_dict = form_store.get_value_dict()
			form_store_field_id = "form_api_dynamic_{0}".format(form_field_id)

			entry_list = form_store_dict.get(form_store_field_id, [ ])
			entry_list.append(entry_data)

			form_store_dict[form_store_field_id] = entry_list
			form_store.set_value_dict(form_store_dict)

			self._set_destroy_dom_result()
		#
		else:
		#
			content = { "title": self._get_form_action_new_title(),
			            "on_closed_query": Link().build_url(Link.TYPE_QUERY_STRING, { "__request__": True, "a": "get" })
			          }

			content['form'] = { "object": form,
			                    "url_parameters": { "__request__": True,
			                                        "a": "new-save"
			                                      },
			                    "button_title": "core_continue"
			                  }

			method = (self._set_replace_dom_oset_result
			          if (is_save_mode) else
			          self._set_append_overlay_dom_oset_result
			         )

			method("dynamic_form.overlay", content)
开发者ID:dNG-git,项目名称:pas_http_dynamic_form,代码行数:55,代码来源:abstract.py

示例5: execute_delete

    def execute_delete(self):
        """
Action for "delete"

:since: v0.2.00
        """

        cid = InputFilter.filter_file_path(self.request.get_dsd("mcid", ""))

        source_iline = InputFilter.filter_control_chars(self.request.get_dsd("source", "")).strip()
        target_iline = InputFilter.filter_control_chars(self.request.get_dsd("target", "")).strip()

        if (source_iline == ""): source_iline = "m=mp;a=list_root_containers"
        if (target_iline == ""): target_iline = source_iline

        L10n.init("mp_core")

        session = (self.request.get_session() if (self.request.is_supported("session")) else None)
        user_profile = (None if (session is None) else session.get_user_profile())

        if (user_profile is None
            or (not user_profile.is_type("ad"))
           ): raise TranslatableError("core_access_denied", 403)

        try: mp_entry = MpEntry.load_id(cid)
        except NothingMatchedException as handled_exception: raise TranslatableError("mp_core_cid_invalid", 404, _exception = handled_exception)

        if (self.response.is_supported("html_css_files")): self.response.add_theme_css_file("mini_default_sprite.min.css")

        Link.set_store("servicemenu",
                       Link.TYPE_RELATIVE_URL,
                       L10n.get("core_back"),
                       { "__query__": re.sub("\\_\\_\\w+\\_\\_", "", source_iline) },
                       icon = "mini-default-back",
                       priority = 7
                      )

        if (not DatabaseTasks.is_available()): raise TranslatableException("pas_core_tasks_daemon_not_available")

        mp_entry.delete()

        database_tasks = DatabaseTasks.get_instance()
        database_tasks.add("dNG.pas.upnp.Resource.onDeleted.{0}".format(cid), "dNG.pas.upnp.Resource.onDeleted", 1, container_id = cid)
        database_tasks.add("dNG.pas.upnp.Resource.onRootContainerDeleted.{0}".format(cid), "dNG.pas.upnp.Resource.onRootContainerDeleted", 1, container_id = cid)

        target_iline = re.sub("\\_\\w+\\_\\_", "", target_iline)

        NotificationStore.get_instance().add_completed_info(L10n.get("mp_core_done_root_container_delete"))

        Link.clear_store("servicemenu")

        redirect_request = PredefinedHttpRequest()
        redirect_request.set_iline(target_iline)
        self.request.redirect(redirect_request)
开发者ID:dNG-git,项目名称:mp_core,代码行数:54,代码来源:root_container.py

示例6: init_control_l10n

def init_control_l10n(params, last_return = None):
    """
Called for "dNG.pas.http.l10n.upnp.Control.init"

:param params: Parameter specified
:param last_return: The return value from the last hook called.

:since: v0.2.00
    """

    L10n.init("mp_core")
    return last_return
开发者ID:dNG-git,项目名称:mp_core,代码行数:12,代码来源:mp_core.py

示例7: __init__

    def __init__(self, l10n = None):
        """
Constructor __init__(SecIDUpdatedEMailRenderer)

:param l10n: L10n instance

:since: v0.2.00
        """

        EMailRenderer.__init__(self, l10n)

        L10n.init("pas_http_user", self.l10n.get_lang())
开发者ID:dNG-git,项目名称:pas_http_user,代码行数:12,代码来源:sec_id_updated_email_renderer.py

示例8: handle_error

    def handle_error(self, message):
        """
"handle_error()" is called to send a error message.

:param message: Message (will be translated if possible)

:since: v1.0.0
        """

        message = L10n.get("errors_{0}".format(message), message)

        if (self.errors is None): self.errors = [ { "title": L10n.get("core_title_error"), "message": message } ]
        else: self.errors.append({ "title": L10n.get("core_title_error"), "message": message })
开发者ID:dNG-git,项目名称:pas_http_core,代码行数:13,代码来源:abstract_http_response.py

示例9: execute_logout

    def execute_logout(self):
        """
Action for "logout"

:since: v0.2.00
        """

        source_iline = InputFilter.filter_control_chars(self.request.get_dsd("source", "")).strip()
        target_iline = InputFilter.filter_control_chars(self.request.get_dsd("target", "")).strip()

        if (target_iline == ""):
            if (Settings.is_defined("pas_http_user_logout_default_target_lang_{0}".format(self.request.get_lang()))): target_iline = Settings.get("pas_http_user_logout_default_target_lang_{0}".format(self.request.get_lang()))
            elif (Settings.is_defined("pas_http_user_logout_default_target")): target_iline = Settings.get("pas_http_user_logout_default_target")
            else: target_iline = source_iline
        #

        L10n.init("pas_http_user")

        if (self.response.is_supported("html_css_files")): self.response.add_theme_css_file("mini_default_sprite.min.css")

        Link.set_store("servicemenu",
                       Link.TYPE_RELATIVE_URL,
                       L10n.get("core_back"),
                       { "__query__": re.sub("\\_\\_\\w+\\_\\_", "", source_iline) },
                       icon = "mini-default-back",
                       priority = 7
                      )

        if (not self.request.is_supported("session")): raise TranslatableError("core_unknown_error", 500)

        session = Session.load(session_create = False)

        if (session is not None):
            session.delete()
            self.request.set_session(None)
        #

        Link.clear_store("servicemenu")

        target_iline = re.sub("\\_\\_\\w+\\_\\_", "", target_iline)

        redirect_request = PredefinedHttpRequest()
        redirect_request.set_module("output")
        redirect_request.set_service("http")
        redirect_request.set_action("done")

        redirect_request.set_parameter_chained("title", L10n.get("pas_http_user_logout"))
        redirect_request.set_parameter_chained("message", L10n.get("pas_http_user_done_logout"))
        redirect_request.set_parameter_chained("target_iline", target_iline)

        self.request.redirect(redirect_request)
开发者ID:dNG-git,项目名称:pas_http_user,代码行数:51,代码来源:status.py

示例10: get_view

    def get_view(self):
        """
Action for "view"

:since: v1.0.0
        """

        cid = InputFilter.filter_file_path(self.request.get_parameter("cid", ""))

        source_iline = InputFilter.filter_control_chars(self.request.get_parameter("source", "")).strip()

        L10n.init("pas_http_core_contentfile")

        Settings.read_file("{0}/settings/pas_http_contentfiles.json".format(Settings.get("path_data")))

        contentfiles = Settings.get("pas_http_contentfiles_list", { })
        if (type(contentfiles) is not dict): raise TranslatableError("pas_http_core_contentfile_cid_invalid", 404)

        if (source_iline != ""):
            if (self.response.is_supported("html_css_files")): self.response.add_theme_css_file("mini_default_sprite.css")

            Link.set_store("servicemenu",
                           Link.TYPE_RELATIVE_URL,
                           L10n.get("core_back"),
                           { "__query__": re.sub("\\_\\_\\w+\\_\\_", "", source_iline) },
                           icon = "mini-default-back",
                           priority = 7
                          )
        #

        if (cid not in contentfiles
            or "title" not in contentfiles[cid]
            or "filepath" not in contentfiles[cid]
           ): raise TranslatableError("pas_http_core_contentfile_cid_invalid", 404)

        file_content = FileContent.read(contentfiles[cid]['filepath'])
        if (file_content is None): raise TranslatableError("pas_http_core_contentfile_cid_invalid", 404)

        if (path.splitext(contentfiles[cid]['filepath'])[1].lower() == ".ftg"): file_content = FormTags.render(file_content)

        content = { "title": contentfiles[cid]['title'],
                    "content": file_content
                  }

        self.response.init()
        self.response.page_title = contentfiles[cid]['title']

        self.response.add_oset_content("core.simple_content", content)
开发者ID:dNG-git,项目名称:pas_http_core,代码行数:48,代码来源:contentfile.py

示例11: init_cds_id

    def init_cds_id(self, _id, client_user_agent = None, deleted = False):
        """
Initialize a UPnP resource by CDS ID.

:param _id: UPnP CDS ID
:param client_user_agent: Client user agent
:param update_id: UPnP UpdateID value
:param deleted: True to include deleted resources

:return: (bool) Returns true if initialization was successful.
:since:  v0.2.00
        """

        if (self.log_handler is not None): self.log_handler.debug("#echo(__FILEPATH__)# -{0!r}.init_cds_id({1})- (#echo(__LINE__)#)", self, _id, context = "pas_upnp")
        _return = Abstract.init_cds_id(self, _id, client_user_agent, deleted)

        if (_id == "0"):
            self.name = L10n.get("pas_upnp_container_root")
            self.type = RootContainer.TYPE_CDS_CONTAINER

            search_segments = Hook.call("dNG.pas.upnp.Resource.getSearchSegments", id = _id)
            self.searchable = (type(search_segments) is list and len(search_segments) > 0)
        else: _return = True

        return _return
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:25,代码来源:root_container.py

示例12: render_rewrite_date_time_xhtml

    def render_rewrite_date_time_xhtml(self, source, key, _type):
        """
Renders a date and time XHTML 5 tag based on the given presentation type.

:param source: Source for rewrite
:param key: Key in source for rewrite
:param _type: Presentation type

:return: (str) Rewritten statement if successful
:since:  v1.0.0
        """

        if (self._log_handler is not None): self._log_handler.debug("#echo(__FILEPATH__)# -{0!r}.render_rewrite_date_time_xhtml({1}, {2})- (#echo(__LINE__)#)", self, key, _type, context = "pas_tag_parser")
        _return = L10n.get("core_unknown")

        timestamp = self.get_source_value(source, key)

        if (timestamp is not None):
            time_attributes = { "tag": "time", "attributes": { "datetime": "{0}+00:00".format(RfcBasics.get_iso8601_datetime(timestamp)) } }

            _return = "{0}{1}</time>".format(XmlParser().dict_to_xml_item_encoder(time_attributes, False),
                                             self.render_rewrite_date_time(source, key, _type)
                                            )
        #

        return _return
开发者ID:dNG-git,项目名称:pas_http_core,代码行数:26,代码来源:rewrite_date_time_xhtml_mixin.py

示例13: execute_services

    def execute_services(self):
        """
Action for "services"

:since: v0.2.00
        """

        L10n.init("pas_http_user")

        content = { "title": L10n.get("pas_http_user_services"),
                    "service_list": { "file": "{0}/settings/lists/pas_user.service.json".format(Settings.get("path_data")) }
                  }

        self.response.init()
        self.response.set_title(content['title'])
        self.response.add_oset_content("core.service_list", content)
开发者ID:dNG-git,项目名称:pas_http_user,代码行数:16,代码来源:index.py

示例14: handle_result

    def handle_result(self, urn, action, result):
        """
Returns a UPNP response for the given URN and SOAP action.

:param urn: UPnP URN called
:param action: SOAP action called
:param result: UPnP result arguments

:since: v0.2.00
        """

        if (isinstance(result, Exception)):
            if (isinstance(result, UpnpException)): self.send_error(result.get_upnp_code(), "{0:l10n_message}".format(result))
            else: self.send_error(501, L10n.get("errors_core_unknown_error"))
        else:
            xml_resource = XmlResource(node_type = OrderedDict)

            client_settings = self.get_client_settings()
            if (not client_settings.get("upnp_xml_cdata_encoded", False)): xml_resource.set_cdata_encoding(False)

            xml_resource.add_node("s:Envelope", attributes = { "xmlns:s": "http://schemas.xmlsoap.org/soap/envelope/", "s:encodingStyle": "http://schemas.xmlsoap.org/soap/encoding/" })

            xml_base_path = "s:Envelope s:Body u:{0}Response".format(action)
            xml_resource.add_node(xml_base_path, attributes = { "xmlns:u": urn })
            xml_resource.set_cached_node(xml_base_path)

            for result_value in result: xml_resource.add_node("{0} {1}".format(xml_base_path, result_value['name']), result_value['value'])

            self.data = Binary.utf8_bytes("<?xml version='1.0' encoding='UTF-8' ?>{0}".format(xml_resource.export_cache(True)))
开发者ID:dNG-git,项目名称:pas_upnp,代码行数:29,代码来源:http_upnp_response.py

示例15: _apply_form

    def _apply_form(self, form, document = None):
        """
Applies document form fields to given form instance.

:param form: Form instance
:param document: Document to get default data values from

:since: v0.2.00
        """

        document_data = ({ "title": None, "tag": None, "content": None, "description": None }
                         if (document is None) else
                         document.get_data_attributes("title", "tag", "content", "description")
                        )

        field = TextField("ctitle")
        field.set_title(L10n.get("pas_http_contentor_document_title"))
        field.set_value(document_data['title'])
        field.set_required()
        field.set_size(TextField.SIZE_LARGE)
        field.set_limits(int(Settings.get("pas_http_contentor_document_title_min", 3)))
        form.add(field)

        field = TextField("ctag")
        field.set_title(L10n.get("pas_http_contentor_document_tag"))
        field.set_value(document_data['tag'])
        field.set_size(TextField.SIZE_SMALL)
        field.set_limits(_max = 255)
        field.set_validators([ self._check_tag_unique ])
        form.add(field)

        field = FormTagsTextareaField("cdescription")
        field.set_title(L10n.get("pas_http_contentor_document_description"))
        field.set_value(document_data['description'])
        field.set_size(FormTagsTextareaField.SIZE_SMALL)
        field.set_limits(_max = 255)
        form.add(field)

        field = FormTagsTextareaField("ccontent")
        field.set_title(L10n.get("pas_http_contentor_document_content"))
        field.set_value(document_data['content'])
        field.set_required()
        field.set_size(FormTagsTextareaField.SIZE_LARGE)
        field.set_limits(int(Settings.get("pas_http_contentor_document_content_min", 6)))
        form.add(field)
开发者ID:dNG-git,项目名称:pas_http_contentor,代码行数:45,代码来源:document.py


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