diff --git a/backend/src/middleware/languages/languages.js b/backend/src/middleware/languages/languages.js
index 7b9678bbc..0cfe6a0e9 100644
--- a/backend/src/middleware/languages/languages.js
+++ b/backend/src/middleware/languages/languages.js
@@ -12,17 +12,30 @@ const setPostLanguage = (text) => {
const lngDetector = new LanguageDetect()
lngDetector.setLanguageType('iso2')
const result = lngDetector.detect(removeHtmlTags(text), 2)
- return result[0][0]
+ return {
+ language: result[0][0],
+ languageScore: result[0][1],
+ secondaryLanguage: result[1][0],
+ secondaryLanguageScore: result[1][1],
+ }
}
export default {
Mutation: {
CreatePost: async (resolve, root, args, context, info) => {
- args.language = await setPostLanguage(args.content)
+ const languages = await setPostLanguage(args.content)
+ args = {
+ ...args,
+ ...languages,
+ }
return resolve(root, args, context, info)
},
UpdatePost: async (resolve, root, args, context, info) => {
- args.language = await setPostLanguage(args.content)
+ const languages = await setPostLanguage(args.content)
+ args = {
+ ...args,
+ ...languages,
+ }
return resolve(root, args, context, info)
},
},
diff --git a/backend/src/middleware/languages/languages.spec.js b/backend/src/middleware/languages/languages.spec.js
index a2f264d40..66f8c5f2b 100644
--- a/backend/src/middleware/languages/languages.spec.js
+++ b/backend/src/middleware/languages/languages.spec.js
@@ -25,13 +25,16 @@ beforeAll(async () => {
})
afterAll(async () => {
- // await cleanDatabase()
+ await cleanDatabase()
})
const createPostMutation = gql`
mutation($title: String!, $content: String!, $categoryIds: [ID]) {
CreatePost(title: $title, content: $content, categoryIds: $categoryIds) {
language
+ languageScore
+ secondaryLanguage
+ secondaryLanguageScore
}
}
`
@@ -58,15 +61,17 @@ describe('languagesMiddleware', () => {
...variables,
content: 'Jeder sollte vor seiner eigenen Tür kehren.',
}
- await expect(
- mutate({
- mutation: createPostMutation,
- variables,
- }),
- ).resolves.toMatchObject({
+ const response = await mutate({
+ mutation: createPostMutation,
+ variables,
+ })
+ expect(response).toMatchObject({
data: {
CreatePost: {
language: 'de',
+ languageScore: 0.5134188034188034,
+ secondaryLanguage: 'no',
+ secondaryLanguageScore: 0.3655555555555555,
},
},
})
@@ -77,15 +82,17 @@ describe('languagesMiddleware', () => {
...variables,
content: 'A journey of a thousand miles begins with a single step.',
}
- await expect(
- mutate({
- mutation: createPostMutation,
- variables,
- }),
- ).resolves.toMatchObject({
+ const response = await mutate({
+ mutation: createPostMutation,
+ variables,
+ })
+ expect(response).toMatchObject({
data: {
CreatePost: {
language: 'en',
+ languageScore: 0.3430188679245283,
+ secondaryLanguage: 'da',
+ secondaryLanguageScore: 0.19968553459119498,
},
},
})
@@ -96,15 +103,17 @@ describe('languagesMiddleware', () => {
...variables,
content: 'A caballo regalado, no le mires el diente.',
}
- await expect(
- mutate({
- mutation: createPostMutation,
- variables,
- }),
- ).resolves.toMatchObject({
+ const response = await mutate({
+ mutation: createPostMutation,
+ variables,
+ })
+ expect(response).toMatchObject({
data: {
CreatePost: {
language: 'es',
+ languageScore: 0.46589743589743593,
+ secondaryLanguage: 'pt',
+ secondaryLanguageScore: 0.3834188034188034,
},
},
})
@@ -116,15 +125,17 @@ describe('languagesMiddleware', () => {
content:
'Jeder sollte vor seiner eigenen
Türkehren.', } - await expect( - mutate({ - mutation: createPostMutation, - variables, - }), - ).resolves.toMatchObject({ + const response = await mutate({ + mutation: createPostMutation, + variables, + }) + expect(response).toMatchObject({ data: { CreatePost: { language: 'de', + languageScore: 0.5134188034188034, + secondaryLanguage: 'no', + secondaryLanguageScore: 0.3655555555555555, }, }, }) diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index b24383fba..f0c57b8fb 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -317,19 +317,6 @@ describe('CreatePost', () => { expected, ) }) - - describe('language', () => { - beforeEach(() => { - variables = { ...variables, language: 'es' } - }) - - it('allows a user to set the language of the post', async () => { - const expected = { data: { CreatePost: { language: 'es' } } } - await expect(mutate({ mutation: createPostMutation, variables })).resolves.toMatchObject( - expected, - ) - }) - }) }) }) diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index 37f9dd176..2d8e39719 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -122,6 +122,9 @@ type Post { createdAt: String updatedAt: String language: String + languageScore: Float + secondaryLanguage: String + secondaryLanguageScore: Float pinnedAt: String @cypher( statement: "MATCH (this)<-[pinned:PINNED]-(:User) WHERE NOT this.deleted = true AND NOT this.disabled = true RETURN pinned.createdAt" ) diff --git a/webapp/components/ContributionForm/ContributionForm.spec.js b/webapp/components/ContributionForm/ContributionForm.spec.js index 0644c1321..a18dacb28 100644 --- a/webapp/components/ContributionForm/ContributionForm.spec.js +++ b/webapp/components/ContributionForm/ContributionForm.spec.js @@ -23,9 +23,7 @@ describe('ContributionForm.vue', () => { cancelBtn, mocks, propsData, - categoryIds, - englishLanguage, - deutschLanguage + categoryIds const postTitle = 'this is a title for a post' const postTitleTooShort = 'xx' let postTitleTooLong = '' @@ -52,7 +50,6 @@ describe('ContributionForm.vue', () => { slug: 'this-is-a-title-for-a-post', content: postContent, contentExcerpt: postContent, - language: 'en', categoryIds, }, }, @@ -109,10 +106,6 @@ describe('ContributionForm.vue', () => { postTitleInput = wrapper.find('.ds-input') postTitleInput.setValue(postTitle) await wrapper.vm.updateEditorContent(postContent) - englishLanguage = wrapper - .findAll('li') - .filter((language) => language.text() === 'English') - englishLanguage.trigger('click') }) it('title cannot be empty', async () => { @@ -147,7 +140,6 @@ describe('ContributionForm.vue', () => { variables: { title: postTitle, content: postContent, - language: 'en', id: null, image: null, }, @@ -155,10 +147,6 @@ describe('ContributionForm.vue', () => { postTitleInput = wrapper.find('.ds-input') postTitleInput.setValue(postTitle) await wrapper.vm.updateEditorContent(postContent) - englishLanguage = wrapper - .findAll('li') - .filter((language) => language.text() === 'English') - englishLanguage.trigger('click') await Vue.nextTick() await Vue.nextTick() }) @@ -168,16 +156,6 @@ describe('ContributionForm.vue', () => { expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams)) }) - it('supports changing the language', async () => { - expectedParams.variables.language = 'de' - deutschLanguage = wrapper - .findAll('li') - .filter((language) => language.text() === 'Deutsch') - deutschLanguage.trigger('click') - wrapper.find('form').trigger('submit') - expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams)) - }) - it('supports adding a teaser image', async () => { expectedParams.variables.image = { aspectRatio: null, @@ -236,10 +214,6 @@ describe('ContributionForm.vue', () => { postTitleInput.setValue(postTitle) await wrapper.vm.updateEditorContent(postContent) categoryIds = ['cat12'] - englishLanguage = wrapper - .findAll('li') - .filter((language) => language.text() === 'English') - englishLanguage.trigger('click') await Vue.nextTick() await Vue.nextTick() }) @@ -260,7 +234,6 @@ describe('ContributionForm.vue', () => { slug: 'dies-ist-ein-post', title: 'dies ist ein Post', content: 'auf Deutsch geschrieben', - language: 'de', image, categories: [ { @@ -290,7 +263,6 @@ describe('ContributionForm.vue', () => { slug: 'this-is-a-title-for-a-post', content: postContent, contentExcerpt: postContent, - language: 'en', categoryIds, }, }, @@ -301,7 +273,6 @@ describe('ContributionForm.vue', () => { variables: { title: propsData.contribution.title, content: propsData.contribution.content, - language: propsData.contribution.language, id: propsData.contribution.id, image: { sensitive: false, diff --git a/webapp/components/ContributionForm/ContributionForm.vue b/webapp/components/ContributionForm/ContributionForm.vue index 8db89173f..42ed2799e 100644 --- a/webapp/components/ContributionForm/ContributionForm.vue +++ b/webapp/components/ContributionForm/ContributionForm.vue @@ -50,17 +50,6 @@ {{ contentLength }}