def test_convert_language_code(self): assert helpers.convert_language_code('fin', 'alpha2') == 'fi' assert helpers.convert_language_code('fin', 'alpha3') == 'fin' assert helpers.convert_language_code('fi', 'alpha2') == 'fi' assert helpers.convert_language_code('fi', 'alpha3') == 'fin' assert helpers.convert_language_code('eng', 'alpha2') == 'en' assert helpers.convert_language_code('eng', 'alpha3') == 'eng' assert helpers.convert_language_code('en', 'alpha2') == 'en' assert helpers.convert_language_code('en', 'alpha3') == 'eng'
def _add_translated_triple_from_dict(self, _dict, subject, predicate, key, fallback=None): """ Creates an RDF triple from a Kata language string {"fin": "Otsikko", "eng": "Title"} -> <dct:title xml:lang="fi">Otsikko</dct:title> <dct:title xml:lang="en">Title</dct:title> """ value = self._get_dict_value(_dict, key) if not value and fallback: value = self._get_dict_value(_dict, fallback) for item in json_to_list(value): lang = convert_language_code( item.get('lang'), 'alpha2', throw_exceptions=False) params = (subject, predicate, Literal( item.get('value'), lang=lang)) self.g.add(params)
def _add_translated_triple_from_dict(self, _dict, subject, predicate, key, fallback=None): """ Creates an RDF triple from a Kata language string {"fin": "Otsikko", "eng": "Title"} -> <dct:title xml:lang="fi">Otsikko</dct:title> <dct:title xml:lang="en">Title</dct:title> """ value = self._get_dict_value(_dict, key) if not value and fallback: value = self._get_dict_value(_dict, fallback) for item in json_to_list(value): lang = convert_language_code(item.get('lang'), 'alpha2', throw_exceptions=False) params = (subject, predicate, Literal(item.get('value'), lang=lang)) self.g.add(params)