dcc_quantities.dcc_lang_text ¶
Classes to operate with data stored in multiple languages.
The dcc_lang_text module defines a class to support XML contents that allow some type of text in different
languages.
For example, the label <dcc:name> allows defining names in different languages.
DccLangText ¶
DccLangText(content: dict[str, dict[str, Any]])
Bases: UserDict, ABC
A mapping containing any XML label information that supports multiple languages.
This mapping is defined as the base class for any more specific DCC label, such as <dcc:name> and
<dcc:description>.
This class is just to be defined as an AbstractBaseClass and should not be used directly anywhere. Instead,
other classes (that would contain information in multiple languages) should inherit from it.
DccLangText allows string representation by the str() call. This representation displays a single name, no
matter how many languages are contained within the instance. The selected name is based on the current system
language.
Only the names contained in the instance can be displayed, even if they don't match the system language. The priority level to display a name is displaying:
- The name that matches with the system language.
- The name in English.
- The first found name, no matter the language.
- The tag '
' if the instance does not contain any name tag.
Examples:
The DccLangName {'de': 'X deutscher Name', 'en': 'X English Name'} is analogous to the following
XML code:
<dcc:name>
<dcc:content lang="de">X deutscher Name</dcc:content>
<dcc:content lang="en">X English Name</dcc:content>
</dcc:name>
Assuming the system language is English, the string representation is then displayed as following:
>>> names = DccLangName({'de': 'X deutscher Name', 'en': 'X English Name'})
>>> str(names)
X English Name
Derived Classes
DccLangName: Class to work with data under the tag<dcc:name>.DccLangDescription: Class to work with data under the tag<dcc:description>.
General constructor based on the provided content.
| Parameters: |
|
|---|
in_use_language_tag
property
¶
in_use_language_tag: str | None
The short representation of the used language tag (EN, DE, etc.) when the 'str' method is called.
matches ¶
matches(other: DccLangText | str) -> bool
Matching algorithm for items and subsets of the data.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
>>> names = DccLangName({"en": "Frequency", "de": "Frequenz", "fr": "Fréquence"})
>>> names.matches("Frequency")
True # The name 'Frequency' is contained wihtin the `names` instance.
>>> names.matches("Speed")
False # The name 'Speed' is not within `names`.
>>> names.matches({"en": "Frequency", "de": "Frequenz"})
True # The provided dictionary is a subset of the `names` instance.
>>> names.matches({"en": "Frequency", "it": "Frequenza"})
False # The provided dictionary is not a subset of the `names` instance.
to_json_dict ¶
to_json_dict()
Class representations as a JSON dict with the same keys as required for the XML code.
| Returns: |
|
|---|
Examples:
Considering the previous example case:
>>> names = DccLangName({'de': 'X deutscher Name', 'en': 'X English Name'})
>>> names.to_json_dict()
{'dcc:name': {
'dcc:content': [
{'@lang': 'de', '$': 'X deutscher Name'},
{'@lang': 'en', '$': 'X English Name'}
]
}
}
DccLangName ¶
DccLangName(content: dict[str, dict[str, Any]])
Bases: DccLangText
Mapping for contents under the tag '<dcc:name>'.
General constructor based on the provided content.
| Parameters: |
|
|---|
DccLangDescription ¶
DccLangDescription(content: dict[str, dict[str, Any]])
Bases: DccLangText
Mapping for contents under the tag '<dcc:description>'.
General constructor based on the provided content.
| Parameters: |
|
|---|