You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ADR/ADR043-use-mobility-with-column-strategy.md
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Date: 2025-06-09
4
4
5
5
## Status
6
6
7
-
Accepted
7
+
Superseded by [ADR046: Use Mobility's table backend strategy to store translations](ADR046-use-mobility-table-backend-strategy.md).
8
8
9
9
## Context
10
10
@@ -28,58 +28,74 @@ The main strategies for storing translations are:
28
28
- essentially a variant of the serialized data strategy that takes advantage of PostgreSQL's jsonb column type to make data easier to query.
29
29
30
30
#### Translatable columns
31
+
31
32
Advantages:
33
+
32
34
- Simple to understand and work with
33
35
- Easy to query
34
36
35
37
Disadvantages:
38
+
36
39
- Since new columns need to be added to every table for every language, the maintenance burden increases as the number of locales increases
37
40
- Since every new model would require new columns, maintenance burden increases as number of models increases
38
41
- Inefficient use of database space
39
42
40
43
We currently have a small number of models and locales which mitigates the main disadvantages, so this seems like a good option for us.
41
44
42
45
#### Model translation tables
46
+
43
47
Advantages:
48
+
44
49
- Scales well with locales (since all locales can use the same table)
45
50
- Uses space more efficiently than translatable columns
46
51
47
52
Disadvantages:
53
+
48
54
- Adds one extra table per model, so maintenance burden increases as the number of models increases
49
55
- Requires table joins, creating increased complexity and risk of performance issues
50
56
51
57
This could be a good option for us, since we have a small number of models.
52
58
53
59
#### Shared translation tables
60
+
54
61
Advantages
62
+
55
63
- Versatile, no additional migrations required when adding new locales or models
56
64
57
65
Disadvantages
66
+
58
67
- Requires more complex table joins, creating increased complexity and risk of performance issues
59
68
- since tables don't map 1:1 with model tables, it's harder to keep the shared table up to date with attribute renames and dropped columns
60
69
61
70
This could work for for us, but might be needlessly complex for the number of models and locales we're currently expecting to have.
62
71
63
72
#### Serialized data
73
+
64
74
Advantages:
75
+
65
76
- Simple to understand and work with
66
77
67
78
Disavantages:
79
+
68
80
- Difficult to add constraints
69
81
- Difficult to query
70
82
71
-
We recommend against this option - the PostgreSQl jsonb strategy is functionally similar with fewer disadvantages.
83
+
We recommend against this option - the PostgreSQl jsonb strategy is functionally similar with fewer disadvantages.
72
84
73
85
#### PostgreSQL jsonb
86
+
74
87
Advantages:
88
+
75
89
- Simple to understand and work with
76
90
77
91
Disavantages:
92
+
78
93
- Difficult to add constraints
79
94
80
95
We think the inability to easily add database constraints makes this a poor option for our use case.
81
96
82
97
### Gems
98
+
83
99
There are a few popular Ruby gems for dealing with translations. We looked into:
84
100
85
101
-[Mobility](https://github.com/shioyama/mobility)
@@ -92,6 +108,7 @@ Of these, only Mobility and Globalize have received recent updates. Mobility is
92
108
Mobility also supports all of the backend strategies we've looked at, with largely the same API for each, which means it would be helpful if we decided we wanted to change strategy later.
93
109
94
110
We also considered the possibility of implementing our own solution without using a gem. In this case we’d:
111
+
95
112
- Have one less dependency
96
113
- Have more control over our implementation
97
114
- Have to manage database changes manually
@@ -101,6 +118,7 @@ We also considered the possibility of implementing our own solution without usin
101
118
## Decision
102
119
103
120
We have decided to:
121
+
104
122
- implement translatable columns for each translatable text field
105
123
- use the Mobility gem, configured with the `:column` backend strategy, to manage this
# ADR046: Use Mobility's table backend strategy to store translations
2
+
3
+
Date: 2025-09-08
4
+
5
+
## Status
6
+
7
+
Accepted
8
+
9
+
## Context
10
+
11
+
We previously decided in [ADR043: Use Mobility gem with :column strategy to manage translated fields](ADR043-use-mobility-with-column-strategy.md) that we would use Mobility's column strategy to handle storing translations.
12
+
13
+
Our initial proposal was to use the column strategy (the simplest strategy Mobility supports) while we had a small number of languages (English and Welsh), and reassess later whether to use a more elaborate strategy if we add more languages. We concluded that Mobility's table strategy (described as 'Model translation tables' in the earlier ADR) scales better with an increased number of languages, so this is likely to be a better option than the column strategy if we need to support more than a few languages.
14
+
15
+
In conversations with departments we have found that there is demand for supporting additional languages, so we think we are likely to need the more scalable backend strategy.
16
+
17
+
Rather than implement the column strategy initially and migrate to the table strategy later, it would be less work to implement the table strategy directly.
18
+
19
+
## Decision
20
+
21
+
We have decided to:
22
+
23
+
- implement translation tables for each model
24
+
- use the Mobility gem, configured with the `:table` backend strategy, to manage this
25
+
26
+
## Consequences
27
+
28
+
- adding additional languages in future should be easier
29
+
- when adding new models, we will need to add a translation table for each new model
0 commit comments