Beispiel #1
0
    def localize(string_id):
        """
        Returns an add-on's localized 'unicode string'.

        :param int string_id: The id or reference string to be localized.

        :returns: Localized unicode string.
        :rtype: unicode
        """
        if 30000 <= string_id <= 30999:
            return addon_data.getLocalizedString(string_id)
        elif 32000 <= string_id <= 32999:
            return script_data.getLocalizedString(string_id)
        else:
            return xbmc.getLocalizedString(string_id)
    def localize(string_id):
        """
        Retruns a translated UI string from addon localization files.

        .. note::

            :data:`utils.string_map<codequick.utils.string_map>`
            needs to be populated before you can pass in a string as the reference.

        :param string_id: The numeric ID or gettext string ID of the localized string
        :type string_id: str or int

        :returns: Localized unicode string.
        :rtype: str

        :raises Keyword: if a gettext string ID was given but the string is not found in English :file:`strings.po`.
        :example:
            >>> Script.localize(30001)
            "Toutes les vidéos"
            >>> Script.localize("All Videos")
            "Toutes les vidéos"
        """
        if isinstance(string_id, (str, unicode_type)):
            try:
                numeric_id = string_map[string_id]
            except KeyError:
                raise KeyError("no localization found for string id '%s'" %
                               string_id)
            else:
                return addon_data.getLocalizedString(numeric_id)

        elif 30000 <= string_id <= 30999:
            return addon_data.getLocalizedString(string_id)
        elif 32000 <= string_id <= 32999:
            return script_data.getLocalizedString(string_id)
        else:
            return xbmc.getLocalizedString(string_id)
    def localize(string_id):
        """
        Retruns a translated UI string from addon localization files.

        .. note::

            :data:`utils.string_map<codequick.utils.string_map>`
            needs to be populated before you can pass in a string as the reference.

        :param string_id: The numeric ID or gettext string ID of the localized string
        :type string_id: str or int

        :returns: Localized unicode string.
        :rtype: str

        :raises Keyword: if a gettext string ID was given but the string is not found in English :file:`strings.po`.
        :example:
            >>> Script.localize(30001)
            "Toutes les vidéos"
            >>> Script.localize("All Videos")
            "Toutes les vidéos"
        """
        if isinstance(string_id, (str, unicode_type)):
            try:
                numeric_id = string_map[string_id]
            except KeyError:
                raise KeyError("no localization found for string id '%s'" % string_id)
            else:
                return addon_data.getLocalizedString(numeric_id)

        elif 30000 <= string_id <= 30999:
            return addon_data.getLocalizedString(string_id)
        elif 32000 <= string_id <= 32999:
            return script_data.getLocalizedString(string_id)
        else:
            return xbmc.getLocalizedString(string_id)