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

@inlang/translatable

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inlang/translatable

This library provides an interface for externally provided translations.

  • 1.3.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
31K
increased by23.23%
Maintainers
2
Weekly downloads
 
Created
Source

What does this library?

This library provides an interface for externally provided translations.

Design goals

  • Incrementally adoptable. Most applications start without any translation logic and suddenly find themselves in need of translation logic. This library allows you to add translation logic to your application without having to rewrite large parts of your application.
  • A stable (data) interface with no implementation logic This library only defines a (data) interface to exchange translations between internal and external parties. This library does not include implementation logic to reduce the risk of breaking changes.

How to use

When to use this library

  • Translations are outside of your control (e.g. provided by a third party like a user, customer, or plugin developer).

When not to use this library

  • You are the only one providing translations for your application. Use an i18n library instead.

Install

You can install the @inlang/cli with this command:

npm install @inlang/translatable

or

yarn add @inlang/translatable

Usage

import { Translatable } from "@inlang/translatable"

const translatable1: Translatable<string> = "Hello world"
const translatable2: Translatable<string> = {
	en: "Hello world",
	de: "Hallo Welt",
}

// "Hello world"
const translation = typeof translatable1 === "object" ? translatable1["de"] ?? translatable.en : translatable1

// "Hello world"
const translation = typeof translatable2 === "object" ? translatable2.en : translatable2

// "Hallo Welt"
const translation = typeof translatable2 === "object" ? translatable2["de"] ?? translatable2.en : translatable2

You are free to write utility functions.

import { Translatable } from "@inlang/translatable"

const translatable1: Translatable<string> = "Hello world"
const translatable2: Translatable<string> = {
	en: "Hello world",
	de: "Hallo Welt",
}

// Hello world
const translation = t(translatable1, "de")

FAQs

Package last updated on 15 Feb 2024

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