Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeanfortheweb/translata
The Composable Translation Utility
https://github.com/jeanfortheweb/translata
hooks i18n node react translation typescript
Last synced: 24 days ago
JSON representation
The Composable Translation Utility
- Host: GitHub
- URL: https://github.com/jeanfortheweb/translata
- Owner: jeanfortheweb
- License: mit
- Created: 2019-03-30T00:58:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T18:46:54.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T22:32:48.405Z (about 1 month ago)
- Topics: hooks, i18n, node, react, translation, typescript
- Language: TypeScript
- Size: 738 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/jeanfortheweb/translata.svg?branch=master)](https://travis-ci.org/jeanfortheweb/translata) [![Maintainability](https://api.codeclimate.com/v1/badges/29e376d945395da69418/maintainability)](https://codeclimate.com/github/jeanfortheweb/translata/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/29e376d945395da69418/test_coverage)](https://codeclimate.com/github/jeanfortheweb/translata/test_coverage)
# Translata - The Composable Translation Utility
**Translata** was created when I struggled with the current i18n utilities avaible. They seem outdated, had features I don't need, or where unusable (in a smooth way) in modular environments. So I decided to create a utility based on functional principles with some simple goals:
- **Modular** - Decide which features you need and in which environment.
- **Independent** - No global scope, no mutations, no singletons. Create as many translators as you like.
- **Easy** - It should be possible to mix and match a setup with minimal effort.**Translata** is completely written in TypeScript and supports advanced typings.
## Installation
For the most simple use cases, you just have to install the core package. It will give you the `createTranslator` function plus
all those middlewares you need to get started:```sh
yarn add @translata/core
```## Usage
A translator is created by using the `createTranslator` function. It takes a variable number of middlewares to create the translation function you want.
In the most simple case, you just need to define a default locale and a set of translation strings:
```ts
// translator.tsimport {
createTranslator,
withDefaultLocale,
withTranslations,
} from '@translata/core';export default createTranslator(
withTranslations('en', {
'user.greeting': 'Welcome to Translata!',
}),
withTranslations('de', {
'user.greeting': 'Willkommen bei Translata!',
}),
withDefaultLocale('en'),
);
```Now you can use it in your project somewhere else:
```ts
import _ from './translator';_('user.greeting'); // Welcome to Translata!
_('user.greeting', { locale: 'de' }); // Willkommen bei Translata!
```## Documentation
For a full documentation, just checkout the `README.md` files for each package, since they will go into detail for each scope:
- [@translata/core](./packages/core/README.md)
- [@translata/node](./packages/node/README.md)
- [@translata/react](./packages/react/README.md)