Skip to content

Commit d11d00a

Browse files
arbrandesclaude
andcommitted
feat: add translations:pull support
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 25c1746 commit d11d00a

6 files changed

Lines changed: 59 additions & 3 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ packages/
99

1010
### i18n ###
1111
src/i18n/transifex_input.json
12+
src/i18n/messages.ts
13+
src/i18n/messages/
14+
src/i18n/site-messages/index.ts
1215

1316
### Editors ###
1417
.DS_Store

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ dev-packages:
1919
dev-site: bin-link
2020
npm run dev
2121

22+
pull_translations:
23+
npm run translations:pull
24+
2225
clean:
2326
rm -rf dist

README.rst

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,52 @@ Workspace Scripts
126126
Internationalization
127127
====================
128128

129-
Please see refer to the `frontend-base i18n howto`_ for documentation on
130-
internationalization.
129+
For general information on how internationalization works in Open edX frontends,
130+
refer to the `frontend-base i18n howto`_.
131131

132132
.. _frontend-base i18n howto: https://github.com/openedx/frontend-base/blob/master/docs/how_tos/i18n.rst
133133

134+
Pulling Translations
135+
--------------------
136+
137+
Translated strings for each package listed under ``atlasTranslations`` in
138+
``package.json`` are hosted in the `openedx-translations`_ repository. To fetch
139+
them before building the site, run::
140+
141+
npm run translations:pull
142+
143+
This downloads the message files into ``src/i18n/messages/`` (one subdirectory
144+
per package) and then generates ``src/i18n/messages.ts``, which aggregates
145+
everything for the runtime. Both the downloaded files and the generated module
146+
are gitignored, so translations must be pulled as part of any build or deploy
147+
pipeline.
148+
149+
If translations have not been pulled, the build still succeeds thanks to a
150+
placeholder ``src/i18n/messages.ts`` that exports an empty array. The site will
151+
simply fall back to the default English strings baked into each component.
152+
153+
.. _openedx-translations: https://github.com/openedx/openedx-translations
154+
155+
Site-level Translation Overrides
156+
--------------------------------
157+
158+
To override or supplement translations provided by packages, add JSON files to
159+
``src/i18n/site-messages/``. Each file is named after a locale
160+
(e.g., ``es_419.json``, ``fr.json``) and contains key-value pairs where the key
161+
is a message ID and the value is the replacement string::
162+
163+
src/i18n/site-messages/
164+
es_419.json
165+
fr.json
166+
167+
When ``translations:pull`` runs, it regenerates ``src/i18n/messages.ts`` with
168+
site-messages included *last* in the array. At runtime, all message sources are
169+
merged in order, so site-messages entries take precedence over the corresponding
170+
package translations.
171+
172+
The ``translations:pull`` command never deletes ``src/i18n/site-messages/`` -
173+
only ``src/i18n/messages/`` is cleared and re-fetched each time.
174+
134175
License
135176
*******
136177

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@
2424
"dev:site": "make dev-site",
2525
"dev:packages": "make dev-packages",
2626
"clean": "make clean",
27-
"serve": "openedx serve"
27+
"serve": "openedx serve",
28+
"translations:pull": "openedx translations:pull"
2829
},
2930
"author": "Open edX",
3031
"license": "AGPL-3.0",
3132
"homepage": "https://github.com/openedx/frontend-template-site#readme",
3233
"bugs": {
3334
"url": "https://github.com/openedx/frontend-template-site/issues"
3435
},
36+
"atlasTranslations": {
37+
"dependencies": [
38+
"@openedx/frontend-app-authn",
39+
"@openedx/frontend-app-learner-dashboard"
40+
]
41+
},
3542
"dependencies": {
3643
"@edx/brand": "npm:@openedx/brand-openedx@^1.2.3",
3744
"@openedx/frontend-app-authn": "^1.0.0-alpha || 0.0.0-dev",

src/i18n/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './messages';

src/i18n/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default [];

0 commit comments

Comments
 (0)