@open-xchange/vite-plugin-ox-manifests 0.4.2 → 0.4.3
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/package.json +1 -1
- package/src/plugins/gettext.js +4 -2
- package/test/gettext-chunked/another_chunk.js +4 -0
- package/test/gettext-chunked/i18n/de_DE.po +16 -0
- package/test/gettext-chunked/i18n/en_US.po +16 -0
- package/test/gettext-chunked/main.test.js +68 -0
- package/test/gettext-chunked/manifest.json +3 -0
- package/test/gettext-chunked/register.js +6 -0
package/package.json
CHANGED
package/src/plugins/gettext.js
CHANGED
|
@@ -54,9 +54,11 @@ export default function () {
|
|
|
54
54
|
const chunk = bundle[file]
|
|
55
55
|
if (!chunk.facadeModuleId) continue
|
|
56
56
|
|
|
57
|
-
Object.keys(chunk.modules)
|
|
57
|
+
const modules = Object.keys(chunk.modules)
|
|
58
|
+
if (modules.length === 0) modules.push(chunk.facadeModuleId)
|
|
59
|
+
modules.forEach(id => {
|
|
58
60
|
const meta = this.getModuleInfo(id)?.meta
|
|
59
|
-
if (
|
|
61
|
+
if (meta?.gettext?.dictionary !== true) return
|
|
60
62
|
|
|
61
63
|
meta.manifests = meta.manifests || []
|
|
62
64
|
meta.manifests.push({ namespace: 'i18n' })
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
msgid ""
|
|
2
|
+
msgstr ""
|
|
3
|
+
"Project-Id-Version: \n"
|
|
4
|
+
"PO-Revision-Date: 2014-01-15 14:13+0100\n"
|
|
5
|
+
"Last-Translator: Julian Bäume <julian.baeume@open-xchange.com>\n"
|
|
6
|
+
"Language-Team: German <julian.baeume@open-xchange.com>\n"
|
|
7
|
+
"Language: de_DE\n"
|
|
8
|
+
"MIME-Version: 1.0\n"
|
|
9
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
|
10
|
+
"Content-Transfer-Encoding: 8bit\n"
|
|
11
|
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
|
12
|
+
"X-Generator: Lokalize 1.5\n"
|
|
13
|
+
|
|
14
|
+
#: module:i18n
|
|
15
|
+
msgid "Hello world!"
|
|
16
|
+
msgstr "Hallo Welt!"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
msgid ""
|
|
2
|
+
msgstr ""
|
|
3
|
+
"Project-Id-Version: \n"
|
|
4
|
+
"PO-Revision-Date: 2014-01-15 14:13+0100\n"
|
|
5
|
+
"Last-Translator: Julian Bäume <julian.baeume@open-xchange.com>\n"
|
|
6
|
+
"Language-Team: German <julian.baeume@open-xchange.com>\n"
|
|
7
|
+
"Language: en_US\n"
|
|
8
|
+
"MIME-Version: 1.0\n"
|
|
9
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
|
10
|
+
"Content-Transfer-Encoding: 8bit\n"
|
|
11
|
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
|
12
|
+
"X-Generator: Lokalize 1.5\n"
|
|
13
|
+
|
|
14
|
+
#: module:i18n
|
|
15
|
+
msgid "Hello world!"
|
|
16
|
+
msgstr ""
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from '@jest/globals'
|
|
2
|
+
import { build, createServer } from 'vite'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import vitePluginOxManifests from '../../index'
|
|
5
|
+
import rollupPluginPo2Json from '@open-xchange/rollup-plugin-po2json'
|
|
6
|
+
import { getFileFromBundle, getPort } from '../util'
|
|
7
|
+
import axios from 'axios'
|
|
8
|
+
|
|
9
|
+
const PORT = getPort()
|
|
10
|
+
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
11
|
+
|
|
12
|
+
describe('Dictionary in modules with dynamic imports', function () {
|
|
13
|
+
let server
|
|
14
|
+
|
|
15
|
+
afterEach(async function () {
|
|
16
|
+
if (server) {
|
|
17
|
+
await server.close()
|
|
18
|
+
server = null
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('works', async function () {
|
|
23
|
+
const bundle = await build({
|
|
24
|
+
root: __dirname,
|
|
25
|
+
logLevel: 'silent',
|
|
26
|
+
build: {
|
|
27
|
+
write: false,
|
|
28
|
+
rollupOptions: {
|
|
29
|
+
input: { }
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
plugins: [rollupPluginPo2Json({
|
|
33
|
+
poFiles: __dirname + '/i18n/*.po'
|
|
34
|
+
}), vitePluginOxManifests({
|
|
35
|
+
|
|
36
|
+
})]
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const manifestFile = getFileFromBundle('manifest', bundle)
|
|
40
|
+
const manifests = JSON.parse(manifestFile.source)
|
|
41
|
+
expect(Object.keys(manifests)).toHaveLength(6)
|
|
42
|
+
expect(manifests['register.js'].meta.manifests[0].namespace).toEqual('test')
|
|
43
|
+
expect(manifests['../../i18n.js'].meta.gettext.dictionary).toEqual(true)
|
|
44
|
+
expect(manifests['../../i18n.js'].meta.manifests[0].namespace).toEqual('i18n')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('works in dev mode', async function () {
|
|
48
|
+
server = await createServer({
|
|
49
|
+
root: __dirname,
|
|
50
|
+
logLevel: 'silent',
|
|
51
|
+
plugins: [rollupPluginPo2Json({
|
|
52
|
+
poFiles: __dirname + '/i18n/*.po'
|
|
53
|
+
}), vitePluginOxManifests({
|
|
54
|
+
|
|
55
|
+
})]
|
|
56
|
+
})
|
|
57
|
+
await server.listen(PORT)
|
|
58
|
+
|
|
59
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/api/manifest.json` })
|
|
60
|
+
const manifests = res.data
|
|
61
|
+
|
|
62
|
+
expect(manifests).toHaveLength(2)
|
|
63
|
+
expect(manifests[0].namespace).toEqual('i18n')
|
|
64
|
+
expect(manifests[0].path).toEqual('i18n')
|
|
65
|
+
expect(manifests[1].namespace).toEqual('test')
|
|
66
|
+
expect(manifests[1].path).toContain('register')
|
|
67
|
+
})
|
|
68
|
+
})
|