Skip to content
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

TranslationProvider: added detect_lang_callback_url param #229

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

All notable changes to this project will be documented in this file.

## [0.11.0 - 2024-0x-xx]
## [0.11.0 - 2024-02-17]

### Added

- Files: `lock` and `unlock` methods, lock file information to `FsNode`. #227

### Fixed

- NextcloudApp: `MachineTranslation` provider registration - added optional `actionDetectLang` param. #229

## [0.10.0 - 2024-02-14]

### Added
Expand Down
9 changes: 9 additions & 0 deletions nc_py_api/ex_app/providers/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def action_handler(self) -> str:
"""Relative ExApp url which will be called by Nextcloud."""
return self._raw_data["action_handler"]

@property
def action_handler_detect_lang(self) -> str:
"""Relative ExApp url which will be called by Nextcloud to detect language."""
return self._raw_data.get("action_detect_lang", "")

def __repr__(self):
return f"<{self.__class__.__name__} name={self.name}, handler={self.action_handler}>"

Expand All @@ -59,6 +64,7 @@ def register(
callback_url: str,
from_languages: dict[str, str],
to_languages: dict[str, str],
detect_lang_callback_url: str = "",
) -> None:
"""Registers or edit the Translations provider."""
require_capabilities("app_api", self._session.capabilities)
Expand All @@ -68,6 +74,7 @@ def register(
"fromLanguages": from_languages,
"toLanguages": to_languages,
"actionHandler": callback_url,
"actionDetectLang": detect_lang_callback_url,
}
self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params)

Expand Down Expand Up @@ -114,6 +121,7 @@ async def register(
callback_url: str,
from_languages: dict[str, str],
to_languages: dict[str, str],
detect_lang_callback_url: str = "",
) -> None:
"""Registers or edit the Translations provider."""
require_capabilities("app_api", await self._session.capabilities)
Expand All @@ -123,6 +131,7 @@ async def register(
"fromLanguages": from_languages,
"toLanguages": to_languages,
"actionHandler": callback_url,
"actionDetectLang": detect_lang_callback_url,
}
await self._session.ocs("POST", f"{self._session.ae_url}/{_EP_SUFFIX}", json=params)

Expand Down
6 changes: 6 additions & 0 deletions tests/actual_tests/translation_provider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ def test_translation_provider(nc_app):
assert result.action_handler == "some_url"
assert result.from_languages == FROM_LANG1
assert result.to_languages == TO_LANG1
assert result.action_handler_detect_lang == ""
nc_app.providers.translations.register(
"test_id2",
"Test #2 Prov",
"some_url2",
{"pl_PL": "Polish"},
{"tr_TR": "Turkish"},
"/detect_lang",
)
result2 = nc_app.providers.translations.get_entry("test_id2")
assert result2.name == "test_id2"
assert result2.display_name == "Test #2 Prov"
assert result2.action_handler == "some_url2"
assert result2.from_languages == {"pl_PL": "Polish"}
assert result2.to_languages == {"tr_TR": "Turkish"}
assert result2.action_handler_detect_lang == "detect_lang"
nc_app.providers.translations.register(
"test_id",
"Renamed",
Expand Down Expand Up @@ -72,19 +75,22 @@ async def test_translation_async(anc_app):
assert result.action_handler == "some_url"
assert result.from_languages == FROM_LANG1
assert result.to_languages == TO_LANG1
assert result.action_handler_detect_lang == ""
await anc_app.providers.translations.register(
"test_id2",
"Test #2 Prov",
"some_url2",
{"pl_PL": "Polish"},
{"tr_TR": "Turkish"},
"/detect_lang",
)
result2 = await anc_app.providers.translations.get_entry("test_id2")
assert result2.name == "test_id2"
assert result2.display_name == "Test #2 Prov"
assert result2.action_handler == "some_url2"
assert result2.from_languages == {"pl_PL": "Polish"}
assert result2.to_languages == {"tr_TR": "Turkish"}
assert result2.action_handler_detect_lang == "detect_lang"
await anc_app.providers.translations.register(
"test_id",
"Renamed",
Expand Down
Loading