def set_iface_lang(): # TODO: internationalize. This seems the best place to put this # (used for formatting of large numbers to break them up with ","). # unfortunately, not directly compatible with gettext locale.setlocale(locale.LC_ALL, g.locale) lang = [g.lang] # GET param wins if c.host_lang: lang = [c.host_lang] else: lang = [c.user.pref_lang] if getattr(g, "lang_override") and lang[0] == "en": lang.insert(0, g.lang_override) #choose the first language c.lang = lang[0] #then try to overwrite it if we have the translation for another #one for l in lang: try: h.set_lang(l, fallback_lang=g.lang) c.lang = l break except h.LanguageError: #we don't have a translation for that language h.set_lang(g.lang, graceful_fail = True) #TODO: add exceptions here for rtl languages if c.lang in ('ar', 'he', 'fa'): c.lang_rtl = True
def set_iface_lang(): lang = ['en'] # GET param wins if c.host_lang: lang = [c.host_lang] else: lang = [c.user.pref_lang] #choose the first language c.lang = lang[0] #then try to overwrite it if we have the translation for another #one for l in lang: try: h.set_lang(l) c.lang = l break except h.LanguageError: #we don't have a translation for that language h.set_lang('en', graceful_fail = True) #TODO: add exceptions here for rtl languages if c.lang in ('ar', 'he', 'fa'): c.lang_rtl = True
def set_iface_lang(): lang = ['en'] # GET param wins if c.host_lang: lang = [c.host_lang] else: lang = [c.user.pref_lang] #choose the first language c.lang = lang[0] #then try to overwrite it if we have the translation for another #one for l in lang: try: h.set_lang(l) c.lang = l break except h.LanguageError: #we don't have a translation for that language h.set_lang('en', graceful_fail=True) #TODO: add exceptions here for rtl languages if c.lang in ('ar', 'he', 'fa'): c.lang_rtl = True
def set_iface_lang(): # TODO: internationalize. This seems the best place to put this # (used for formatting of large numbers to break them up with ","). # unfortunately, not directly compatible with gettext locale.setlocale(locale.LC_ALL, g.locale) lang = [g.lang] # GET param wins if c.host_lang: lang = [c.host_lang] else: lang = [c.user.pref_lang] if getattr(g, "lang_override") and lang[0] == "en": lang.insert(0, g.lang_override) #choose the first language c.lang = lang[0] #then try to overwrite it if we have the translation for another #one for l in lang: try: h.set_lang(l) c.lang = l break except h.LanguageError: #we don't have a translation for that language h.set_lang(g.lang, graceful_fail = True) #TODO: add exceptions here for rtl languages if c.lang in ('ar', 'he', 'fa'): c.lang_rtl = True
def fallback_trans(x): """For translating placeholder strings the user should never see in raw form, such as 'funny 500 message'. If the string does not translate in the current language, falls back on the g.lang translation that we've hopefully already provided""" t = _(x) if t == x: l = h.get_lang() h.set_lang(g.lang, graceful_fail=True) t = _(x) if l and l[0] != g.lang: h.set_lang(l[0]) return t
def fallback_trans(x): """For translating placeholder strings the user should never see in raw form, such as 'funny 500 message'. If the string does not translate in the current language, falls back on the g.lang translation that we've hopefully already provided""" t = _(x) if t == x: l = h.get_lang() h.set_lang(g.lang, graceful_fail = True) t = _(x) if l and l[0] != g.lang: h.set_lang(l[0]) return t