Commit b8e3ba0
Make locale generation idempotent with force flag support (#2090)
## Summary
The `react_on_rails:locale` rake task is now idempotent, automatically
skipping generation when locale files are already up-to-date. This
addresses issue #2090 by making it safe to call multiple times (e.g.,
in Shakapacker's `precompile_hook`) without duplicate work or race
conditions.
## Key Improvements
- **Idempotent behavior**: Task skips regeneration when locale files
are newer than source YAML files
- **Force flag**: Added `force=true` option to override timestamp
checking and force regeneration
- **Clear messaging**: Outputs helpful messages when skipping or
generating files
- **Safe coordination**: Can be called multiple times in precompile
hooks, development servers, and CI without issues
## Changes
### Core Implementation
- `lib/tasks/locale.rake`: Added `force=true` parameter support and
improved task description
- `lib/react_on_rails/locales/base.rb`: Modified `compile()` and
`Base#initialize()` to accept and handle `force` parameter, added
informative output messages
### Tests
- `spec/react_on_rails/locales_spec.rb`: Added tests for force
parameter propagation to ToJson and ToJs
- `spec/react_on_rails/locales_to_js_spec.rb`: Added test verifying
force flag bypasses timestamp checking
### Documentation
- `docs/building-features/i18n.md`: Added recommended pattern for using
Shakapacker's `precompile_hook` with idempotent locale generation
- `CHANGELOG.md`: Added entry documenting the improvement
## Usage
### Normal use (skips if up-to-date):
```bash
bundle exec rake react_on_rails:locale
```
### Force regeneration:
```bash
bundle exec rake react_on_rails:locale force=true
```
### Recommended shakapacker.yml configuration:
```yaml
default: &default
precompile_hook: "bundle exec rake react_on_rails:locale"
```
Fixes #2090
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent 2306825 commit b8e3ba0
File tree
6 files changed
+76
-9
lines changed- docs/building-features
- lib
- react_on_rails/locales
- tasks
- spec/react_on_rails
6 files changed
+76
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
28 | 47 | | |
29 | 48 | | |
30 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | | - | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
39 | 55 | | |
40 | 56 | | |
41 | 57 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
53 | 71 | | |
54 | 72 | | |
55 | 73 | | |
| |||
0 commit comments