Skip to content

Commit

Permalink
Merge pull request #688 from Mara3l/master
Browse files Browse the repository at this point in the history
STL-169: Translations PySDK support
  • Loading branch information
hkad98 authored May 30, 2024
2 parents 9d40327 + 11bce4f commit eef2bb1
Show file tree
Hide file tree
Showing 13 changed files with 548 additions and 0 deletions.
67 changes: 67 additions & 0 deletions docs/content/en/latest/workspace-content/localization/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: "Metadata Localization"
linkTitle: "Metadata Localization"
weight: 20
---

Manage metadata localization for workspaces.

## Methods

* [get_metadata_localization](./get_metadata_localization/)
* [set_metadata_localization](./set_metadata_localization/)
* [clean_metadata_localization](./clean_metadata_localization/)
* [add_metadata_locale](./add_metadata_locale/)
* [save_metadata_locale_to_disk](./save_metadata_locale_to_disk/)
* [set_metadata_locale_from_disk](./set_metadata_locale_from_disk/)

## Example

```python
from gooddata_sdk import GoodDataSdk
from pathlib import Path

# GoodData base URL, e.g. "https://www.example.com"
host = "https://www.example.com"
# GoodData user token
token = "some_user_token"
sdk = GoodDataSdk.create(host, token)

# Example usage for getting metadata localization
localization = sdk.catalog_workspace.get_metadata_localization(
workspace_id="123",
target_language="de-DE"
)

# Example usage for setting metadata localization
sdk.catalog_workspace.set_metadata_localization(
workspace_id="123",
encoded_xml=b"<xml>...</xml>"
)

# Example usage for cleaning metadata localization
sdk.catalog_workspace.clean_metadata_localization(
workspace_id="123",
target_language="de-DE"
)

# Example usage for adding metadata locale
sdk.catalog_workspace.add_metadata_locale(
workspace_id="123",
target_language="de-DE",
translator_func=my_translation_function,
set_locale=True
)

# Example usage for saving metadata locale to disk
sdk.catalog_workspace.save_metadata_locale_to_disk(
workspace_id="123",
target_language="de-DE",
file_path=Path("/path/to/file.xliff")
)

# Example usage for setting metadata locale from disk
sdk.catalog_workspace.set_metadata_locale_from_disk(
workspace_id="123",
file_path=Path("/path/to/file.xliff")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: "add_metadata_locale"
linkTitle: "add_metadata_locale"
weight: 25
superheading: "catalog_workspace."
---

``add_metadata_locale(workspace_id: str, target_language: str, translator_func: Callable, set_locale: bool = True) -> None``

Add and optionally set the metadata localization for a workspace in a target language.

{{% parameters-block title="Parameters" %}}
{{< parameter p_name="workspace_id" p_type="string" >}}
The ID of the workspace.
{{< /parameter >}}
{{< parameter p_name="target_language" p_type="string" >}}
The target language for the metadata localization.
{{< /parameter >}}
{{< parameter p_name="translator_func" p_type="Callable" >}}
A function to translate the source text.
{{< /parameter >}}
{{< parameter p_name="set_locale" p_type="bool" >}}
Flag to indicate if the locale settings should be updated in the workspace.
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" None="yes" %}}
{{% /parameters-block %}}

## Example

```python
# Add and set the metadata localization for a workspace using a translation function.
sdk.catalog_workspace.add_metadata_locale(
workspace_id="123",
target_language="de-DE",
translator_func=my_translation_function,
set_locale=True
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: "add_metadata_locale"
linkTitle: "add_metadata_locale"
weight: 55
superheading: "catalog_workspace."
---

``add_metadata_locale(workspace_id: str, target_language: str, translator_func: Callable, set_locale: bool = True) -> None``

Add and optionally set the metadata localization for a workspace in a target language.

{{% parameters-block title="Parameters" %}}
{{< parameter p_name="workspace_id" p_type="string" >}}
The ID of the workspace.
{{< /parameter >}}
{{< parameter p_name="target_language" p_type="string" >}}
The target language for the metadata localization.
{{< /parameter >}}
{{< parameter p_name="translator_func" p_type="Callable" >}}
A function to translate the source text.
{{< /parameter >}}
{{< parameter p_name="set_locale" p_type="bool" >}}
Flag to indicate if the locale settings should be updated in the workspace.
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" None="yes" %}}
{{% /parameters-block %}}

## Example

```python
# Add and set the metadata localization for a workspace using a translation function.
sdk.catalog_workspace.add_metadata_locale(
workspace_id="123",
target_language="de-DE",
translator_func=my_translation_function,
set_locale=True
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: "get_metadata_localization"
linkTitle: "get_metadata_localization"
weight: 52
superheading: "catalog_workspace."
---

``get_metadata_localization(workspace_id: str, target_language: str) -> bytes``

Retrieve the metadata localization for a workspace.

{{% parameters-block title="Parameters" %}}
{{< parameter p_name="workspace_id" p_type="string" >}}
The ID of the workspace for which to retrieve the metadata localization.
{{< /parameter >}}
{{< parameter p_name="target_language" p_type="string" >}}
The target language code for the localization.
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" %}}
{{< parameter p_type="bytes" >}}
Object Containing declarative Analytical Model.
{{< /parameter >}}The encoded metadata localization in the target language.
{{% /parameters-block %}}

## Example

```python
# Retrieve metadata localization for a workspace in the specified language.
localization = sdk.catalog_workspace.get_metadata_localization(
workspace_id="123",
target_language="de-DE"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "save_metadata_locale_to_disk"
linkTitle: "save_metadata_locale_to_disk"
weight: 56
superheading: "catalog_workspace."
---

``save_metadata_locale_to_disk(workspace_id: str, target_language: str, file_path: Path) -> None``

Save the metadata localization for a workspace to a file.

{{% parameters-block title="Parameters" %}}
{{< parameter p_name="workspace_id" p_type="string" >}}
The ID of the workspace.
{{< /parameter >}}
{{< parameter p_name="target_language" p_type="string" >}}
The target language for the metadata localization.
{{< /parameter >}}
{{< parameter p_name="file_path" p_type="Path" >}}
The path to the file where the XLIFF content will be saved.
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" None="yes" %}}
{{% /parameters-block %}}

## Example

```python
# Save the metadata localization for a workspace to a file.
sdk.catalog_workspace.save_metadata_locale_to_disk(
workspace_id="123",
target_language="de-DE",
file_path=Path("/path/to/file.xliff")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: "set_metadata_locale_from_disk"
linkTitle: "set_metadata_locale_from_disk"
weight: 57
superheading: "catalog_workspace."
---

``set_metadata_locale_from_disk(workspace_id: str, file_path: Path) -> None``

Load and set the metadata localization for a workspace from a file.

{{% parameters-block title="Parameters" %}}
{{< parameter p_name="workspace_id" p_type="string" >}}
The ID of the workspace to which the metadata localization applies.
{{< /parameter >}}
{{< parameter p_name="file_path" p_type="Path" >}}
The path to the file containing the encoded XML metadata.
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" None="yes" %}}
{{% /parameters-block %}}

## Example

```python
# Load and set the metadata localization for a workspace from a file.
from pathlib import Path

sdk.catalog_workspace.set_metadata_locale_from_disk(
workspace_id="123",
file_path=Path("/path/to/file.xliff")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: "set_metadata_localization"
linkTitle: "set_metadata_localization"
weight: 53
superheading: "catalog_workspace."
---

``set_metadata_localization(workspace_id: str, encoded_xml: bytes) -> None``

Set the metadata localization for a workspace.

{{% parameters-block title="Parameters" %}}
{{< parameter p_name="workspace_id" p_type="string" >}}
The ID of the workspace to which the metadata localization applies.
{{< /parameter >}}
{{< parameter p_name="encoded_xml" p_type="bytes" >}}
The encoded XML metadata to be set.
{{< /parameter >}}
{{% /parameters-block %}}

{{% parameters-block title="Returns" None="yes" %}}
{{% /parameters-block %}}

## Example

```python
# Set the metadata localization for a workspace using encoded XML.
sdk.catalog_workspace.set_metadata_localization(
workspace_id="123",
encoded_xml=b"<xml>...</xml>"
)
Loading

0 comments on commit eef2bb1

Please sign in to comment.