Skip to content

Commit 38f3acb

Browse files
authored
feat: simplify next-js integration (#3391)
1 parent fc6cc84 commit 38f3acb

File tree

85 files changed

+1562
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1562
-409
lines changed

.github/workflows/publish-examples-check.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ jobs:
1515
[
1616
'react',
1717
'next',
18-
'next-app',
1918
'vue',
19+
'next-app',
20+
'next-app-intl',
2021
'svelte',
2122
'ngx',
2223
'react-i18next',

.github/workflows/publish-examples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
'next',
1919
'vue',
2020
'next-app',
21+
'next-app-intl',
2122
'svelte',
2223
'ngx',
2324
'react-i18next',
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { exampleAppTest } from '../../common/exampleAppTest';
2+
import { translationMethodsTest } from '../../common/translationMethodsTest';
3+
import { exampleAppDevTest } from '../../common/exampleAppDevTest';
4+
5+
context(
6+
'Next with app router (with next-intl) in dev mode',
7+
{ retries: 5 },
8+
() => {
9+
const url = 'http://localhost:8125';
10+
const translationMethods = url + '/en/translation-methods';
11+
exampleAppTest(url);
12+
translationMethodsTest(translationMethods, {
13+
en: [
14+
{ text: 'This is a key', count: 2 },
15+
{ text: 'This is key with params value value2', count: 6 },
16+
{
17+
text: 'This is a key with tags bold value',
18+
count: 2,
19+
testId: 'translationWithTags',
20+
},
21+
{ text: 'Translation in translation', count: 2 },
22+
],
23+
de: [
24+
{ text: 'Dies ist ein Schlüssel', count: 2 },
25+
{
26+
text: 'Dies ist ein Schlüssel mit den Parametern value value2',
27+
count: 6,
28+
},
29+
{
30+
text: 'Dies ist ein Schlüssel mit den Tags bold value',
31+
count: 2,
32+
testId: 'translationWithTags',
33+
},
34+
{ text: 'Translation in translation', count: 2 },
35+
],
36+
});
37+
38+
exampleAppDevTest(url, { noLoading: true });
39+
}
40+
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { exampleAppTest } from '../../common/exampleAppTest';
2+
import { translationMethodsTest } from '../../common/translationMethodsTest';
3+
4+
context('Next with app router (with next-intl) in prod mode', () => {
5+
const url = 'http://localhost:8127';
6+
const translationMethods = url + '/en/translation-methods';
7+
exampleAppTest(url);
8+
translationMethodsTest(translationMethods, {
9+
en: [
10+
{ text: 'This is a key', count: 2 },
11+
{ text: 'This is key with params value value2', count: 6 },
12+
{
13+
text: 'This is a key with tags bold value',
14+
count: 2,
15+
testId: 'translationWithTags',
16+
},
17+
{ text: 'Translation in translation', count: 2 },
18+
],
19+
de: [
20+
{ text: 'Dies ist ein Schlüssel', count: 2 },
21+
{
22+
text: 'Dies ist ein Schlüssel mit den Parametern value value2',
23+
count: 6,
24+
},
25+
{
26+
text: 'Dies ist ein Schlüssel mit den Tags bold value',
27+
count: 2,
28+
testId: 'translationWithTags',
29+
},
30+
{ text: 'Translation in translation', count: 2 },
31+
],
32+
});
33+
});

e2e/cypress/e2e/next-app/dev.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { exampleAppDevTest } from '../../common/exampleAppDevTest';
44

55
context('Next with app router in dev mode', { retries: 5 }, () => {
66
const url = 'http://localhost:8122';
7-
const translationMethods = url + '/en/translation-methods';
7+
const translationMethods = url + '/translation-methods';
88
exampleAppTest(url);
99
translationMethodsTest(translationMethods, {
1010
en: [

e2e/cypress/e2e/next-app/prod.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { translationMethodsTest } from '../../common/translationMethodsTest';
33

44
context('Next with app router in prod mode', () => {
55
const url = 'http://localhost:8121';
6-
const translationMethods = url + '/en/translation-methods';
6+
const translationMethods = url + '/translation-methods';
77
exampleAppTest(url);
88
translationMethodsTest(translationMethods, {
99
en: [

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"develop:react-i18next": "npm run develop -- --scope=@tolgee/react-i18next-testapp",
2626
"develop:vue-i18next": "npm run develop -- --scope=@tolgee/vue-i18next-testapp",
2727
"develop:next-app": "npm run develop -- --scope=@tolgee/next-app-testapp",
28+
"develop:next-app-intl": "npm run develop -- --scope=@tolgee/next-app-intl-testapp",
2829
"develop:vue-ssr": "npm run develop -- --scope=@tolgee/vue-ssr-testapp",
2930
"build:e2e": "turbo run build:e2e --cache-dir='.turbo'",
3031
"test:e2e": "pnpm run build:e2e && pnpm --prefix e2e run start",

packages/core/src/Controller/State/initState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export type TolgeeOptionsInternal = {
8181
*
8282
* ```ts
8383
* {
84-
* 'locale': <translations | async function>
85-
* 'locale:namespace': <translations | async function>
84+
* 'language': <translations | async function>
85+
* 'language:namespace': <translations | async function>
8686
* }
8787
* ```
8888
*/

packages/format-icu/src/createFormatIcu.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ describe('format icu', () => {
1212
expect(result).toEqual('result is 42,000');
1313
});
1414

15-
it('fixes invalid locale', () => {
15+
it('fixes invalid language', () => {
1616
const formatter = createFormatIcu() as any;
17-
expect(formatter.getLocale('en_GB')).toEqual('en-GB');
18-
expect(formatter.getLocale('en_GB-nonsenceeeee')).toEqual('en-GB');
19-
expect(formatter.getLocale('cs CZ')).toEqual('cs-CZ');
17+
expect(formatter.getLanguage('en_GB')).toEqual('en-GB');
18+
expect(formatter.getLanguage('en_GB-nonsenceeeee')).toEqual('en-GB');
19+
expect(formatter.getLanguage('cs CZ')).toEqual('cs-CZ');
2020
});
2121
});

packages/format-icu/src/createFormatIcu.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const createFormatIcu = (): FinalFormatterMiddleware => {
1212
}
1313
}
1414

15-
function getLocale(language: string) {
15+
function getLanguage(language: string) {
1616
if (!locales.get(language)) {
1717
let localeCandidate: string = String(language).replace(/[^a-zA-Z]/g, '-');
1818
while (!isLocaleValid(localeCandidate)) {
@@ -33,12 +33,12 @@ export const createFormatIcu = (): FinalFormatterMiddleware => {
3333
(p) => typeof p === 'function'
3434
);
3535

36-
const locale = getLocale(language);
36+
const locale = getLanguage(language);
3737

3838
return new IntlMessageFormat(translation, locale, undefined, {
3939
ignoreTag,
4040
}).format(params);
4141
};
4242

43-
return Object.freeze({ getLocale, format });
43+
return Object.freeze({ getLanguage, format });
4444
};

0 commit comments

Comments
 (0)