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.1.0
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

@inlang/translatable

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.
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.

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 12 Sep 2023

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