Closed Daandamhuis closed 1 year ago
I’ve adjusted some things in my fork and removed PyTranslations and instead just use a list of dicts in PyCulture.
class PyCulture(PyObject):
"""Wrapper for [Cultures](https://learn.microsoft.com/en-us/dotnet/api/microsoft.analysisservices.tabular.culture?view=analysisservices-dotnet).
Args:
Table: Parent Table to the Object Translations
"""
def __init__(self, object, model) -> None:
super().__init__(object)
self.Model = model
self._display.add_row("Culture Name", self._object.Name)
self.ObjectTranslations = self.set_translation()
def set_translation(self):
return [
{
"object_translation": translation.Value,
"object_name": translation.Object.Name,
"object_parent_name": translation.Object.Parent.Name,
"object_type": str(translation.Property),
}
for translation in self._object.ObjectTranslations.GetEnumerator()
]
And added a get function
def get_translation(
self, object_name: str, object_parent_name: str, object_type: str ="Caption"
) -> dict:
if translations := [
d
for d in self.ObjectTranslations
if d["object_name"] == object_name
and d["object_type"] == object_type
and d["object_parent_name"] == object_parent_name
]:
return translations[0]
return {
"object_translation": "Not Available",
"object_name": "Not Available",
"object_parent_name": "Not Available",
"object_type": "Not Available",
}
Usage
Model.Cultures[‘en-US’].get_translation(‘Measure’, ‘Sales Orders’)
Hi,
I'm getting a Recursion after merging some changes from the master branch. Did anything change? I'm testing it on a production model, so maybe the adventure works model doesn't have enough translations to generate a recursion error.
https://github.com/Curts0/PyTabular/blob/18210eb9da1708b681bb2b139937d675ebef7f6d/pytabular/pytabular.py#L119