-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fluent Compatibility #240
base: master
Are you sure you want to change the base?
Fluent Compatibility #240
Conversation
- Started locale support with usage of the get_translated helper.
- Fixed keywords.
@amercader, can you take a look at this PR? It's a part of PR series from @JVickery-TBS with translation fixes |
- Removed unnecessary imports and code for the resource translations.
- Reverted profile.py back to master.
- Modified code to condition on fluent being loaded. - Added code to the `dcat_dataset_show` method to set the values of the data_dict before the serializer profiles.
@amercader okay I understand this extension a bit better from your comments thanks! So basically, we do not want to really mess with the Profiles at all because they are just the mappings of all of the different meta formats. So I found that the logic method So I now check I have reverted everything from I realize that it is not the greatest level/place to put the code, but it is clean and easy. The only thing that I would really like to do still is figure out the
So it would be nice to have the Let me know if you think there is any way to do that? |
- Added code for fluent fields to catalog show method.
- Added replacement of `{{LANG}}` to the `ckanext.dcat.base_uri` config value.
- Moved `{{LANG}}` replacement down.
@amercader Okay I figured it out now! Firstly, I added the fluent compatibility to the catalog view/blueprint as well now. As for the landingPage/URL stuff, I figured that out. So it will not override any set
It is now in the |
Maybe similar to #124 |
Thanks @JVickery-TBS . Let's step back for a second and see what means for ckanext-dcat to have multi-language support.
Multilingual support means:
Both don't need to be done at the same time, so it's fine to focus on serialization for now. <rdf:RDF>
<dcat:Dataset rdf:about="https://someckan.org/dataset/d9865e61-227c-4298-a1d1-620e6669b097">
<dct:title>Some title in English</dct:title>
<dct:description>A description in English</dct:description> And if they are visiting https://someckan.org/ca (or <rdf:RDF>
<dcat:Dataset rdf:about="https://someckan.org/dataset/d9865e61-227c-4298-a1d1-620e6669b097">
<dct:title>Un títol en català</dct:title>
<dct:description>Una descripció en català</dct:description> This is very limited in that we are not representing all languages, and the serialization does not provide information on which is the actual language used to display the values are provided. Besides, this will only work in the context of a web request, not when used in the CLI, or as module elsewhere. The correct and more interoperable approach is to always provide all available languages, and use language codes: <rdf:RDF>
<dcat:Dataset rdf:about="https://someckan.org/dataset/d9865e61-227c-4298-a1d1-620e6669b097">
<dct:title xml:lang="en">Some title in English</dct:title>
<dct:title xml:lang="ca">Un títol en català</dct:title>
<dct:title xml:lang="es">Un título en castellano</dct:title>
<dct:description xml:lang="en">A description in English</dct:description>
<dct:description xml:lang="ca">Una descripció en català</dct:description>
<dct:description xml:lang="es">Una descripción en castellano</dct:description> For this I'm afraid we need to go low level, at the profiles level. But the good news is that by changing it there we will automatically get multilingual serializations regardless of how these are created (API, RDF endpoint, CLI, etc). Below is a quick patch I tried to add support for multilingual @seitenbau-govdata I'd love to get another pair of eyes on the modified diff --git a/ckanext/dcat/profiles.py b/ckanext/dcat/profiles.py
index 9b066ef..f91c79e 100644
--- a/ckanext/dcat/profiles.py
+++ b/ckanext/dcat/profiles.py
@@ -727,14 +727,16 @@ class RDFProfile(object):
def _add_triples_from_dict(self, _dict, subject, items,
list_value=False,
- date_value=False):
+ date_value=False,
+ multilingual=False):
for item in items:
key, predicate, fallbacks, _type = item
self._add_triple_from_dict(_dict, subject, predicate, key,
fallbacks=fallbacks,
list_value=list_value,
date_value=date_value,
- _type=_type)
+ _type=_type,
+ multilingual=multilingual)
def _add_triple_from_dict(self, _dict, subject, predicate, key,
fallbacks=None,
@@ -742,7 +744,8 @@ class RDFProfile(object):
date_value=False,
_type=Literal,
_datatype=None,
- value_modifier=None):
+ value_modifier=None,
+ multilingual=False):
'''
Adds a new triple to the graph with the provided parameters
@@ -776,6 +779,11 @@ class RDFProfile(object):
self._add_date_triple(subject, predicate, value, _type)
elif value:
# Normal text value
+ if multilingual and isinstance(value, dict):
+ # We assume that all multilingual field values are Literals
+ for lang, translated_value in value.items():
+ object = Literal(translated_value, lang=lang)
+ self.g.add((subject, predicate, object))
# ensure URIRef items are preprocessed (space removal/url encoding)
if _type == URIRef:
_type = CleanedURIRef
@@ -1207,10 +1215,16 @@ class EuropeanDCATAPProfile(RDFProfile):
g.add((dataset_ref, RDF.type, DCAT.Dataset))
- # Basic fields
+ # Multilingual fields
items = [
('title', DCT.title, None, Literal),
('notes', DCT.description, None, Literal),
+ ]
+
+ self._add_triples_from_dict(dataset_dict, dataset_ref, items, multilingual=True)
+
+ # Basic fields
+ items = [
('url', DCAT.landingPage, None, URIRef),
('identifier', DCT.identifier, ['guid', 'id'], URIRefOrLiteral),
('version', OWL.versionInfo, ['dcat_version'], Literal), |
- Removed fluent compatibility code in converters. - Removed fluent compatibility code in logic. - Removed fluent loaded check in `catalog_uri` util method.
- Removed `LANG` replacement in base uri util method. - Added multilingual support to graph from dataset.
@amercader Okay here we go again hahaha. I have done your above implementation for There were a couple places in which I had to do some strange-ish things:
I also removed the language from the url for the |
…elper; - Made the translation keys fallback to the normal core field, like the `get_translated` helper does.
@amercader Just added in the fallback for the field keys. Realized that if we put in the So just a simple check if the |
- Changed conditions for translated tags.
- Renamed `multilingual` to `all_translated` due to core extension name.
@amercader Ian mentioned that I should rename the So I just renamed that param to |
- Fixed syntax error from refactor.
- Fixed syntax error from refactor.
- Fixed fluent tags output.
- Fixed fluent tags output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bearing with me @JVickery-TBS
I don't like all_translated
, what about just translated
?
And one final thing about the organization_show
call. Besides that this is good to go
Will this ever get merged or not? |
- Renamed `all_translated` to `translated`. - Added a class cache variable for org dicts. - Updated org test for serializing.
@inderps Hey! Sorry! Have been busy with things over here. But have just done the feedback now, so we shall see! |
Quick update here just to say that I've pulled the fluent compatibility work in the wider Scheming / DCAT 3 support effort so at some point during the next few weeks this will be looked at. I just need to think about how it will integrate with the more general scheming support but the majority of the work here should get incorporated as is. Thanks for bearing with me @JVickery-TBS |
Featre/language support
Added translation support to the extensions. Translates: