@saooti/octopus-sdk 41.10.0 → 41.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -3,6 +3,8 @@ import { transcriptionApi, TranslationState, type PodcastTranslationData } from
|
|
|
3
3
|
import { CreateTranslation, defaultTranslationConfig, TranslationConfiguration } from "../../stores/class/transcript/transcriptParams";
|
|
4
4
|
import { podcastApi } from "../../api/podcastApi";
|
|
5
5
|
import { Emission } from "../../stores/class/general/emission";
|
|
6
|
+
import { OrganisationAttributes } from "@/stores/class/general/organisation";
|
|
7
|
+
import { organisationApi } from "../../api/organisationApi";
|
|
6
8
|
|
|
7
9
|
const DEFAULT_LANGUAGE = 'en';
|
|
8
10
|
|
|
@@ -67,21 +69,20 @@ export const useTranslation = () => {
|
|
|
67
69
|
* @param emission *(optional)* If set, will also check in emission settings
|
|
68
70
|
* @returns Whether the language is available or not
|
|
69
71
|
*/
|
|
70
|
-
function getTranslationConfig(language: string, emission: Emission): CreateTranslation {
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const orgTranslation = parseOrDefault(orgAttributes?.['translation-config']);
|
|
72
|
+
function getTranslationConfig(language: string, emission: Emission, orgaAttributes: OrganisationAttributes): CreateTranslation {
|
|
73
|
+
const emissionTranslation = parseOrDefault(emission.annotations?.['translation-config'] as string|undefined, true);
|
|
74
|
+
const orgTranslation = parseOrDefault(orgaAttributes?.['translation-config']);
|
|
74
75
|
|
|
75
76
|
return getConfigurationFor(language, emissionTranslation, orgTranslation);
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
function getLanguageAvailability(language: string, emission: Emission, translationData: PodcastTranslationData): Availability {
|
|
79
|
+
function getLanguageAvailability(language: string, emission: Emission, orgaAttributes: OrganisationAttributes, translationData: PodcastTranslationData): Availability {
|
|
79
80
|
|
|
80
81
|
// 1. If language of podcast == language of browser, use that language
|
|
81
82
|
if (language === translationData.nativeLanguage) {
|
|
82
83
|
return Availability.Available;
|
|
83
84
|
} else {
|
|
84
|
-
const langConfig = getTranslationConfig(language, emission);
|
|
85
|
+
const langConfig = getTranslationConfig(language, emission, orgaAttributes);
|
|
85
86
|
|
|
86
87
|
// 2. If the language of the browser is available, use it
|
|
87
88
|
if (langConfig === CreateTranslation.ALWAYS) {
|
|
@@ -136,12 +137,13 @@ export const useTranslation = () => {
|
|
|
136
137
|
|
|
137
138
|
const podcast = await podcastApi.get(translationData.podcastId);
|
|
138
139
|
const emission = podcast.emission;
|
|
140
|
+
const orgaAttributes = await organisationApi.getAttributes(podcast.organisation.id);
|
|
139
141
|
|
|
140
142
|
let bestReady: string|null = null;
|
|
141
143
|
let bestAvailable: string|null = null;
|
|
142
144
|
|
|
143
145
|
for (const language of languages) {
|
|
144
|
-
const avaibility = getLanguageAvailability(language, emission, translationData);
|
|
146
|
+
const avaibility = getLanguageAvailability(language, emission, orgaAttributes, translationData);
|
|
145
147
|
if (avaibility === Availability.Available && bestReady === null) {
|
|
146
148
|
bestReady = language;
|
|
147
149
|
break;
|
|
@@ -19,19 +19,26 @@ vi.mock('@/api/podcastApi', () => ({
|
|
|
19
19
|
},
|
|
20
20
|
}));
|
|
21
21
|
|
|
22
|
+
vi.mock('@/api/organisationApi', () => ({
|
|
23
|
+
organisationApi: {
|
|
24
|
+
getAttributes: vi.fn()
|
|
25
|
+
}
|
|
26
|
+
}));
|
|
27
|
+
|
|
22
28
|
vi.mock('@/helper/language', () => ({
|
|
23
29
|
getLanguage: vi.fn().mockReturnValue('fr'),
|
|
24
30
|
}));
|
|
25
31
|
|
|
26
32
|
import { transcriptionApi, type PodcastTranslationData } from '@/api/transcriptionApi';
|
|
27
33
|
import { podcastApi } from '@/api/podcastApi';
|
|
34
|
+
import { organisationApi } from '@/api/organisationApi';
|
|
28
35
|
import { getLanguage } from '@/helper/language';
|
|
29
36
|
|
|
30
37
|
function makeTranslationData(overrides: Partial<PodcastTranslationData> = {}): PodcastTranslationData {
|
|
31
38
|
return { podcastId: 1, nativeLanguage: 'fr', translations: [], ...overrides };
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
function makeEmission(
|
|
41
|
+
function makeEmission(): Emission {
|
|
35
42
|
return {
|
|
36
43
|
emissionId: 0,
|
|
37
44
|
name: '',
|
|
@@ -40,7 +47,6 @@ function makeEmission(orgConfig?: object): Emission {
|
|
|
40
47
|
id: 'test-org',
|
|
41
48
|
imageUrl: '',
|
|
42
49
|
name: 'Test Org',
|
|
43
|
-
attributes: orgConfig ? { 'translation-config': JSON.stringify(orgConfig) } : undefined,
|
|
44
50
|
},
|
|
45
51
|
beneficiaries: [],
|
|
46
52
|
rubriqueIds: [],
|
|
@@ -50,7 +56,17 @@ function makeEmission(orgConfig?: object): Emission {
|
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
function setOrgTranslationConfig(config: object) {
|
|
53
|
-
vi.mocked(podcastApi.get).mockResolvedValue({
|
|
59
|
+
vi.mocked(podcastApi.get).mockResolvedValue({
|
|
60
|
+
emission: makeEmission(),
|
|
61
|
+
organisation: { id: 1 }
|
|
62
|
+
} as never);
|
|
63
|
+
setOrgAttributes(config);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function setOrgAttributes(orgConfig: object) {
|
|
67
|
+
vi.mocked(organisationApi.getAttributes).mockResolvedValue({
|
|
68
|
+
'translation-config': JSON.stringify(orgConfig)
|
|
69
|
+
});
|
|
54
70
|
}
|
|
55
71
|
|
|
56
72
|
describe('useTranslation', () => {
|
|
@@ -97,6 +113,10 @@ describe('useTranslation', () => {
|
|
|
97
113
|
});
|
|
98
114
|
|
|
99
115
|
const translationData = { nativeLanguage: 'it', podcastId: 0, translations: [] };
|
|
116
|
+
setOrgTranslationConfig({
|
|
117
|
+
createTranslation: { en: CreateTranslation.ALWAYS },
|
|
118
|
+
otherLanguage: CreateTranslation.NEVER,
|
|
119
|
+
});
|
|
100
120
|
|
|
101
121
|
const result = await composable.getMostRelevantLanguage(translationData)
|
|
102
122
|
expect(result.ready).toBe('it');
|
|
@@ -111,6 +131,10 @@ describe('useTranslation', () => {
|
|
|
111
131
|
});
|
|
112
132
|
|
|
113
133
|
const translationData = { nativeLanguage: 'fr', podcastId: 0, translations: [] };
|
|
134
|
+
setOrgTranslationConfig({
|
|
135
|
+
createTranslation: { en: CreateTranslation.ALWAYS },
|
|
136
|
+
otherLanguage: CreateTranslation.NEVER,
|
|
137
|
+
});
|
|
114
138
|
|
|
115
139
|
const result = await composable.getMostRelevantLanguage(translationData)
|
|
116
140
|
expect(result.ready).toBe('fr');
|