Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 35 additions & 39 deletions docs/how_tos/migrate-frontend-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ packages/

### i18n ###
src/i18n/transifex_input.json
src/i18n/messages.ts
src/i18n/messages/

### Editors ###
.DS_Store
Expand Down Expand Up @@ -538,51 +540,45 @@ i18n

Description fields are now required on all i18n messages in the repository. This is because of a change to the ESLint config.

Also, replace the contents of `src/i18n/index.js` with:

```
// Placeholder be overridden by `make pull_translations`
export default {
ar: {},
'zh-hk': {},
'zh-cn': {},
uk: {},
'tr-tr': {},
th: {},
te: {},
ru: {},
'pt-pt': {},
'pt-br': {},
'it-it': {},
id: {},
hi: {},
he: {},
'fr-ca': {},
fa: {},
'es-es': {},
'es-419': {},
el: {},
'de-de': {},
da: {},
bo: {},
};
Translations are now pulled and prepared using the `openedx translations:pull` CLI command. Add an `atlasTranslations` field to your `package.json` so the command knows where to find your app's translations and which dependencies to resolve transitively:

```json
"atlasTranslations": {
"path": "translations/frontend-app-[YOUR_APP]/src/i18n/messages",
"dependencies": ["@openedx/frontend-base"]
}
```

Finally, edit the `Makefile` so that no strings are being pulled from `frontend-component-(header|footer)`, and rename `frontend-platform` to `frontend-base`. Such as:
Also add a `translations:pull` script to your `package.json`:

```Makefile
# Pulls translations using atlas.
pull_translations:
mkdir src/i18n/messages
cd src/i18n/messages \
&& atlas pull $(ATLAS_OPTIONS) \
translations/frontend-base/src/i18n/messages:frontend-base \
translations/paragon/src/i18n/messages:paragon \
translations/frontend-app-[YOUR_APP]/src/i18n/messages:frontend-app-[YOUR_APP]
```json
"scripts": {
"translations:pull": "openedx translations:pull"
}
```

And update your `pull_translations` Makefile target to use it:

$(intl_imports) frontend-base paragon frontend-app-[YOUR_APP]
```Makefile
pull_translations: | requirements
npm run translations:pull
```

Running `npm run translations:pull` will pull translations from `openedx-translations` and generate `src/i18n/messages.ts`.

Add a `src/i18n/index.ts` file that re-exports the generated messages:

```ts
export { default } from './messages';
```

Also add a `src/i18n/messages.d.ts` type declaration file so TypeScript knows the shape of the generated module even before `translations:pull` has been run:

```ts
import type { SiteMessages } from '@openedx/frontend-base';

declare const messages: SiteMessages;
export default messages;
```

SVGR "ReactComponent" imports have been removed
Expand Down
4 changes: 4 additions & 0 deletions frontend-base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ declare module 'site.config' {
export default SiteConfig;
}

declare module 'site.i18n' {
export default SiteMessages;
}

declare module '*.svg' {
const content: string;
export default content;
Expand Down
32 changes: 15 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@
"/dist"
],
"bin": {
"intl-imports.js": "./dist/tools/cli/intl-imports.js",
"openedx": "./dist/tools/cli/openedx.js",
"transifex-utils.js": "./dist/tools/cli/transifex-utils.js"
"openedx": "./dist/tools/cli/openedx.js"
},
"atlasTranslations": {
"path": "translations/frontend-base/src/i18n/messages",
"dependencies": [
"@openedx/paragon"
]
},
"scripts": {
"build": "make build",
"clean": "make clean",
"dev": "npm run build && node ./dist/tools/cli/openedx.js dev:shell",
"docs": "jsdoc -c jsdoc.json",
"lint": "eslint .; npm run lint:tools; npm --prefix ./test-site run lint",
"lint:fix": "eslint . --fix; npm run lint:fix:tools",
"lint:tools": "cd ./tools && eslint . && cd ..",
"lint:fix:tools": "cd ./tools && eslint . --fix && cd ..",
Comment on lines +33 to +35
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like having lint:fix around as a script (especially when lint is multi-part so appending -- --fix doesn't "just work"), but I can remove it if we don't want it.

"pack": "mkdir -p pack && npm pack --silent --pack-destination pack >/dev/null && mv \"$(ls -t pack/*.tgz | head -n 1)\" pack/openedx-frontend-base.tgz",
"prepack": "npm run build",
"test": "jest",
Expand Down Expand Up @@ -143,12 +149,12 @@
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.6.1",
"@tsconfig/node20": "^20.1.5",
"@tsconfig/node24": "^24.0.4",
"@types/compression": "^1.7.5",
"@types/jest": "^29.5.14",
"@types/lodash.camelcase": "^4.3.9",
"@types/lodash.merge": "^4.6.9",
"@types/node": "^18.19.43",
"@types/node": "^24.12.0",
"@types/react": "^18.3.20",
"@types/react-dom": "^18.3.6",
"axios-mock-adapter": "^1.22.0",
Expand All @@ -157,7 +163,7 @@
"nodemon": "^3.1.4"
},
"peerDependencies": {
"@openedx/paragon": "^23.4.5",
"@openedx/paragon": "^23.20.0",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first version with an atlasTranslations block in its package.json.

"@tanstack/react-query": "^5.81.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
1 change: 0 additions & 1 deletion runtime/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export {
} from 'react-intl';

export {
addAppMessages,
configureI18n,
getLocale,
getLocalizedLanguageName,
Expand Down
14 changes: 0 additions & 14 deletions runtime/i18n/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,6 @@ export function mergeMessages(newMessages = {}) {
return messages;
}

/**
* Adds all the messages found in the loaded apps.
*
* @memberof module:Internationalization
*/
export function addAppMessages() {
const { apps } = getSiteConfig();
if (apps) {
apps.forEach((app) => {
mergeMessages(app.messages);
});
}
}

interface ConfigureI18nOptions {
messages: LocalizedMessages[] | LocalizedMessages,
}
Expand Down
2 changes: 0 additions & 2 deletions shell/dev/devHome/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { App } from '../../../types';
import HomePage from './HomePage';
import messages from './i18n';

const app: App = {
appId: 'org.openedx.frontend.app.dev.home',
Expand All @@ -12,7 +11,6 @@ const app: App = {
role: 'org.openedx.frontend.role.devHome'
}
}],
messages,
};

export default app;
27 changes: 0 additions & 27 deletions shell/dev/devHome/i18n/index.ts

This file was deleted.

25 changes: 0 additions & 25 deletions shell/i18n/index.ts

This file was deleted.

4 changes: 1 addition & 3 deletions shell/site.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import {
subscribe
} from '../runtime';
import { addAppConfigs } from '../runtime/config';
import { addAppMessages } from '../runtime/i18n';
import messages from './i18n';
import messages from 'site.i18n';
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see ‎tools/webpack/utils/getResolvedSiteI18nPath.ts

import createRouter from './router/createRouter';

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

addAppConfigs();
addAppMessages();

const root = createRoot(document.getElementById('root') as HTMLElement);
root.render(
Expand Down
27 changes: 0 additions & 27 deletions test-site/src/authenticated-page/i18n/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions test-site/src/authenticated-page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { App, LinkMenuItem, WidgetOperationTypes } from '@openedx/frontend-base';
import messages from './i18n';

const config: App = {
appId: 'test-authenticated-page-app',
Expand All @@ -22,7 +21,6 @@ const config: App = {
)
}
],
messages,
};

export default config;
3 changes: 0 additions & 3 deletions test-site/src/i18n/README.md

This file was deleted.

1 change: 1 addition & 0 deletions test-site/src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default [];
Loading
Loading