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
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')
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))
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
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))
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
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
def get(locale, name, default=None): locale = get_locale(locale) mod = get_locale_module(locale) return getattr(mod, name, default)
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)