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

feat(translations): Expose task-processing translation options #14068

Merged
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
1 change: 1 addition & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,4 @@
* `config => conversations => force-passwords` - Whether passwords are enforced for public rooms
* `conversation-creation-password` - Whether the endpoints for creating public conversations or making a conversation public support setting a password
* `call-notification-state-api` (local) - Whether the endpoints exists for checking if a call notification should be dismissed
* `config => chat => has-translation-task-providers` (local) - When true, translations can be done using the [OCS TaskProcessing API](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-taskprocessing-api.html).
6 changes: 6 additions & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\IUserSession;
use OCP\TaskProcessing\IManager as ITaskProcessingManager;
use OCP\TaskProcessing\TaskTypes\TextToTextSummary;
use OCP\TaskProcessing\TaskTypes\TextToTextTranslate;
use OCP\Translation\ITranslationManager;
use OCP\Util;

Expand Down Expand Up @@ -148,6 +149,7 @@ class Capabilities implements IPublicCapability {
'chat' => [
'read-privacy',
'has-translation-providers',
'has-translation-task-providers',
'typing-privacy',
'summary-threshold',
],
Expand Down Expand Up @@ -223,6 +225,7 @@ public function getCapabilities(): array {
'max-length' => ChatManager::MAX_CHAT_LENGTH,
'read-privacy' => Participant::PRIVACY_PUBLIC,
'has-translation-providers' => $this->translationManager->hasProviders(),
'has-translation-task-providers' => false,
'typing-privacy' => Participant::PRIVACY_PUBLIC,
'summary-threshold' => 100,
],
Expand Down Expand Up @@ -324,6 +327,9 @@ public function getCapabilities(): array {
if (isset($supportedTaskTypes[TextToTextSummary::ID])) {
$capabilities['features'][] = 'chat-summary-api';
}
if (isset($supportedTaskTypes[TextToTextTranslate::ID])) {
$capabilities['config']['chat']['has-translation-task-providers'] = true;
}

return [
'spreed' => $capabilities,
Expand Down
3 changes: 2 additions & 1 deletion lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,13 @@
* max-length: int,
* read-privacy: int,
* has-translation-providers: bool,
* has-translation-task-providers: bool,
* typing-privacy: int,
* summary-threshold: positive-int,
* },
* conversations: array{
* can-create: bool,
* force-passwords: bool,
* force-passwords: bool,
* },
* federation: array{
* enabled: bool,
Expand Down
4 changes: 4 additions & 0 deletions openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
"max-length",
"read-privacy",
"has-translation-providers",
"has-translation-task-providers",
"typing-privacy",
"summary-threshold"
],
Expand All @@ -223,6 +224,9 @@
"has-translation-providers": {
"type": "boolean"
},
"has-translation-task-providers": {
"type": "boolean"
},
"typing-privacy": {
"type": "integer",
"format": "int64"
Expand Down
4 changes: 4 additions & 0 deletions openapi-backend-recording.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"max-length",
"read-privacy",
"has-translation-providers",
"has-translation-task-providers",
"typing-privacy",
"summary-threshold"
],
Expand All @@ -156,6 +157,9 @@
"has-translation-providers": {
"type": "boolean"
},
"has-translation-task-providers": {
"type": "boolean"
},
"typing-privacy": {
"type": "integer",
"format": "int64"
Expand Down
4 changes: 4 additions & 0 deletions openapi-backend-signaling.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"max-length",
"read-privacy",
"has-translation-providers",
"has-translation-task-providers",
"typing-privacy",
"summary-threshold"
],
Expand All @@ -156,6 +157,9 @@
"has-translation-providers": {
"type": "boolean"
},
"has-translation-task-providers": {
"type": "boolean"
},
"typing-privacy": {
"type": "integer",
"format": "int64"
Expand Down
4 changes: 4 additions & 0 deletions openapi-backend-sipbridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"max-length",
"read-privacy",
"has-translation-providers",
"has-translation-task-providers",
"typing-privacy",
"summary-threshold"
],
Expand All @@ -199,6 +200,9 @@
"has-translation-providers": {
"type": "boolean"
},
"has-translation-task-providers": {
"type": "boolean"
},
"typing-privacy": {
"type": "integer",
"format": "int64"
Expand Down
4 changes: 4 additions & 0 deletions openapi-bots.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"max-length",
"read-privacy",
"has-translation-providers",
"has-translation-task-providers",
"typing-privacy",
"summary-threshold"
],
Expand All @@ -156,6 +157,9 @@
"has-translation-providers": {
"type": "boolean"
},
"has-translation-task-providers": {
"type": "boolean"
},
"typing-privacy": {
"type": "integer",
"format": "int64"
Expand Down
4 changes: 4 additions & 0 deletions openapi-federation.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"max-length",
"read-privacy",
"has-translation-providers",
"has-translation-task-providers",
"typing-privacy",
"summary-threshold"
],
Expand All @@ -199,6 +200,9 @@
"has-translation-providers": {
"type": "boolean"
},
"has-translation-task-providers": {
"type": "boolean"
},
"typing-privacy": {
"type": "integer",
"format": "int64"
Expand Down
4 changes: 4 additions & 0 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
"max-length",
"read-privacy",
"has-translation-providers",
"has-translation-task-providers",
"typing-privacy",
"summary-threshold"
],
Expand All @@ -357,6 +358,9 @@
"has-translation-providers": {
"type": "boolean"
},
"has-translation-task-providers": {
"type": "boolean"
},
"typing-privacy": {
"type": "integer",
"format": "int64"
Expand Down
4 changes: 4 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
"max-length",
"read-privacy",
"has-translation-providers",
"has-translation-task-providers",
"typing-privacy",
"summary-threshold"
],
Expand All @@ -316,6 +317,9 @@
"has-translation-providers": {
"type": "boolean"
},
"has-translation-task-providers": {
"type": "boolean"
},
"typing-privacy": {
"type": "integer",
"format": "int64"
Expand Down
1 change: 1 addition & 0 deletions src/__mocks__/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const mockedCapabilities: Capabilities = {
'max-length': 32000,
'read-privacy': 0,
'has-translation-providers': true,
'has-translation-task-providers': true,
'typing-privacy': 0,
'summary-threshold': 100,
},
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-administration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export type components = {
/** Format: int64 */
"read-privacy": number;
"has-translation-providers": boolean;
"has-translation-task-providers": boolean;
/** Format: int64 */
"typing-privacy": number;
/** Format: int64 */
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-backend-recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export type components = {
/** Format: int64 */
"read-privacy": number;
"has-translation-providers": boolean;
"has-translation-task-providers": boolean;
/** Format: int64 */
"typing-privacy": number;
/** Format: int64 */
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-backend-signaling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type components = {
/** Format: int64 */
"read-privacy": number;
"has-translation-providers": boolean;
"has-translation-task-providers": boolean;
/** Format: int64 */
"typing-privacy": number;
/** Format: int64 */
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-backend-sipbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export type components = {
/** Format: int64 */
"read-privacy": number;
"has-translation-providers": boolean;
"has-translation-task-providers": boolean;
/** Format: int64 */
"typing-privacy": number;
/** Format: int64 */
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type components = {
/** Format: int64 */
"read-privacy": number;
"has-translation-providers": boolean;
"has-translation-task-providers": boolean;
/** Format: int64 */
"typing-privacy": number;
/** Format: int64 */
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export type components = {
/** Format: int64 */
"read-privacy": number;
"has-translation-providers": boolean;
"has-translation-task-providers": boolean;
/** Format: int64 */
"typing-privacy": number;
/** Format: int64 */
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,7 @@ export type components = {
/** Format: int64 */
"read-privacy": number;
"has-translation-providers": boolean;
"has-translation-task-providers": boolean;
/** Format: int64 */
"typing-privacy": number;
/** Format: int64 */
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ export type components = {
/** Format: int64 */
"read-privacy": number;
"has-translation-providers": boolean;
"has-translation-task-providers": boolean;
/** Format: int64 */
"typing-privacy": number;
/** Format: int64 */
Expand Down
13 changes: 13 additions & 0 deletions tests/php/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\TaskProcessing\IManager as ITaskProcessingManager;
use OCP\TaskProcessing\TaskTypes\TextToTextFormalization;
use OCP\TaskProcessing\TaskTypes\TextToTextSummary;
use OCP\TaskProcessing\TaskTypes\TextToTextTranslate;
use OCP\Translation\ITranslationManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
Expand Down Expand Up @@ -147,6 +148,7 @@ public function testGetCapabilitiesGuest(): void {
'max-length' => 32000,
'read-privacy' => 0,
'has-translation-providers' => false,
'has-translation-task-providers' => false,
'typing-privacy' => 0,
'summary-threshold' => 100,
],
Expand Down Expand Up @@ -280,6 +282,7 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea
'max-length' => 32000,
'read-privacy' => $readPrivacy,
'has-translation-providers' => false,
'has-translation-task-providers' => false,
'typing-privacy' => 0,
'summary-threshold' => 100,
],
Expand Down Expand Up @@ -404,6 +407,16 @@ public function testCapabilitiesTranslations(): void {
$this->assertEquals(true, $data['spreed']['config']['chat']['has-translation-providers']);
}

public function testCapabilitiesTranslationsTaskProviders(): void {
$capabilities = $this->getCapabilities();

$this->taskProcessingManager->method('getAvailableTaskTypes')
->willReturn([TextToTextTranslate::ID => true]);

$data = json_decode(json_encode($capabilities->getCapabilities(), JSON_THROW_ON_ERROR), true);
$this->assertEquals(true, $data['spreed']['config']['chat']['has-translation-task-providers']);
}

public function testSummaryTaskProviders(): void {
$capabilities = $this->getCapabilities();

Expand Down
Loading