livelocale 0.9.0 → 0.10.0-next.7

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/README.md CHANGED
@@ -195,6 +195,37 @@ Generates API route handlers based on your router structure (App vs Pages Router
195
195
  npx livelocale init [--dir <path>]
196
196
  ```
197
197
 
198
+ ### `init --share`
199
+
200
+ Sets up the share link for your stack and, on a GitHub remote, writes
201
+ `.github/workflows/livelocale.yml`, which turns change links into pull requests. It prints every
202
+ file it creates, updates, leaves unchanged or skips, then what is left for you to do.
203
+
204
+ ```bash
205
+ npx livelocale init --share [--locales <path>] [--source <locale>] [--branches <a,b>] [--overwrite] [--dir <path>]
206
+ ```
207
+
208
+ | Stack | Build change |
209
+ | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
210
+ | CRA / webpack / Rsbuild | `"build": "react-scripts build && livelocale pack build"`. This is an explicit `&&`, not a `postbuild` hook, because Yarn Berry and some pnpm versions skip pre/post scripts, and hosts that call the bundler directly skip them too ([yarn](https://v2.yarnpkg.com/advanced/lifecycle-scripts), [pnpm](https://pnpm.io/cli/run)). |
211
+ | Next.js `output: 'export'` | `"build:preview": "livelocale build --preview -- next build"`, deployed to a staging location, because the HTML is pre-rendered and must be watermarked at build time. |
212
+ | Next.js on Vercel/Node | For the Preview environment, use the build command `livelocale build --preview -- next build`. It packs into a gitignored `public/livelocale/`. |
213
+ | Custom CI | `LIVELOCALE=preview <your build>` (only for SSR/SSG), then `npx livelocale pack <outDir>`. |
214
+
215
+ For Vite it adds `share: true` to your `liveLocaleVite({ ... })` call. The scripts it writes also
216
+ pass `--locales` and `--source`; webpack and Rsbuild pack `dist`.
217
+
218
+ - `--locales` — locales directory relative to the project (default: the first of `locales`,
219
+ `src/locales`, `public/locales`, `src/i18n/locales` and `messages` that holds locale JSON).
220
+ - `--source` — source locale (default `en`).
221
+ - `--branches` — branches a change link may target (default: the repository's default branch, at
222
+ most 10). Merge the workflow into each of them too: a pull request into a branch runs that
223
+ branch's copy of the workflow.
224
+ - `--overwrite` — replace an existing workflow file whose content differs (it is skipped otherwise).
225
+ - On another git host no workflow is written; use `npx livelocale apply "<link>" --pr`.
226
+
227
+ Commit and push the result: the workflow must be on the default branch.
228
+
198
229
  ### `studio`
199
230
 
200
231
  Spins up a lightweight, CORS-enabled HTTP server serving the Visual Studio assets statically.
@@ -343,6 +374,28 @@ The summary lists each edit's locale, key and status (applied, already done, con
343
374
  applied or already done, and 1 when any edit is a conflict, needs `--force` or was rejected, or
344
375
  when the link cannot be read.
345
376
 
377
+ #### `apply --github-event`
378
+
379
+ ```bash
380
+ npx livelocale apply --github-event --locales <path> --source <locale> [--branches <a,b>] [--dir <path>]
381
+ ```
382
+
383
+ For the generated `.github/workflows/livelocale.yml` workflow only; do not run it yourself. It reads
384
+ the issue, comment, dispatch or pull request event from `$GITHUB_EVENT_PATH` (never from the
385
+ command line) and needs `GITHUB_TOKEN`.
386
+
387
+ - Only a maintainer (OWNER, MEMBER or COLLABORATOR, or write access) makes it write. Anyone else
388
+ gets the reply "Waiting for a maintainer: comment `/livelocale apply`".
389
+ - It writes one commit on a `livelocale/issue-<n>` branch (`livelocale/run-<id>` for a manual
390
+ run), opens or reuses the pull request, and comments the link on the issue. When the repository
391
+ does not let GitHub Actions open pull requests, the comment carries a one-click compare link
392
+ instead.
393
+ - `--locales` and `--dir` are relative to the repository root. `--branches` lists the branches a
394
+ link may target (default: the repository's default branch); a link made from any other branch
395
+ targets the default branch, and the comment says so.
396
+ - `--force` is not accepted; a maintainer comments `/livelocale apply --force` instead.
397
+ - When the pull request is merged or closed, it closes the issue.
398
+
346
399
  ### `migrate`
347
400
 
348
401
  Performs static analysis to scan and automatically wrap existing `react-i18next` hooks with `wrapTranslationEngine`.
@@ -464,14 +517,60 @@ it. Without `reference` only the syntax check runs.
464
517
 
465
518
  ## 🔗 Share link on any host
466
519
 
467
- A share link lets a translator fix copy on your deployed site, with no server, no account and no
468
- credential anywhere. The Studio ships inside your build at `<base>livelocale/`, so any host that
469
- serves the site serves the Studio too: Apache, Nginx, S3, GitHub Pages, Netlify, Cloudflare Pages
470
- or Vercel. The translator's fixes stay in their own browser until they send you a change link, and
471
- you turn that link into a pull request with one command.
520
+ Translators fix text on your live site with no account, and every fix becomes a pull request with one click.
521
+
522
+ A share link needs no server, no account and no credential anywhere. The Studio ships inside your
523
+ build at `<base>livelocale/`, so any host that serves the site serves the Studio too: Apache,
524
+ Nginx, S3, GitHub Pages, Netlify, Cloudflare Pages or Vercel. The translator's fixes stay in their
525
+ own browser until they send you a change link. On GitHub you turn that link into a pull request
526
+ with one click; on any other git host, with one command.
472
527
 
473
528
  ### Setup
474
529
 
530
+ 1. Run `npx livelocale init --share` in your project. It sets up the build for your stack (see the
531
+ table below) and, on a GitHub remote, writes `.github/workflows/livelocale.yml`. See
532
+ [`init --share`](#init---share) for its options.
533
+ 2. Commit and push the result. The workflow must be on the default branch, because GitHub runs
534
+ issue and comment workflows only from there.
535
+ 3. On GitHub, tick the one setting below.
536
+ 4. Deploy as usual, then check the deployment and print the share link (next step).
537
+
538
+ On a GitHub remote, `init --share` writes this workflow (`X.Y.Z` is the livelocale version you
539
+ installed, `locales`, `en` and `main` come from your project):
540
+
541
+ ````yaml
542
+ # Written by `npx livelocale init --share`. Turns LiveLocale change links into pull requests.
543
+ # livelocale reads the link from the event file; it never reaches a shell command.
544
+ name: LiveLocale
545
+ on:
546
+ issues: { types: [opened] }
547
+ issue_comment: { types: [created] }
548
+ pull_request: { types: [closed] }
549
+ workflow_dispatch: { inputs: { link: { description: 'LiveLocale change link', required: true } } }
550
+ permissions: { contents: write, pull-requests: write, issues: write }
551
+ concurrency: { group: 'livelocale-${{ github.event.issue.number || github.run_id }}', queue: max }
552
+ jobs:
553
+ apply:
554
+ if: >-
555
+ github.event_name == 'workflow_dispatch' ||
556
+ (github.event_name == 'issues' && contains(github.event.issue.body, '```livelocale')) ||
557
+ (github.event_name == 'issue_comment' && !github.event.issue.pull_request &&
558
+ startsWith(github.event.comment.body, '/livelocale')) ||
559
+ (github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'livelocale/issue-') &&
560
+ github.event.pull_request.base.ref != github.event.repository.default_branch)
561
+ runs-on: ubuntu-latest
562
+ steps:
563
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
564
+ with: { persist-credentials: false }
565
+ - run: npx --yes livelocale@X.Y.Z apply --github-event --locales locales --source en --branches main
566
+ env: { GITHUB_TOKEN: '${{ github.token }}' }
567
+ ````
568
+
569
+ It reads the change link only from the event file, never from a shell command, and it has no
570
+ `pull_request_target` trigger.
571
+
572
+ To set up the build by hand instead:
573
+
475
574
  | Stack | Build change |
