Skip to content

Commit b266643

Browse files
araujoguiovflowd
andauthored
Set up i18n package (#6991)
* build: change package scopes * build: create packages workspace * feat: create initial i18n package * feat: create import locale fn * chore: some peaks * refactor: remove duplicated type * chore: set up lint * chore: dep fix * fix: crowdin config * fix: fix modules, eslint * fix: fixed lint, test and build process * chore: code review changes * chore: fix turbo.json * chore: fix package versions * fix: fix build due to shiki * chore: (unrelated) shiki js engine --------- Co-authored-by: Claudio Wunder <[email protected]>
1 parent a2cb6d8 commit b266643

35 files changed

+2732
-3962
lines changed

.github/workflows/translations-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ on:
1212
- 'apps/site/pages/**/*.mdx'
1313
- '!apps/site/pages/en/**/*.md'
1414
- '!apps/site/pages/en/**/*.mdx'
15-
- 'apps/site/i18n/locales/*.json'
16-
- '!apps/site/i18n/locales/en.json'
15+
- 'packages/i18n/locales/*.json'
16+
- '!packages/i18n/locales/en.json'
1717

1818
permissions:
1919
actions: read

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ tsconfig.tsbuildinfo
3333

3434
# Sentry Config File
3535
.sentryclirc
36+
37+
dist/

.husky/pre-commit

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
41
# lint and format staged files
52
npx lint-staged
63

apps/site/.storybook/preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import englishLocale from '@node-core/website-i18n/locales/en.json';
12
import { withThemeByDataAttribute } from '@storybook/addon-themes';
23
import type { Preview, ReactRenderer } from '@storybook/react';
34
import { NextIntlClientProvider } from 'next-intl';
45

56
import { STORYBOOK_MODES, STORYBOOK_SIZES } from '@/.storybook/constants';
6-
import englishLocale from '@/i18n/locales/en.json';
77
import { NotificationProvider } from '@/providers/notificationProvider';
88

99
import '../next.fonts';

apps/site/components/Common/LanguageDropDown/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { LanguageIcon } from '@heroicons/react/24/outline';
2+
import type { LocaleConfig } from '@node-core/website-i18n/types';
23
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
34
import classNames from 'classnames';
45
import { useTranslations } from 'next-intl';
56
import type { FC } from 'react';
67

7-
import type { LocaleConfig } from '@/types';
8-
98
import styles from './index.module.css';
109

1110
type SimpleLocaleConfig = Pick<LocaleConfig, 'name' | 'code'>;

apps/site/components/Downloads/Release/ReleaseCodeBox.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import type { FC } from 'react';
66

77
import CodeBox from '@/components/Common/CodeBox';
88
import { ReleaseContext } from '@/providers/releaseProvider';
9-
import { getShiki, highlightToHtml } from '@/util/getHighlighter';
9+
import { shikiPromise, highlightToHtml } from '@/util/getHighlighter';
1010
import { getNodeDownloadSnippet } from '@/util/getNodeDownloadSnippet';
1111

12-
// We cannot do top-level awaits on utilities or code that is imported by client-only components
13-
// hence we only declare a Promise and let it be fulfilled by the first call to the function
14-
const memoizedShiki = getShiki();
12+
const memoizedShiki = shikiPromise.then(highlightToHtml);
1513

1614
const ReleaseCodeBox: FC = () => {
1715
const { platform, os, release } = useContext(ReleaseContext);
@@ -25,9 +23,7 @@ const ReleaseCodeBox: FC = () => {
2523
// but usually we should recommend users to download "major" versions
2624
// since our Download Buttons get the latest minor of a major, it does make sense
2725
// to request installation of a major via a package manager
28-
memoizedShiki
29-
.then(shiki => highlightToHtml(shiki)(updatedCode, 'bash'))
30-
.then(setCode);
26+
memoizedShiki.then(shiki => shiki(updatedCode, 'bash')).then(setCode);
3127
// Only react when the specific release number changed
3228
// eslint-disable-next-line react-hooks/exhaustive-deps
3329
}, [release.versionWithPrefix, os, platform]);

apps/site/eslint.config.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { fixupPluginRules } from '@eslint/compat';
21
import { FlatCompat } from '@eslint/eslintrc';
32
import js from '@eslint/js';
43
import importX from 'eslint-plugin-import-x';
@@ -9,27 +8,16 @@ import storybook from 'eslint-plugin-storybook';
98
import tseslint from 'typescript-eslint';
109

1110
const compat = new FlatCompat();
12-
const pluginToPatch = '@next/next';
1311

14-
const compatConfig = compat
15-
.config({
16-
extends: [
17-
// https://github.com/vercel/next.js/discussions/49337
18-
'plugin:@next/eslint-plugin-next/core-web-vitals',
19-
20-
// https://github.com/facebook/react/issues/28313
21-
'plugin:react-hooks/recommended',
22-
],
23-
})
24-
.map(entry => {
25-
if (Object.hasOwn(entry.plugins, pluginToPatch)) {
26-
entry.plugins[pluginToPatch] = fixupPluginRules(
27-
entry.plugins[pluginToPatch]
28-
);
29-
}
12+
const compatConfig = compat.config({
13+
extends: [
14+
// https://github.com/vercel/next.js/discussions/49337
15+
'plugin:@next/eslint-plugin-next/core-web-vitals',
3016

31-
return entry;
32-
});
17+
// https://github.com/facebook/react/issues/28313
18+
'plugin:react-hooks/recommended',
19+
],
20+
});
3321

3422
export default tseslint.config(
3523
{
@@ -58,6 +46,7 @@ export default tseslint.config(
5846
'no-relative-import-paths': noRelativeImportPaths,
5947
},
6048
rules: {
49+
'@next/next/no-duplicate-head': 'off',
6150
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
6251
'@typescript-eslint/consistent-type-imports': 'error',
6352
'@typescript-eslint/no-require-imports': 'off',

apps/site/i18n.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { importLocale } from '@node-core/website-i18n';
12
import { getRequestConfig } from 'next-intl/server';
23

34
import { availableLocaleCodes } from '@/next.locales.mjs';
@@ -7,13 +8,15 @@ const loadLocaleDictionary = async (locale: string) => {
78
if (locale === 'en') {
89
// This enables HMR on the English Locale, so that instant refresh
910
// happens while we add/change texts on the source locale
10-
return import('./i18n/locales/en.json').then(f => f.default);
11+
return import('@node-core/website-i18n/locales/en.json').then(
12+
f => f.default
13+
);
1114
}
1215

1316
if (availableLocaleCodes.includes(locale)) {
1417
// Other languages don't really require HMR as they will never be development languages
1518
// so we can load them dynamically
16-
return import(`./i18n/locales/${locale}.json`).then(f => f.default);
19+
return importLocale(locale);
1720
}
1821

1922
throw new Error(`Unsupported locale: ${locale}`);

apps/site/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
/// <reference types="next/navigation-types/compat/navigation" />
44

55
// NOTE: This file should not be edited
6-
// see https://nextjs.org/docs/basic-features/typescript for more information.
6+
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.

apps/site/next.locales.mjs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
'use strict';
22

3-
import localeConfig from './i18n/config.json' assert { type: 'json' };
3+
import {
4+
getAvailableLocales,
5+
getAvailableLocaleCodes,
6+
getDefaultLocale,
7+
getAvailableLocalesMap,
8+
getAllLocaleCodes,
9+
} from '@node-core/website-i18n';
410

511
// As set of available and enabled locales for the website
612
// This is used for allowing us to redirect the user to any
713
// of the available locales that we have enabled on the website
8-
const availableLocales = localeConfig.filter(locale => locale.enabled);
14+
const availableLocales = getAvailableLocales();
915

1016
// This gives an easy way of accessing all available locale codes
11-
const availableLocaleCodes = availableLocales.map(locale => locale.code);
17+
const availableLocaleCodes = getAvailableLocaleCodes();
1218

1319
// This provides the default locale information for the Next.js Application
1420
// This is marked by the unique `locale.default` property on the `en` locale
15-
/** @type {import('./types').LocaleConfig} */
16-
const defaultLocale = availableLocales.find(locale => locale.default);
21+
/** @type {import('@node-core/website-i18n/types').LocaleConfig} */
22+
const defaultLocale = getDefaultLocale();
1723

1824
// Creates a Map of available locales for easy access
19-
const availableLocalesMap = Object.fromEntries(
20-
localeConfig.map(locale => [locale.code, locale])
21-
);
25+
const availableLocalesMap = getAvailableLocalesMap();
2226

2327
// Creates all supported locales
24-
const allLocaleCodes = localeConfig.map(locale => locale.code);
28+
const allLocaleCodes = getAllLocaleCodes();
2529

2630
export {
2731
allLocaleCodes,

0 commit comments

Comments
 (0)