i18n — Locale URLs Name the Shipped English File
RULES.md
An element points the i18n manager at its locales by naming its English locale file and stepping back to the folder: `new URL("./locales/<tag>.en.json", import.meta.url).href + "/../"` (from `lib/`, `../locales/<tag>.en.json`). This applies to `registerLocalization` and to the haxProperties `i18n-manager-register-element` event alike. Never point `new URL()` at the folder (`"./locales/"`, `` `./locales` ``) or at a language file the element does not commit (such as a scaffold's `.ar.json`): bundlers using `@web/rollup-plugin-import-meta-assets` fail on both (EISDIR on 1.x, ENOENT on every version). Name the file literally, never with a runtime expression such as `` `../locales/${this.tag}.es.json` `` (`tag` is static, so on an instance that is `undefined`, and a bundler cannot resolve it). A base element that sites subclass with their own tag passes `namespace: "<tag>"` so the subclass still loads its translations. The `"/../"` resolves back to `locales/`, so the runtime fetch is identical unbundled. Anchor on English because it is the one locale file every element commits (feature PRs are English-only). An element with only haxProperties locales anchors on a haxProperties file it ships. A bundled site still copies element `locales/*.json` next to the emitted anchor asset if it wants languages beyond the anchor. Enforced in haxtheweb/webcomponents by `yarn lint:locale-urls` (blocking in `yarn precheck` and CI). The `hax webcomponent` templates ship `<name>.en.json` and anchor on it. Extends haxtheweb/issues#1616. Tracking: <https://github.com/haxtheweb/issues/issues/3402>. In PRAW RULES.md (scope: webcomponents). Enforced by Locale URLs point at a shipped locale file. Partly. Template lint's locale-url check fails the pull request when new URL() for locales names the locales/ folder or a file that doesn't ship; that it is the English file is checked in review.
Connects to
- Web Component Development includes this
- Locale URLs point at a shipped locale file enforces this