476
575
  | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
477
576
  | Vite | `share: true` in `liveLocaleVite(...)` (see [Share link from `vite build`](#share-link-from-vite-build)). |
@@ -492,6 +591,14 @@ npx livelocale doctor --app <url>
492
591
  The doctor checks the Studio page, the manifest, `flag.js`, frame headers and service workers, then
493
592
  prints `🔗 Share link: <base>livelocale/index.html`. Pin that link for your translators.
494
593
 
594
+ #### The one-checkbox setting
595
+
596
+ In the repository's **Settings → Actions → General → Workflow permissions**, tick
597
+ **Allow GitHub Actions to create and approve pull requests**. Without it the workflow still
598
+ commits the branch, but GitHub refuses to let it open the pull request; the issue comment then
599
+ carries a one-click compare link that opens the pull request form already filled in, and you
600
+ press **Create pull request** there.
601
+
495
602
  ### Translator steps
496
603
 
497
604
  1. Open the share link in a desktop browser. There is no sign-up, no password and nothing to
@@ -513,18 +620,79 @@ prints `🔗 Share link: <base>livelocale/index.html`. Pin that link for your tr
513
620
  ### Developer
514
621
 
515
622
  Open the change link. The Studio opens in **Review mode**, with the proposed edits shown read-only
516
- on the real page and a before/after table with the check results. Then apply it:
623
+ on the real page and a before/after table with the check results. Then turn it into a pull request.
624
+
625
+ **On GitHub, with the workflow:**
626
+
627
+ - Press **Create pull request** in Review mode. It opens a GitHub issue already filled in with the
628
+ change link; press **Submit new issue**. About a minute later the workflow has committed the
629
+ edits on a `livelocale/issue-<n>` branch, opened the pull request and commented its link on the
630
+ issue. Without `exposeRepo: true`, Review mode asks for `owner/repo` the first time and remembers
631
+ it in that browser.
632
+ - With issues turned off, or for a link you would rather not file: **Actions → LiveLocale → Run
633
+ workflow**, paste the link and run it. The result is on the run's summary page.
634
+ - **The trust gate.** The workflow writes only for a maintainer: the issue author or the
635
+ commenter must be an owner, member or collaborator, or have write access. For anyone else it
636
+ replies "Waiting for a maintainer: comment `/livelocale apply`", and nothing is written until a
637
+ maintainer posts that comment on the issue. Edits the translator saved with "Save anyway" are
638
+ skipped as `needs --force`; comment `/livelocale apply --force` to include them.
639
+ - **Base branches.** By default every pull request targets the default branch. To let links made
640
+ from other builds (for example a `staging` deployment) target their own branch, list the
641
+ branches with `npx livelocale init --share --branches main,staging`. A link from any other
642
+ branch targets the default branch, and the comment says so. A pull request into the default
643
+ branch says `Closes #n`, so merging it closes the issue; into another branch it says `Refs #n`,
644
+ because GitHub only closes issues from the default branch, and LiveLocale closes the issue
645
+ itself when that pull request is merged or closed.
646
+ Also merge .github/workflows/livelocale.yml into each extra branch; pull requests into it run workflows from that branch, so LiveLocale cannot close their issues otherwise.
647
+
648
+ **On any git host, from your machine:**
517
649
 
518
650
  ```bash
519
651
  npx livelocale apply "<link or file>" --pr
520
652
  ```
521
653
 
522
- This works on any git host, with your own `git` login: it commits only the locale files on a new
654
+ This works with your own `git` login: it commits only the locale files on a new
523
655
  `livelocale/apply-<time>` branch and pushes it. On GitHub it opens the pull request with `gh`;
524
656
  elsewhere it prints the branch to open a pull or merge request from. Every edit is checked again
525
657
  against your own files first. For a long link, use `npx livelocale apply --clipboard`, or pass `-` and pipe
526
658
  the link in (`npx livelocale apply - < changes.txt`). See [`apply`](#apply) for every option.
527
659
 
660
+ #### Run CI on LiveLocale PRs without the approval click
661
+
662
+ Pull requests opened with the workflow's `GITHUB_TOKEN` start their CI in an approval-required
663
+ state: someone has to press **Approve workflows to run** on each one. Pull requests opened with a
664
+ GitHub App token start CI as usual. To use one:
665
+
666
+ 1. Create a GitHub App with **Contents**, **Pull requests** and **Issues** set to read and write,
667
+ and install it on the repository.
668
+ 2. Store its ID as the repository variable `LIVELOCALE_APP_ID` and its private key as the secret
669
+ `LIVELOCALE_APP_PRIVATE_KEY`.
670
+ 3. In `.github/workflows/livelocale.yml`, add this step before the `apply` step and give its token
671
+ to the `apply` step as `GITHUB_TOKEN`:
672
+
673
+ ```yaml
674
+ - id: app-token
675
+ uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
676
+ with:
677
+ {
678
+ app-id: '${{ vars.LIVELOCALE_APP_ID }}',
679
+ private-key: '${{ secrets.LIVELOCALE_APP_PRIVATE_KEY }}',
680
+ }
681
+ - run: npx --yes livelocale@X.Y.Z apply --github-event --locales locales --source en --branches main
682
+ env: { GITHUB_TOKEN: '${{ steps.app-token.outputs.token }}' }
683
+ ```
684
+
685
+ `init --share` leaves an edited workflow alone unless you pass `--overwrite`.
686
+
687
+ ### Translators with GitHub access
688
+
689
+ **Open on GitHub** in the Send dialog lets a translator file the issue themselves, so the pull
690
+ request opens with no developer click when the translator is a collaborator (otherwise a
691
+ maintainer comments `/livelocale apply`). It is available only with `exposeRepo: true`, because it
692
+ needs the repository's `owner/repo` in the public manifest. Turn it on for a private repository
693
+ whose translators already have GitHub access; with the default, translators use **Copy link** or
694
+ **Download file**, and the developer path is unchanged.
695
+
528
696
  ### What "Sent" means
529
697
 
530
698
  In this mode "Sent" means the translator handed the link over; it is not a pull request until a developer applies it.
@@ -564,6 +732,19 @@ In this mode "Sent" means the translator handed the link over; it is not a pull
564
732
  scripts can read and alter drafts. This is accepted because no secret is stored, and you review
565
733
  every edit before it is merged.
566
734
 
735
+ ### Honest risks
736
+
737
+ - **Issues in public repositories are public.** A change link filed as an issue, with its text,
738
+ the translator's name and note, is visible to everyone.
739
+ - **Bot pull requests wait for a click.** CI on a pull request the workflow opens waits until
740
+ someone presses **Approve workflows to run**, unless you use the
741
+ [App token](#run-ci-on-livelocale-prs-without-the-approval-click).
742
+ - **Vercel may refuse the commit.** Vercel can block deployments of commits whose author is not a
743
+ member of the Vercel team. The commit author is the maintainer who triggered the run, with a
744
+ `Translated-by:` trailer for the translator.
745
+ - **One-click automation is GitHub-only.** Other git hosts use
746
+ `npx livelocale apply "<link>" --pr`, which works anywhere git works.
747
+
567
748
  ### Limits
568
749
 
569
750
  - **Desktop only.** Alt+Click needs a keyboard; phones and tablets can only view.