cockpit-po-plugin: add a 'podir' option

This plugin assumes that the 'po' directory is located at `$SRCDIR/po`
or `./po` if `$SRCDIR` is unset.  That conflicts with our desire to be
able to run `build.js` from other directories and is also a little bit
"evil" in terms of hardcoding information about project layout.

Add an optional `podir` option to the plugin which should be set to the
`po/` path.  Set it from `build.js` for Cockpit itself.  For other users
of the plugin, we preserve the fallback of using `$SRCDIR/po` or `./po`
so that we don't break them on the next cockpitlib upgrade.  The
expectation is that everyone will migrate to providing the `podir`
option, however.
This commit is contained in:
Allison Karlitskaya 2026-11-02 15:47:45 +01:00 committed by Allison Karlitskaya
parent 5f3c0e9b8b
commit bcbd5d0c01
2 changed files with 4 additions and 6 deletions

View file

@ -170,6 +170,7 @@ async function build() {
const pkgLastPlugins = [
cockpitPoEsbuildPlugin({
podir: path.join(srcdir, 'po'),
subdirs: args.onlydir ? [args.onlydir] : all_subdirs,
// login page does not have cockpit.js, but reads window.cockpit_po
wrapper: subdir => subdir == "static" ? "window.cockpit_po = PO_DATA;" : undefined,

View file

@ -1,8 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import gettext_parser from "gettext-parser";
const config = {};
@ -11,11 +9,10 @@ const DEFAULT_WRAPPER = 'cockpit.locale(PO_DATA);';
const RTL_LANGS = new Set(["ar", "fa", "he", "ur"]);
function get_po_files() {
const poDir = path.resolve(config.srcdir, 'po');
try {
return fs.readdirSync(poDir)
return fs.readdirSync(config.podir)
.filter(file => file.endsWith('.po'))
.map(file => path.join(poDir, file));
.map(file => path.join(config.podir, file));
} catch (error) {
return [];
}
@ -182,7 +179,7 @@ function buildFile(data, subdir, filename, filter) {
}
function init(options) {
config.srcdir = process.env.SRCDIR || './';
config.podir = options.podir || path.resolve(process.env.SRCDIR || './', 'po');
config.subdirs = options.subdirs || [''];
config.src_directory = options.src_directory || 'src';
config.wrapper = options.wrapper;