Skip to content

Commit

Permalink
TranslationProvider: added detect_lang_callback_url param (#229)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 authored Feb 17, 2024
1 parent 35ff268 commit c8731e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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

0 comments on commit c8731e1

Please sign in to comment.