@appnest/lit-translate
Advanced tools
Comparing version 1.1.6 to 1.1.7
{ | ||
"name": "@appnest/lit-translate", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"license": "MIT", | ||
@@ -50,3 +50,4 @@ "module": "index.js", | ||
"s": "npm run s:dev", | ||
"deploy": "npm run b:demo:prod && firebase deploy" | ||
"deploy": "npm run b:demo:prod && firebase deploy", | ||
"readme": "node node_modules/.bin/readme" | ||
}, | ||
@@ -57,5 +58,31 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@appnest/web-config": "0.3.11", | ||
"@appnest/web-config": "0.3.19", | ||
"@appnest/readme": "^1.0.1", | ||
"lit-element": "^2.0.1" | ||
}, | ||
"readme": { | ||
"demo": "https://appnest-demo.firebaseapp.com/lit-translate", | ||
"toc": true, | ||
"ids": { | ||
"github": "andreasbm/lit-translate", | ||
"npm": "@appnest/lit-translate", | ||
"webcomponents": "@appnest/lit-translate" | ||
}, | ||
"badges": [ | ||
{ | ||
"text": "Awesome", | ||
"url": "https://github.com/web-padawan/awesome-lit-html", | ||
"img": "https://awesome.re/badge.svg" | ||
} | ||
], | ||
"bullets": [ | ||
"Simple API that can return a translation for a given key (out of the box you can use the dot notation eg. `get(\"home.header.title\")`)", | ||
"Works very well with JSON based translation data-structures", | ||
"Can interpolate values into the strings", | ||
"Customize just about everything (eg. choose your own translations loader, how to interpolate values, empty placeholder and how to look up the strings)", | ||
"Caches the translations for maximum performance", | ||
"Contains a `lit-html` directive that automatically updates when the language changes", | ||
"Approximately 800 bytes minified & gzipped (2kb without)" | ||
] | ||
} | ||
} |
@@ -1,16 +0,17 @@ | ||
# @appnest/lit-translate | ||
<h1 align="center">@appnest/lit-translate</h1> | ||
<p align="center"> | ||
<a href="https://github.com/web-padawan/awesome-lit-html"><img alt="undefined" src="https://awesome.re/badge.svg" height="20"/></a> | ||
<a href="https://npmcharts.com/compare/@appnest/lit-translate?minimal=true"><img alt="Downloads per month" src="https://img.shields.io/npm/dm/@appnest/lit-translate.svg" height="20"/></a> | ||
<a href="https://www.npmjs.com/package/@appnest/lit-translate"><img alt="NPM Version" src="https://img.shields.io/npm/v/@appnest/lit-translate.svg" height="20"/></a> | ||
<a href="https://david-dm.org/andreasbm/lit-translate"><img alt="Dependencies" src="https://img.shields.io/david/andreasbm/lit-translate.svg" height="20"/></a> | ||
<a href="https://github.com/andreasbm/lit-translate/graphs/contributors"><img alt="Contributors" src="https://img.shields.io/github/contributors/andreasbm/lit-translate.svg" height="20"/></a> | ||
<a href="https://www.webcomponents.org/element/@appnest/lit-translate"><img alt="Published on webcomponents.org" src="https://img.shields.io/badge/webcomponents.org-published-blue.svg" height="20"/></a> | ||
</p> | ||
<p align="center"> | ||
<b>A lightweight blazing-fast internationalization (i18n) library for your next web-based project</b></br> | ||
<sub> Go here to see a demo <a href="https://appnest-demo.firebaseapp.com/lit-translate">https://appnest-demo.firebaseapp.com/lit-translate</a>.<sub> | ||
</p> | ||
<a href="https://npmcharts.com/compare/@appnest/lit-translate?minimal=true"><img alt="Downloads per month" src="https://img.shields.io/npm/dm/@appnest/lit-translate.svg" height="20"></img></a> | ||
<a href="https://david-dm.org/andreasbm/lit-translate"><img alt="Dependencies" src="https://img.shields.io/david/andreasbm/lit-translate.svg" height="20"></img></a> | ||
<a href="https://www.npmjs.com/package/@appnest/lit-translate"><img alt="NPM Version" src="https://img.shields.io/npm/v/@appnest/lit-translate.svg" height="20"></img></a> | ||
<a href="https://github.com/andreasbm/lit-translate/graphs/contributors"><img alt="Contributors" src="https://img.shields.io/github/contributors/andreasbm/lit-translate.svg" height="20"></img></a> | ||
<a href="https://opensource.org/licenses/MIT"><img alt="MIT License" src="https://img.shields.io/badge/License-MIT-yellow.svg" height="20"></img></a> | ||
[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/@appnest/lit-translate) | ||
<br /> | ||
## What is this? | ||
This is a lightweight blazing-fast internationalization (i18n) library for your next web-based project. Go here to see a demo [https://appnest-demo.firebaseapp.com/lit-translate/](https://appnest-demo.firebaseapp.com/lit-translate). | ||
**Features** | ||
* Simple API that can return a translation for a given key (out of the box you can use the dot notation eg. `get("home.header.title")`) | ||
@@ -24,24 +25,25 @@ * Works very well with JSON based translation data-structures | ||
<img src="https://raw.githubusercontent.com/andreasbm/lit-translate/master/example.gif" width="600"> | ||
## Table of Contents | ||
* [Installation](#installation) | ||
* [1. Define the translations](#1-Define-the-translations) | ||
* [2. Register the translate config](#2-register-the-translate-config) | ||
* [3. Set the language](#3-set-the-language) | ||
* [4. Get the translations](#4-get-the-translations) | ||
* [5. Interpolate values](#5-interpolate-values) | ||
* [6. Use the `translate` directive together with `lit-html`](#6-use-the-translate-directive-together-with-lit-html) | ||
* [Customize! (advanced)](#customize-advanced) | ||
* [Wait for strings to be loaded before displaying the component](#wait-for-strings-to-be-loaded-before-displaying-the-component) | ||
* [License](#-license) | ||
* [❯ Installation](#-installation) | ||
* [❯ 1. Define the translations](#-1-define-the-translations) | ||
* [❯ 2. Register the translate config](#-2-register-the-translate-config) | ||
* [❯ 3. Set the language](#-3-set-the-language) | ||
* [❯ 4. Get the translations](#-4-get-the-translations) | ||
* [❯ 5. Interpolate values](#-5-interpolate-values) | ||
* [❯ 6. Use the `translate` directive together with `lit-html`](#-6-use-the-translate-directive-together-with-lit-html) | ||
* [❯ Customize! (advanced)](#-customize-advanced) | ||
* [❯ Wait for strings to be loaded before displaying the component](#-wait-for-strings-to-be-loaded-before-displaying-the-component) | ||
* [❯ License](#-license) | ||
## Installation | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
## ❯ Installation | ||
```javascript | ||
npm i @appnest/lit-translate | ||
``` | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
## 1. Define the translations | ||
## ❯ 1. Define the translations | ||
@@ -58,3 +60,3 @@ To take advantage of the translation features you need to be able to provide your translations as a JSON structure. You are able to configure how these strings are loaded, but to make things simple we encourage you to maintain your translations in `.json` files - one for each language you support. | ||
"cta": { | ||
"awesome": "{{ things }} are awesome!", | ||
"awesome": "things are awesome!", | ||
"cats": "Cats" | ||
@@ -65,4 +67,6 @@ } | ||
## 2. Register the translate config | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
## ❯ 2. Register the translate config | ||
Use the `registerTranslateConfig` function to register a loader that loads and parses the translations based on a language identifier. In the example below, a loader is registered which loads a `.json` file with translations for a given language. | ||
@@ -78,5 +82,5 @@ | ||
It is possible to use the `registerTranslateConfig` function to customize almost everything from the library. To learn more you can see `step 7`. | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
## 3. Set the language | ||
## ❯ 3. Set the language | ||
@@ -91,4 +95,6 @@ Invoke the `use` function to set a language. This function will use the registered loader from step 1 to load the strings for the language and dispatch a global `langChanged` event. | ||
## 4. Get the translations | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
## ❯ 4. Get the translations | ||
To get a translation use the `get` function. Give this function a string of keys (using the dot notation) that points to the desired translation in the JSON structure. The example below is based on the translations defined in `step 1`. | ||
@@ -103,6 +109,8 @@ | ||
## 5. Interpolate values | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
Using the `get` function it is possible to interpolate values. As default, you can simply use the `{{ key }}` syntax in your translations and provide an object with values replacing those defined in the translations when using the `get` function. The example below is based on the strings defined in `step 1`. | ||
## ❯ 5. Interpolate values | ||
When using the `get` function it is possible to interpolate values (eg. replace the placeholders with content). As default, you can simply use the `key` syntax in your translations and provide an object with values replacing those defined in the translations when using the `get` function. The example below is based on the strings defined in `step 1`. | ||
```typescript | ||
@@ -114,4 +122,7 @@ import { get } from "@appnest/lit-translate"; | ||
## 6. Use the `translate` directive together with `lit-html` | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
## ❯ 6. Use the `translate` directive together with `lit-html` | ||
If you are using `lit-html` you might want to use the `translate` directive. This directive makes sure to automatically update all of the translated parts when the `use` function is called and the global `langChanged` event is dispatched. Note that values have to be returned from callbacks to refresh the translated values. | ||
@@ -133,4 +144,6 @@ | ||
## Customize! (advanced) | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
## ❯ Customize! (advanced) | ||
If you want you can customize just about anything by overwriting the configuration hooks. Below is an example on what you might want to customize. | ||
@@ -178,4 +191,6 @@ | ||
## Wait for strings to be loaded before displaying the component | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
## ❯ Wait for strings to be loaded before displaying the component | ||
Sometimes you want to avoid the empty placeholders being shown initially before any of the translation strings has been loaded. To avoid this issue you might want to defer the first update of the component. Here's an example of what you could do if using `lit-element`. | ||
@@ -211,5 +226,7 @@ | ||
## 🎉 License | ||
Licensed under [MIT](https://opensource.org/licenses/MIT). | ||
![line](https://github.com/andreasbm/readme/blob/master/assets/line.png) | ||
## ❯ License | ||
Licensed under [MIT](https://opensource.org/licenses/MIT). |
32901
222
3