Skip to content

Commit 999448f

Browse files
feat: wire translations into runtime via site.i18n webpack alias
- Add `site.i18n` webpack alias (dev, build, dev-shell configs) using a new `getResolvedSiteI18nPath` utility mirroring `getResolvedSiteConfigPath` - Declare `site.i18n` module in `frontend-base.d.ts` using new `SiteMessages` type (`LocalizedMessages[]`) added to `types.ts` - Remove `App.messages`, `addAppMessages()`, and `shell/i18n/` placeholder — all translations now flow through `initialize({ messages })` from the site-level pull - Add `test-site/src/i18n/index.ts` (empty array) for the dev shell Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3d8ddf8 commit 999448f

13 files changed

Lines changed: 39 additions & 48 deletions

File tree

frontend-base.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ declare module 'site.config' {
22
export default SiteConfig;
33
}
44

5+
declare module 'site.i18n' {
6+
export default SiteMessages;
7+
}
8+
59
declare module '*.svg' {
610
const content: string;
711
export default content;

runtime/i18n/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export {
9797
} from 'react-intl';
9898

9999
export {
100-
addAppMessages,
101100
configureI18n,
102101
getLocale,
103102
getLocalizedLanguageName,

runtime/i18n/lib.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,6 @@ export function mergeMessages(newMessages = {}) {
237237
return messages;
238238
}
239239

240-
/**
241-
* Adds all the messages found in the loaded apps.
242-
*
243-
* @memberof module:Internationalization
244-
*/
245-
export function addAppMessages() {
246-
const { apps } = getSiteConfig();
247-
if (apps) {
248-
apps.forEach((app) => {
249-
mergeMessages(app.messages);
250-
});
251-
}
252-
}
253-
254240
interface ConfigureI18nOptions {
255241
messages: LocalizedMessages[] | LocalizedMessages,
256242
}

shell/dev/devHome/app.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { App } from '../../../types';
22
import HomePage from './HomePage';
3-
import messages from './i18n';
43

54
const app: App = {
65
appId: 'org.openedx.frontend.app.dev.home',
@@ -12,7 +11,6 @@ const app: App = {
1211
role: 'org.openedx.frontend.role.devHome'
1312
}
1413
}],
15-
messages,
1614
};
1715

1816
export default app;

shell/i18n/index.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

shell/site.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ import {
1010
subscribe
1111
} from '../runtime';
1212
import { addAppConfigs } from '../runtime/config';
13-
import { addAppMessages } from '../runtime/i18n';
14-
import messages from './i18n';
13+
import messages from 'site.i18n';
1514
import createRouter from './router/createRouter';
1615

1716
subscribe(SITE_READY, async () => {
1817
const queryClient = new QueryClient();
1918
const router = createRouter();
2019

2120
addAppConfigs();
22-
addAppMessages();
2321

2422
const root = createRoot(document.getElementById('root') as HTMLElement);
2523
root.render(

test-site/src/authenticated-page/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { App, LinkMenuItem, WidgetOperationTypes } from '@openedx/frontend-base';
2-
import messages from './i18n';
32

43
const config: App = {
54
appId: 'test-authenticated-page-app',
@@ -22,7 +21,6 @@ const config: App = {
2221
)
2322
}
2423
],
25-
messages,
2624
};
2725

2826
export default config;

test-site/src/i18n/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default [];
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
export default function getResolvedSiteI18nPath(defaultDirname: string) {
5+
const siteI18nPath = process.env.SITE_I18N_PATH;
6+
7+
if (siteI18nPath !== undefined) {
8+
const absolutePath = path.resolve(process.cwd(), siteI18nPath);
9+
if (fs.existsSync(absolutePath)) {
10+
return absolutePath;
11+
}
12+
console.error(`Invalid site i18n path (${siteI18nPath}) specified as an environment variable. Aborting.`);
13+
process.exit(1);
14+
}
15+
16+
const defaultPath = path.resolve(process.cwd(), defaultDirname);
17+
if (fs.existsSync(defaultPath)) {
18+
return defaultPath;
19+
}
20+
21+
console.error(`Default site i18n directory (${defaultPath}) does not exist. Aborting.`);
22+
process.exit(1);
23+
}

tools/webpack/webpack.config.build.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import {
1616

1717
import getPublicPath from './utils/getPublicPath';
1818
import getResolvedSiteConfigPath from './utils/getResolvedSiteConfigPath';
19+
import getResolvedSiteI18nPath from './utils/getResolvedSiteI18nPath';
1920

2021
const resolvedSiteConfigPath = getResolvedSiteConfigPath('site.config.build.tsx');
22+
const resolvedSiteI18nPath = getResolvedSiteI18nPath('src/i18n');
2123

2224
const config: Configuration = {
2325
mode: 'production',
@@ -34,6 +36,7 @@ const config: Configuration = {
3436
resolve: {
3537
alias: {
3638
'site.config': resolvedSiteConfigPath,
39+
'site.i18n': resolvedSiteI18nPath,
3740
},
3841
plugins: [
3942
new TsconfigPathsPlugin({

0 commit comments

Comments
 (0)