Skip to content

Commit 4b42b8e

Browse files
committed
Update i18n.md to explain bin/dev precompile_hook coordination
References the idempotent locale generation feature (PR #2093) and explains how bin/dev automatically coordinates the precompile hook.
1 parent 6a6bc08 commit 4b42b8e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

docs/building-features/i18n.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,31 @@ You can use [Rails internationalization (i18n)](https://guides.rubyonrails.org/i
2121

2222
3. The locale files must be generated before `yarn build` using `rake react_on_rails:locale`.
2323

24-
For development, you should adjust your startup scripts (`Procfile`s) so that they run `bundle exec rake react_on_rails:locale` before running any Webpack watch process (`yarn run build:development`).
24+
**Recommended: Use Shakapacker's precompile_hook with bin/dev** (React on Rails 16.2+, Shakapacker 9.3+)
2525

26-
If you are not using the React on Rails test helper,
27-
you may need to configure your CI to run `bundle exec rake react_on_rails:locale` before any Webpack process as well.
26+
The locale generation task is idempotent and can be safely called multiple times. Configure it in Shakapacker's `precompile_hook` and `bin/dev` will handle coordination automatically:
27+
28+
```yaml
29+
# config/shakapacker.yml
30+
default: &default
31+
# Run locale generation before webpack compilation
32+
# Safe to run multiple times - will skip if already built
33+
precompile_hook: 'bundle exec rake react_on_rails:locale'
34+
```
35+
36+
With this configuration, `bin/dev` will:
37+
38+
- Run the precompile hook **once** before starting development processes
39+
- Set `SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true` to prevent duplicate execution
40+
- Pass the environment variable to all spawned processes (Rails, webpack, etc.)
41+
42+
This eliminates the need for sleep hacks and manual coordination in `Procfile.dev`. See the [Process Managers documentation](./process-managers.md#precompile-hook-integration) for details.
43+
44+
**Alternative: Manual coordination**
45+
46+
For development, you can adjust your startup scripts (`Procfile`s) so that they run `bundle exec rake react_on_rails:locale` before running any Webpack watch process (`yarn run build:development`).
47+
48+
If you are not using the React on Rails test helper, you may need to configure your CI to run `bundle exec rake react_on_rails:locale` before any Webpack process as well.
2849

2950
> [!NOTE]
3051
> If you try to lint before running tests, and you depend on the test helper to build your locales, linting will fail because the translations won't be built yet.

0 commit comments

Comments
 (0)