Access language and value of LngString
Closed this issue · 2 comments
Description
Currently it looks like you create a LngString as follows:
test=LngString(__root__={'en': ['label'], 'cy': ['welsh']})
and then to find out what languages are available in the lang string you need to do:
>>> test.__root__.keys()
dict_keys(['en', 'cy'])
and to find the values you would need to do:
>>> test.__root__['cy']
['welsh']
It would be nice if you could call LngString.lang
for the languages and LngString.values(lang)
for the values.
Function name / Parameters / Return
Function name:
lang property and values method
Returns:
LngString.lang returns a list of Strings
LngString.values takes in a language string and returns an array of Strings
Objects
- Base Object (all Prezi3 Classes)
- Collection
- Manifest
- Canvas
- Range
- AnnotationCollection
- AnnotationPage
- Annotation
- Content Resource - Image
- Content Resource - Video
- Content Resource - Text
- Service
- Provider
- Other - please list below
LngString
Considerations
It would also be nice if we could sort out the constructor for LngString.
Good idea. I think this pattern is the same for any object that just has a __root__
key in the skeleton (e.g you can't create a Format
object with f = Format("text/html")
but have to use f = Format(__root__ = "text/html")
.
I wonder if we could achieve this with some more code in the __setattr__
handler in the base class, similar to how we use __getattribute__
to automatically return the __root__
(or a string representation if __root__
is an AnyUrl
)
Discussed in the prezi3 meeting and this isn't necessary. It is unusual and not supported to instantiate the LngString directly and more likely you would do something like this:
example=Manifest(id="http://example.com",
label={
'en': ['Eng label'],
'cy': ['Welsh label']
})
where the base code handles setting __root__
and returning __root__
so you can do things like:
# Get languages available
>>> example.label.keys()
dict_keys(['en', 'cy'])
# Get value for English:
>>> example.label['en']
['Eng label']