Skip to content

Commit

Permalink
TASK: Move <I18n/>-component into separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
grebaldi authored and markusguenther committed Dec 13, 2024
1 parent cd21e93 commit 8647a23
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/neos-ui-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "",
"description": "I18n utilities and components for Neos CMS UI.",
"private": true,
"main": "./src/index.tsx",
"main": "./src/index.ts",
"devDependencies": {
"@neos-project/jest-preset-neos-ui": "workspace:*",
"enzyme": "^3.8.0",
Expand Down
41 changes: 41 additions & 0 deletions packages/neos-ui-i18n/src/component/I18n.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
import React from 'react';
import {mount} from 'enzyme';

import {i18nRegistry} from '../registry';

import {I18n} from './I18n';

describe('<I18n/>', () => {
beforeEach(() => {
jest.spyOn(i18nRegistry, 'translate');
(jest as any)
.mocked(i18nRegistry.translate)
.mockImplementation((key: string) => {
return key;
});
});
afterEach(() => {
jest.restoreAllMocks();
});

it(`should render a <span> node.`, () => {
const original = mount(<I18n />);

expect(original.html()).toBe('<span></span>');
});

it(`should call translation service with key.`, () => {
const original = mount(<I18n id="My key" />);

expect(original.html()).toBe('<span>My key</span>');
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
import React from 'react';
import {LegacyParameters, i18nRegistry} from './registry';

export {initializeI18n, setupI18n, teardownI18n} from './global';

export type {I18nRegistry} from './registry';

export {translate} from './translate';
import {LegacyParameters, i18nRegistry} from '../registry';

interface I18nProps {
// Fallback key which gets rendered once the i18n service doesn't return a translation.
Expand All @@ -25,7 +29,7 @@ interface I18nProps {
className?: string;
}

export default class I18n extends React.PureComponent<I18nProps> {
export class I18n extends React.PureComponent<I18nProps> {
public render(): JSX.Element {
const {packageKey, sourceName, params, id, fallback} = this.props;

Expand Down
10 changes: 10 additions & 0 deletions packages/neos-ui-i18n/src/component/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
export {I18n} from './I18n';
36 changes: 0 additions & 36 deletions packages/neos-ui-i18n/src/index.spec.tsx

This file was deleted.

16 changes: 16 additions & 0 deletions packages/neos-ui-i18n/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
export {I18n as default} from './component';

export {initializeI18n, setupI18n, teardownI18n} from './global';

export type {I18nRegistry} from './registry';

export {translate} from './translate';

0 comments on commit 8647a23

Please sign in to comment.