Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

piral-translate

Package Overview
Dependencies
Maintainers
1
Versions
947
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piral-translate

Plugin for providing translated messages in Piral.


Version published
Weekly downloads
2.2K
increased by15.69%
Maintainers
1
Weekly downloads
 
Created
Source

Piral Logo

Piral Translate · GitHub License npm version tested with jest Gitter Chat

This is a plugin that only has a peer dependency to piral-core. What piral-translate brings to the table is a set of Pilet API extensions that is used by piral. The set features a simple yet sufficient translation system.

Documentation

The following functions are brought to the Pilet API.

translate()

Returns the translation (i.e., a string defined for the currently selected language) of a provided language key.

Variables can also be provided using an object as the second argument. The variable replacement looks for occurrences of double curly braces, e.g., {{foo}}.

setTranslations()

Sets the translations (custom language to key to string mapping) for the pilet.

getTranslations()

Gets the translations defined in the pilet.

Setup and Bootstrapping

The provided library only brings API extensions for pilets to a Piral instance.

For the setup of the library itself you'll need to import createLocaleApi from the piral-translate package.

import { createLocaleApi } from 'piral-translate';

The integration looks like:

const instance = createInstance({
  // important part
  extendApi: [createLocaleApi()],
  // ...
});

Via the options the available languages, translations, as well as the currently selected language can be chosen.

For example:

const localizer = setupLocalizer({
  language: 'en',
  messages: {
    en: {
      'greeting': 'Hello',
    },
    de: {
      'greeting': 'Hallo',
    },
  },
});

const instance = createInstance({
  // important part
  extendApi: [createLocaleApi(localizer)],
  // ...
});

Alternatively, the current language can also be inferred via a function.

const localizer = setupLocalizer({
  language: getUserLocale,
  messages: {
    en: {
      'greeting': 'Hello',
    },
    de: {
      'greeting': 'Hallo',
    },
  },
});

The function getUserLocale retrieves either the cookie with name _culture or local storage value for key locale. In any case either the first found language or ultimately en is used as a fallback.

License

Piral is released using the MIT license. For more information see the license file.

Keywords

FAQs

Package last updated on 03 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc