Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Trans component #18

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Implement Trans component #18

wants to merge 16 commits into from

Conversation

DRFR0ST
Copy link
Collaborator

@DRFR0ST DRFR0ST commented Apr 23, 2023

📜 Description

This PR adds a new feature to the project: the Trans component. The Trans component is a custom translation component that can interpolate variables and parse HTML elements.

The Trans component takes three props:

  • children - The translation string to be rendered.
  • values - An object containing values to be interpolated in the translation string.
  • components - An object containing custom React components or HTML tags to be parsed and rendered.

This PR also includes an updated version of package.json.

🧪 How to test this?

To test this PR, follow these steps:

  1. Clone the repository.
  2. Checkout the trans-component branch.
  3. Install dependencies with yarn install.
  4. Run tests with yarn test.
  5. Link littera package with yarn link while in the root directory.
  6. Set up an example React app with npx create-react-app ./PlaygroundApp --template=typescript
  7. Link littera with the example app and complete basic setup. Link with yarn link @assembless/react-littera while in the apps root directory.
  8. Run the app and navigate to http://localhost:3000 to see the Trans component in action.

🚀 Examples

Here are a few examples of how to use the Trans component:

import React from 'react';
import { Trans, useLittera } from '@assembless/react-littera';

const translations = {
  welcome: {
    en_US: "Welcome <strong>{name}</strong>!",
    de_DE: "Willkommen <strong>{name}</strong>!",
    pl_PL: "Witaj <strong>{name}</strong>!",
  },
};

function App() {
  const translated = useLittera(translations);

  return (
    <Trans values={{ name: "Jack" }}>
      {translated.welcome}
    </Trans>
  );
}
import React from 'react';
import { Trans, useLittera } from '@assembless/react-littera';

const translations = {
  about: {
    en_US: "This is the <a href='/about'>about</a> page.",
    de_DE: "Dies ist die <a href='/about'>Über uns</a>-Seite.",
    pl_PL: "To jest <a href='/about'>strona o nas</a>.",
  },
};

function AboutPage() {
  const translated = useLittera(translations);

  return (
    <Trans components={{ a: Link }}>
      {translated.about}
    </Trans>
  );
}

@DRFR0ST DRFR0ST added the enhancement New feature or request label Apr 23, 2023
@DRFR0ST DRFR0ST self-assigned this Apr 23, 2023
@codesandbox
Copy link

codesandbox bot commented Apr 23, 2023

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@abhagsain
Copy link

welldone

@DRFR0ST DRFR0ST marked this pull request as ready for review April 24, 2023 22:48
@DRFR0ST
Copy link
Collaborator Author

DRFR0ST commented Apr 24, 2023

We have pushed a nightly release that includes the Trans component.
https://www.npmjs.com/package/@assembless/react-littera/v/2.5.0-nightly.0

To update run: yarn upgrade @assembless/react-littera@nightly

@reviewpad reviewpad bot mentioned this pull request May 15, 2023
9 tasks
@Assembless Assembless deleted a comment from reviewpad bot May 15, 2023
@DRFR0ST
Copy link
Collaborator Author

DRFR0ST commented May 15, 2023

/reviewpad summarize

@reviewpad reviewpad bot requested a review from zivavu May 15, 2023 11:54
@reviewpad reviewpad bot added large Pull request is large waiting-for-review labels May 15, 2023
@reviewpad
Copy link
Contributor

reviewpad bot commented May 15, 2023

Reviewpad Report

‼️ Errors

  • Unconventional commit detected: ':sparkles: Implement the Trans component' (bf884d3)
  • Unconventional commit detected: ':arrow_up: Update packages

React from 16.X to 18.X
Webpack from 4.X to 5.X' (d2cf716)

  • Unconventional commit detected: ':white_check_mark: Add Trans component tests' (6d14d12)
  • Unconventional commit detected: ':fire: Remove failing and abandoned tests

Only for withLittera HOC that is suggested not to be used' (50dfbba)

  • Unconventional commit detected: ':arrow_up: Update Jest and cleanup tests' (8293200)
  • Unconventional commit detected: ':zap: Optimize Trans component' (a5adcae)
  • Unconventional commit detected: ':white_check_mark: Implement more tests' (9958124)
  • Unconventional commit detected: ':camera_flash: Update snapshots' (e7f52fd)
  • Unconventional commit detected: ':memo: Update README.md' (ea2a46b)
  • Unconventional commit detected: ':memo: Update CHANGELOG.md' (b61b494)
  • Unconventional commit detected: ':memo: Update LICENSE' (2d2dd9f)
  • Unconventional commit detected: ':arrow_up: Update dependencies' (6296233)
  • Unconventional commit detected: ':memo: Update jsdocs comments' (0a74d4c)
  • Unconventional commit detected: ':recycle: Sync yarn.lock' (5459ecd)
  • Unconventional commit detected: ':wrench: Update tsconfig.json' (7110ffa)
  • Unconventional commit detected: ':wrench: Fix critical issue crashing React
  • Clean up code and dependencies' (1fb736b)
  • Unconventional title detected: 'Implement Trans component' illegal 'I' character in commit message type: col=00

⚠️ Warnings

  • Please link an issue to the pull request

Fatal

  • License files cannot be modified

@Assembless Assembless deleted a comment from reviewpad bot May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request large Pull request is large waiting-for-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants