From d75db01f14138ea660c4c519e37ab05228b39d13 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Jul 2019 14:44:50 +0200 Subject: Add plugin translation system --- .../peertube-plugin-test-three/package.json | 3 +- .../peertube-plugin-test-two/languages/fr.json | 3 + .../peertube-plugin-test-two/languages/it.json | 3 + .../fixtures/peertube-plugin-test-two/package.json | 6 +- .../peertube-plugin-test/languages/fr.json | 3 + .../fixtures/peertube-plugin-test/package.json | 5 +- server/tests/plugins/index.ts | 1 + server/tests/plugins/translations.ts | 113 +++++++++++++++++++++ 8 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 server/tests/fixtures/peertube-plugin-test-two/languages/fr.json create mode 100644 server/tests/fixtures/peertube-plugin-test-two/languages/it.json create mode 100644 server/tests/fixtures/peertube-plugin-test/languages/fr.json create mode 100644 server/tests/plugins/translations.ts (limited to 'server/tests') diff --git a/server/tests/fixtures/peertube-plugin-test-three/package.json b/server/tests/fixtures/peertube-plugin-test-three/package.json index 3f7819db3..41d4c93fe 100644 --- a/server/tests/fixtures/peertube-plugin-test-three/package.json +++ b/server/tests/fixtures/peertube-plugin-test-three/package.json @@ -15,5 +15,6 @@ "library": "./main.js", "staticDirs": {}, "css": [], - "clientScripts": [] + "clientScripts": [], + "translations": {} } diff --git a/server/tests/fixtures/peertube-plugin-test-two/languages/fr.json b/server/tests/fixtures/peertube-plugin-test-two/languages/fr.json new file mode 100644 index 000000000..52d8313df --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-two/languages/fr.json @@ -0,0 +1,3 @@ +{ + "Hello world": "Bonjour le monde" +} diff --git a/server/tests/fixtures/peertube-plugin-test-two/languages/it.json b/server/tests/fixtures/peertube-plugin-test-two/languages/it.json new file mode 100644 index 000000000..9e187d83b --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-two/languages/it.json @@ -0,0 +1,3 @@ +{ + "Hello world": "Ciao, mondo!" +} diff --git a/server/tests/fixtures/peertube-plugin-test-two/package.json b/server/tests/fixtures/peertube-plugin-test-two/package.json index 52ebb5ac1..926f2d69b 100644 --- a/server/tests/fixtures/peertube-plugin-test-two/package.json +++ b/server/tests/fixtures/peertube-plugin-test-two/package.json @@ -15,5 +15,9 @@ "library": "./main.js", "staticDirs": {}, "css": [], - "clientScripts": [] + "clientScripts": [], + "translations": { + "fr-FR": "./languages/fr.json", + "it-IT": "./languages/it.json" + } } diff --git a/server/tests/fixtures/peertube-plugin-test/languages/fr.json b/server/tests/fixtures/peertube-plugin-test/languages/fr.json new file mode 100644 index 000000000..9e52f7065 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test/languages/fr.json @@ -0,0 +1,3 @@ +{ + "Hi": "Coucou" +} diff --git a/server/tests/fixtures/peertube-plugin-test/package.json b/server/tests/fixtures/peertube-plugin-test/package.json index 9d6fe5c90..108f21fd6 100644 --- a/server/tests/fixtures/peertube-plugin-test/package.json +++ b/server/tests/fixtures/peertube-plugin-test/package.json @@ -15,5 +15,8 @@ "library": "./main.js", "staticDirs": {}, "css": [], - "clientScripts": [] + "clientScripts": [], + "translations": { + "fr-FR": "./languages/fr.json" + } } diff --git a/server/tests/plugins/index.ts b/server/tests/plugins/index.ts index 95e358732..f41708055 100644 --- a/server/tests/plugins/index.ts +++ b/server/tests/plugins/index.ts @@ -1,3 +1,4 @@ import './action-hooks' import './filter-hooks' +import './translations' import './video-constants' diff --git a/server/tests/plugins/translations.ts b/server/tests/plugins/translations.ts new file mode 100644 index 000000000..88d91a033 --- /dev/null +++ b/server/tests/plugins/translations.ts @@ -0,0 +1,113 @@ +/* tslint:disable:no-unused-expression */ + +import * as chai from 'chai' +import 'mocha' +import { + cleanupTests, + flushAndRunMultipleServers, + flushAndRunServer, killallServers, reRunServer, + ServerInfo, + waitUntilLog +} from '../../../shared/extra-utils/server/servers' +import { + addVideoCommentReply, + addVideoCommentThread, + deleteVideoComment, + getPluginTestPath, + getVideosList, + installPlugin, + removeVideo, + setAccessTokensToServers, + updateVideo, + uploadVideo, + viewVideo, + getVideosListPagination, + getVideo, + getVideoCommentThreads, + getVideoThreadComments, + getVideoWithToken, + setDefaultVideoChannel, + waitJobs, + doubleFollow, getVideoLanguages, getVideoLicences, getVideoCategories, uninstallPlugin, getPluginTranslations +} from '../../../shared/extra-utils' +import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' +import { VideoDetails } from '../../../shared/models/videos' +import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports' + +const expect = chai.expect + +describe('Test plugin translations', function () { + let server: ServerInfo + + before(async function () { + this.timeout(30000) + + server = await flushAndRunServer(1) + await setAccessTokensToServers([ server ]) + + await installPlugin({ + url: server.url, + accessToken: server.accessToken, + path: getPluginTestPath() + }) + + await installPlugin({ + url: server.url, + accessToken: server.accessToken, + path: getPluginTestPath('-two') + }) + }) + + it('Should not have translations for locale pt', async function () { + const res = await getPluginTranslations({ url: server.url, locale: 'pt' }) + + expect(res.body).to.deep.equal({}) + }) + + it('Should have translations for locale fr', async function () { + const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' }) + + expect(res.body).to.deep.equal({ + 'peertube-plugin-test': { + 'Hi': 'Coucou' + }, + 'peertube-plugin-test-two': { + 'Hello world': 'Bonjour le monde' + } + }) + }) + + it('Should have translations of locale it', async function () { + const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' }) + + expect(res.body).to.deep.equal({ + 'peertube-plugin-test-two': { + 'Hello world': 'Ciao, mondo!' + } + }) + }) + + it('Should remove the plugin and remove the locales', async function () { + await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-two' }) + + { + const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' }) + + expect(res.body).to.deep.equal({ + 'peertube-plugin-test': { + 'Hi': 'Coucou' + } + }) + } + + { + const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' }) + + expect(res.body).to.deep.equal({}) + } + }) + + after(async function () { + await cleanupTests([ server ]) + }) +}) -- cgit v1.2.3