@open-xchange/vite-plugin-po2json 1.0.0-pre1 → 1.0.0-pre2
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/dist/index.js +18 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -58,23 +58,27 @@ export default function gettextPlugin(options) {
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
resolveId(id) {
|
|
61
|
-
|
|
61
|
+
// Strip \0 prefix for matching (Rolldown convention for virtual modules)
|
|
62
|
+
const cleanId = id.startsWith('\0') ? id.slice(1) : id;
|
|
63
|
+
if (/^(virtual:)?gettext$/.test(cleanId)) {
|
|
62
64
|
const meta = { gettext: { dictionary: true } };
|
|
63
|
-
return { id:
|
|
65
|
+
return { id: `\0${defaultDictionary}.js`, meta };
|
|
64
66
|
}
|
|
65
|
-
const gettextModuleMatch =
|
|
67
|
+
const gettextModuleMatch = cleanId.match(/(virtual:)?gettext\?.*dictionary=([^&]+)/);
|
|
66
68
|
if (gettextModuleMatch) {
|
|
67
|
-
dictionaries.add(gettextModuleMatch[
|
|
69
|
+
dictionaries.add(gettextModuleMatch[2].replace(/\.js$/, ''));
|
|
68
70
|
const meta = { gettext: { dictionary: true } };
|
|
69
|
-
return { id: gettextModuleMatch[
|
|
71
|
+
return { id: `\0${gettextModuleMatch[2].replace(/(\.js)?$/, '.js')}`, meta };
|
|
70
72
|
}
|
|
71
|
-
if (dictionaries.has(
|
|
73
|
+
if (dictionaries.has(cleanId.replace(/\.js$/, ''))) {
|
|
72
74
|
const meta = { gettext: { dictionary: true } };
|
|
73
|
-
return { id
|
|
75
|
+
return { id: id.startsWith('\0') ? id : `\0${id}`, meta };
|
|
74
76
|
}
|
|
75
|
-
const match =
|
|
77
|
+
const match = cleanId.match(/(.*)\.([a-zA-Z]{2}_[a-zA-Z]{2})(\.js)?$/);
|
|
76
78
|
const [, namespace, language] = match || [];
|
|
77
|
-
|
|
79
|
+
if (namespace && language)
|
|
80
|
+
return id.startsWith('\0') ? id : `\0${id}`;
|
|
81
|
+
return null;
|
|
78
82
|
},
|
|
79
83
|
transform: {
|
|
80
84
|
order: 'pre',
|
|
@@ -83,7 +87,9 @@ export default function gettextPlugin(options) {
|
|
|
83
87
|
}
|
|
84
88
|
},
|
|
85
89
|
async load(id) {
|
|
86
|
-
|
|
90
|
+
if (!id.startsWith('\0'))
|
|
91
|
+
return;
|
|
92
|
+
const dictionary = id.slice(1).replace(/\\/g, '/').replace(/^\.?\//, '').replace(/\.js$/, '');
|
|
87
93
|
if (dictionaries.has(dictionary)) {
|
|
88
94
|
const poDir = path.dirname(poFiles);
|
|
89
95
|
const languages = (await readdir(poDir)).map(f => (f.match(/([^/]+).po$/) || [])[1]).filter(a => Boolean(a));
|
|
@@ -94,7 +100,8 @@ export default function gettextPlugin(options) {
|
|
|
94
100
|
.replaceAll(/['"]{{languages}}['"]/g, languages.map(lang => `'${lang}'`).join(', '));
|
|
95
101
|
return { meta: { gettext: { dictionary: true } }, code };
|
|
96
102
|
}
|
|
97
|
-
const
|
|
103
|
+
const cleanId = id.slice(1);
|
|
104
|
+
const match = cleanId.match(/\.?\/?(.*)\.([a-zA-Z]{2}_[a-zA-Z]{2})(\.js)?$/);
|
|
98
105
|
const [, namespace, language] = match || [];
|
|
99
106
|
if (!namespace || !language || !dictionaries.has(namespace))
|
|
100
107
|
return;
|
package/package.json
CHANGED