Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: npx tsc --noEmit

- name: Lint l10n strings
run: npm run l10n -- --lint
run: npm run l10n extract -- --lint

test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pre-push:
- name: tsc
run: npx tsc
- name: lint l10n strings
run: npm run l10n -- --lint
run: npm run l10n extract -- --lint

post-merge:
only:
Expand Down
2 changes: 1 addition & 1 deletion l10n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ We have a few pseudo locales for testing if strings have been added, or if compo
- `qaa`: "accented" locale: adds accents to all characters, duplicates some vowels to create longer strings, wraps string in square brackets to help detect truncation
- `qai`: "id" locale: replaces strings with their identifiers, wrapped in square brackets

The `qai` locale works all the time, the `qaa` locale must be manually generated with `npm run l10n -- --gen-pseudo`
The `qai` locale works all the time, the `qaa` locale must be manually generated with `npm run l10n extract -- --gen-pseudo`

## For localizers

Expand Down
47 changes: 30 additions & 17 deletions l10n/cli.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { extract } from "./parser/extractor.js";
import { generateQaaLocale } from "./parser/transform.js";
import yargs from "yargs";

const help = process.argv.includes("--help");
if (help) {
console.log(`Generates template.ftl by combining en-US.ftl and inline l10n tagged strings
import { hideBin } from "yargs/helpers";

Usage:
--lint Don't write the file, just check if it needs updating
--gen-pseudo Generate pseudo-locales for QA
`);
} else {
const lint = process.argv.includes("--lint");
await extract({ lint });
import { extract } from "./parser/extractor.js";
import { generateQaaLocale } from "./parser/transform.js";

const generatePseudo = process.argv.includes("--gen-pseudo");
if (generatePseudo) {
await generateQaaLocale();
}
}
await yargs(hideBin(process.argv))
.command({
command: "extract",

@caugner caugner Mar 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be called sync or fix?

describe:
"Generates template.ftl by combining en-US.ftl and inline l10n tagged strings",
builder: (yargs) =>
yargs
.option("lint", {

@caugner caugner Mar 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a separate lint command?

Otherwise, to avoid confusion, we could call the option check (like prettier --check and cargo fmt -- --check).

describe: "Don't write the file, just check if it needs updating",
type: "boolean",
default: false,
})
.option("gen-pseudo", {
describe: "Generate pseudo-locales for QA",
type: "boolean",
default: false,
}),
handler: async ({ lint, genPseudo }) => {
await extract({ lint });
if (genPseudo) {
await generateQaaLocale();
}
},
})
.demandCommand()
.parse();
4 changes: 2 additions & 2 deletions l10n/parser/extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Node, Project, SyntaxKind } from "ts-morph";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const TEMPLATE_HEADER = `WARNING: do not edit this file, it's automatically generated by \`npm run l10n\`.
const TEMPLATE_HEADER = `WARNING: do not edit this file, it's automatically generated by \`npm run l10n extract\`.
If you need to manually add strings, do so in ./locales/en-US.ftl. See ./README.md for more details.`;

/**
Expand All @@ -40,7 +40,7 @@ export async function extract(options = {}) {
const existing = await readFile(outputPath, "utf8");
if (existing !== output) {
throw new Error(
"l10n template.ftl is out of date. Run `npm run l10n` to update.",
"l10n template.ftl is out of date. Run `npm run l10n extract` to update.",
);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion l10n/template.ftl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# WARNING: do not edit this file, it's automatically generated by `npm run l10n`.
# WARNING: do not edit this file, it's automatically generated by `npm run l10n extract`.
# If you need to manually add strings, do so in ./locales/en-US.ftl. See ./README.md for more details.

article-footer-last-modified = This page was last modified on <time data-l10n-name="date">{ $date }</time> by <a data-l10n-name="contributors">MDN contributors</a>.
Expand Down
Loading
Loading