tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

localization.py (1630B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 # You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 
      6 class L10n:
      7    """An API which allows Marionette to handle localized content.
      8 
      9    The `localization`_ of UI elements in Gecko based applications is done via
     10    entities and properties. For static values entities are used, which are located
     11    in .dtd files. Whereby for dynamically updated content the values come from
     12    .property files. Both types of elements can be identifed via a unique id,
     13    and the translated content retrieved.
     14 
     15    For example::
     16 
     17        from marionette_driver.localization import L10n
     18        l10n = L10n(marionette)
     19 
     20        l10n.localize_property(["chrome://global/locale/findbar.properties"], "FastFind"))
     21 
     22    .. _localization: https://mzl.la/2eUMjyF
     23    """
     24 
     25    def __init__(self, marionette):
     26        self._marionette = marionette
     27 
     28    def localize_property(self, properties_urls, property_id):
     29        """Retrieve the localized string for the specified property id.
     30 
     31        :param properties_urls: List of .properties URLs which will be used to
     32                                search for the property.
     33        :param property_id: ID of the property to retrieve the localized string for.
     34 
     35        :returns: The localized string for the requested property.
     36        :raises: :exc:`NoSuchElementException`
     37        """
     38        body = {"urls": properties_urls, "id": property_id}
     39        return self._marionette._send_message(
     40            "L10n:LocalizeProperty", body, key="value"
     41        )