def tg_gettext(key, locale=None, domain=None):
    """Get the gettext value for key.

    Added to builtins as '_'. Returns Unicode string.

    @param key: text to be translated
    @param locale: locale code to be used.
        If locale is None, gets the value provided by get_locale.

    """
    if locale is None:
        locale = get_locale()

    if not is_locale_supported(locale):
        locale = locale[:2]

    if key == "":
        return ""  # special case

    try:
        return get_catalog(locale, domain).ugettext(key)

    except KeyError:
        return key

    except IOError:
        return key
Example #2
0
def _(msg): 
    ''' 
    Translate given message from current tg locale 
 
    Parameters 
    :message: text to be translated 
    Returns: Translated message string 
    ''' 
    return tg_gettext(msg, get_locale(), 'python-fedora')
Example #3
0
def _(msg):
    ''' 
    Translate given message from current tg locale 
 
    Parameters 
    :message: text to be translated 
    Returns: Translated message string 
    '''
    return tg_gettext(msg, get_locale(), 'python-fedora')
Example #4
0
def so_gettext(key, locale=None, domain=None):
    """SQLObject-based version of gettext. Messages are stored in database instead.
    """
    
    locale = get_locale(locale)
    
    messages = get_so_catalog(domain).get(locale)
    if not messages:
        messages = get_so_catalog(domain).get(locale[:2], {})
        
    return unicode(messages.get(key, key))
Example #5
0
 def retrieve_javascript(self):
     if not self._initialized:
         if not config.get('i18n.suppress_default_package_provider', False):
             self.register_package_provider()
         self._initialized = True
     js = super(JSI18NWidget, self).retrieve_javascript()
     js.add(JSLink("turbogears", 'js/i18n_base.js'))
     locale = get_locale()
     for pp in self.locale_catalog_providers:
         js.extend(pp(locale))
     return js
Example #6
0
 def retrieve_javascript(self):
     if not self._initialized:
         if not config.get('i18n.suppress_default_package_provider', False):
             self.register_package_provider()
         self._initialized = True
     js = super(JSI18NWidget, self).retrieve_javascript()
     js.add(JSLink("turbogears", 'js/i18n_base.js'))
     locale = get_locale()
     for pp in self.locale_catalog_providers:
         js.extend(pp(locale))
     return js
Example #7
0
def so_gettext(key, locale=None, domain=None):
    """
    SQLObject-based version of gettext. Messages are stored in
    database instead.
    """

    locale = get_locale(locale)

    messages = get_so_catalog(domain).get(locale)
    if not messages:
        messages = get_so_catalog(domain).get(locale[:2], {})

    return unicode(messages.get(key, key))
Example #8
0
 def _get_locale(self):
     locale = get_locale().lower()
     if locale in self.langs:
         log.debug("Locale %s is available" % locale)
         return locale
     else:
         log.debug("Locale %s is not available" % locale)
         #See if a less specific locale is available
         locale = locale.split('_')[0]
         if locale in self.langs:
             log.debug("Locale %s is available" % locale)
             return locale
     log.debug(
         "Locale %s is not available, resorting to default locale" % locale
         )
     return None
Example #9
0
def tg_gettext(key, locale=None, domain=None):
    """Get the gettext value for key.

    Added to builtins as '_'. Returns Unicode string.

    @param key: text to be translated
    @param locale: locale code to be used.
        If locale is None, gets the value provided by get_locale.

    """
    if locale is None:
        locale = get_locale()
    if not is_locale_supported(locale):
        locale = locale[:2]
    if key == '':
        return ''  # special case
    try:
        return get_catalog(locale, domain).ugettext(key)
    except KeyError:
        return key
    except IOError:
        return key
Example #10
0
def get(locale, name, default=None):

    locale = get_locale(locale)
    mod = get_locale_module(locale)
    
    return getattr(mod, name, default)
Example #11
0
def get(locale, name, default=None):
    """Get an attribute value for the locale."""
    locale = get_locale(locale)
    mod = get_locale_module(locale)
    return getattr(mod, name, default)