def lang_choices(): """generated locale choices for drop down lists in forms""" choices = [] for code, name in supported_langs(): name = data.tr_lang(translation.to_locale('en'))(name) tr_name = data.tr_lang(translation.to_locale(code))(name) if tr_name != name: # We have to use the LRO (left-to-right override) to ensure that # brackets in the English part of the name is rendered correctly # in an RTL layout like Arabic. We can't use markup because this # is used inside an option tag. name = u"%s | \u202d%s" % (tr_name, name) choices.append((code, name)) choices.sort(cmp=locale.strcoll, key=lambda choice: unicode(choice[1])) return choices
def test_language_names(): _ = data.tr_lang('en_US') assert _(u"Bokmål, Norwegian; Norwegian Bokmål") == u"Norwegian Bokmål" assert _(u"Spanish; Castillian") == u"Spanish" assert _(u"Mapudungun; Mapuche") == u"Mapudungun" assert _(u"Interlingua (International Auxiliary Language Association)" ) == u"Interlingua"
def tr_lang(language_name): """Translates language names.""" language_code = translation.get_language() if language_code is None: language_code = settings.LANGUAGE_CODE language_code = translation.to_locale(language_code) return langdata.tr_lang(language_code)(language_name)
def lang_choices(): """Generate locale choices for drop down lists in forms.""" choices = [] for code, name in supported_langs(): name = data.tr_lang(translation.to_locale("en"))(name) tr_name = data.tr_lang(translation.to_locale(code))(name) # We have to use the bidi.insert_embeding() to ensure that brackets # in the English part of the name is rendered correctly in an RTL # layout like Arabic. We can't use markup because this is used # inside an option tag. if tr_name != name: name = u"%s | %s" % (bidi.insert_embeding(tr_name), bidi.insert_embeding(name)) else: name = bidi.insert_embeding(name) choices.append((code, name)) choices.sort(cmp=locale.strcoll, key=lambda choice: unicode(choice[1])) return choices
def lang_choices(): """Generate locale choices for drop down lists in forms.""" choices = [] for code, name in supported_langs(): name = data.tr_lang(translation.to_locale('en'))(name) tr_name = data.tr_lang(translation.to_locale(code))(name) # We have to use the bidi.insert_embeding() to ensure that brackets # in the English part of the name is rendered correctly in an RTL # layout like Arabic. We can't use markup because this is used # inside an option tag. if tr_name != name: name = u"%s | %s" % (bidi.insert_embeding(tr_name), bidi.insert_embeding(name)) else: name = bidi.insert_embeding(name) choices.append((code, name)) choices.sort(cmp=locale.strcoll, key=lambda choice: unicode(choice[1])) return choices
def __init__(self, langcode='und', more_langs={}): """Constructor. Looks up the language information based on the given language code (C{langcode}).""" super(LanguageModel, self).__init__() self.gettext_lang = tr_lang() if not self.languages: self.languages.update(toolkit_langs) self.languages.update(more_langs) self.load(langcode)
def tr_lang(language_name): """Translates language names.""" return langdata.tr_lang( translation.to_locale( translation.get_language() or settings.LANGUAGE_CODE))(language_name)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see <http://www.gnu.org/licenses/>. import logging from translate.lang.data import languages as toolkit_langs, tr_lang from translate.lang import data from virtaal.common.pan_app import ui_language from basemodel import BaseModel gettext_lang = tr_lang(ui_language) class LanguageModel(BaseModel): """ A simple container for language information for use by the C{LanguageController} and C{LanguageView}. """ __gtype_name__ = "LanguageModel" languages = {} # INITIALIZERS # def __init__(self, langcode="und", more_langs={}): """Constructor.
def tr_lang(language_name): """Translate language names.""" language_code = translation.to_locale(translation.get_language()) return langdata.tr_lang(language_code)(language_name)
def test_language_names(): _ = data.tr_lang('en_US') assert _("Bokmål, Norwegian; Norwegian Bokmål") == "Norwegian Bokmål" assert _("Spanish; Castillian") == "Spanish" assert _("Mapudungun; Mapuche") == "Mapudungun" assert _("Interlingua (International Auxiliary Language Association)") == "Interlingua"
def test_language_names(): _ = data.tr_lang('en_US') assert _(u"Bokmål, Norwegian; Norwegian Bokmål") == u"Norwegian Bokmål" assert _(u"Spanish; Castillian") == u"Spanish" assert _(u"Mapudungun; Mapuche") == u"Mapudungun"
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see <http://www.gnu.org/licenses/>. import logging from translate.lang.data import languages as toolkit_langs, tr_lang from translate.lang import data from virtaal.common.pan_app import ui_language from basemodel import BaseModel gettext_lang = tr_lang(ui_language) class LanguageModel(BaseModel): """ A simple container for language information for use by the C{LanguageController} and C{LanguageView}. """ __gtype_name__ = 'LanguageModel' languages = {} # INITIALIZERS # def __init__(self, langcode='und', more_langs={}): """Constructor.
def settargetlang(self, newlang): """Set a human readable target language""" self._header_dict['language'] = tr_lang('en')(newlang)