Assembless / react-littera

🌐 Modern react library for managing translations.
MIT License
19 stars 1 forks source link

Implement Trans component #18

Open DRFR0ST opened 1 year ago

DRFR0ST commented 1 year ago

πŸ“œ 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:

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>
  );
}
codesandbox[bot] commented 1 year ago

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

abhagsain commented 1 year ago

welldone

DRFR0ST commented 1 year ago

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

DRFR0ST commented 1 year ago

/reviewpad summarize

reviewpad[bot] commented 1 year ago

Reviewpad Report

:bangbang: Errors

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

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

:warning: Warnings

Fatal