2.2.2 • Published 12 months ago

@hurtigruten/nellie-microcopies v2.2.2

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

nellie.microcopy

NPM package for syncing microcopies from Contentful, and some other nice tools for managing microcopies in your project.

NB, todo

Need to write a script removing emtpy export {} at the bottom of the file (something tsc is adding by default, but unfortunately it fails my script, so right now Im removing it manually before publishing)

How to setup and sync

  1. Install the package

    npm i @hurtigruten/nellie-microcopies --save-dev
  2. Then create a .env file for your project and add the following variables

    CONTENTFUL_SPACE = "add_your_space"
    CONTENTFUL_ACCESS_TOKEN = "add_your_token"
  3. Then create a sync-microcopies.js on the root of your project

  4. In this file you add the following

    const microcopySync = require('@hurtigruten/nellie-microcopies');
    
    const config = {
      contentfulConfig: {
        space: process.env.CONTENTFUL_SPACE,
        accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
        environment: 'master',
        host: 'cdn.contentful.com'
      },
      baseDir: 'src'
    };
    
    microcopySync(config);
  1. Add this to your scripts in package.json: sync:microcopies": "node sync-microcopies.js

  2. Then run npm run sync:microcopies from the cmd and the sync should start

Desired result

You should now have a /microcopies folder in your /src folder

How to use in application

Add this to your_app_file.tsx

    import { useTranslate } from '@hurtigruten/nellie-microcopies';
    import { some_set } from '@microcopies/index';
    
    const MyApp = () => {
        const fancyLocale = 'en-us';
        const translate = useTranslate(activities, (x) => x.activities, fancyLocale);
        return (
          <p>
            Check out this awesome translation: {translate((x) => x.popular.description)}
          </p>
        )
    }
    

Dont want to pass a locale everytime?

Heres what you can do

  1. Make your own wrapper of the useTranslate function so that the locale is always provided

The useTranslate function defaults to defaultLocale if no locale is provided

2.2.2

12 months ago

2.1.0

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago