def translate_graph(graph): """ Look for title assertions with i18n as the lang, use their object as the msgid to find additionaly title translations Args: graph: rdflib processed graph for us to walk through i18n_dir: directory of PO files. Default directory is that which is supplied with this package. """ lang_dirs = os.listdir( os.path.abspath(pkg_resources.resource_filename('cc.i18n', 'i18n'))) for subject, predicate, obj in graph.triples((None, None, None)): if not hasattr(obj, 'language') or obj.language != 'i18n': continue else: str_id = unicode(obj) if not str_id: return None old_objects = {} # remove any previous instane of this language's # translations. for s, p, old_obj in graph.triples((subject, predicate, None)): if lang_dirs.count(old_obj.language): old_objects[old_obj.language] = old_obj for lang in lang_dirs: rdf_lang = locale_to_lower_lower(lang) if old_objects.has_key(rdf_lang): graph.remove((subject, predicate, old_objects[rdf_lang])) translated = util.inverse_translate(str_id, lang) graph.add((subject, predicate, Literal(translated, lang=rdf_lang)))
def translate_graph(graph): """ Look for title assertions with i18n as the lang, use their object as the msgid to find additionaly title translations Args: graph: rdflib processed graph for us to walk through i18n_dir: directory of PO files. Default directory is that which is supplied with this package. """ lang_dirs = os.listdir(os.path.abspath(pkg_resources.resource_filename("cc.i18n", "i18n"))) for subject, predicate, obj in graph.triples((None, None, None)): if not hasattr(obj, "language") or obj.language != "i18n": continue else: str_id = unicode(obj) if not str_id: return None old_objects = {} # remove any previous instane of this language's # translations. for s, p, old_obj in graph.triples((subject, predicate, None)): if lang_dirs.count(old_obj.language): old_objects[old_obj.language] = old_obj for lang in lang_dirs: rdf_lang = locale_to_lower_lower(lang) if old_objects.has_key(rdf_lang): graph.remove((subject, predicate, old_objects[rdf_lang])) translated = util.inverse_translate(str_id, lang) graph.add((subject, predicate, Literal(translated, lang=rdf_lang)))
def title(self, language='en'): if self._titles is None: self._titles = rdf_helper.get_titles(self.uri) i18n_title = self._titles['x-i18n'] return inverse_translate(i18n_title, locale_to_lower_upper(language))
def title(self, language='en'): if self._titles is None: self._titles = rdf_helper.get_titles(self.uri) i18n_title = self._titles['i18n'] return inverse_translate(i18n_title, locale_to_lower_upper(language))