def get_languages_mapping(self): """Get mapping token/value for languages.""" portal = api.portal.get() portal_state = queryMultiAdapter((portal, portal.REQUEST), name=u'plone_portal_state') mapping = portal_state.locale().displayNames.languages language_tool = api.portal.get_tool('portal_languages') supported_langs = language_tool.supported_langs languages_mapping = { get_lang_code(lang): mapping[get_lang_code(lang)].capitalize() for lang in supported_langs } # add taxonomy's default language if it is not in supported langs default_lang = self.taxonomy.default_language languages_mapping[default_lang] = mapping[default_lang].capitalize() return json.dumps(languages_mapping)
def get_languages_mapping(self): """Get mapping token/value for languages.""" portal = api.portal.get() portal_state = queryMultiAdapter( (portal, portal.REQUEST), name=u'plone_portal_state') mapping = portal_state.locale().displayNames.languages language_tool = api.portal.get_tool('portal_languages') supported_langs = language_tool.supported_langs languages_mapping = { get_lang_code(lang): mapping[get_lang_code(lang)].capitalize() for lang in supported_langs } # add taxonomy's default language if it is not in supported langs default_lang = self.taxonomy.default_language languages_mapping[default_lang] = mapping[default_lang].capitalize() return json.dumps(languages_mapping)
def getCurrentLanguage(self, request): language = get_lang_code() if language in self.data: return language elif self.default_language in self.data: return self.default_language else: # our best guess! return self.data.keys()[0]