An open API service indexing awesome lists of open source software.

https://github.com/scriptex/attr-i18n

Translate your vanilla websites or web apps using HTML attributes and a pinch of Javascript
https://github.com/scriptex/attr-i18n

html-translation i18n internationalization translation vanilla-i18n

Last synced: 10 months ago
JSON representation

Translate your vanilla websites or web apps using HTML attributes and a pinch of Javascript

Awesome Lists containing this project

README

          

# attr-i18n (Internationalization through HTML attributes)

[![Github Build](https://github.com/scriptex/attr-i18n/workflows/Build/badge.svg)](https://github.com/scriptex/attr-i18n/actions?query=workflow%3ABuild)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/34d3d75710534dc6a38c3584a1dcd068)](https://www.codacy.com/gh/scriptex/attr-i18n/dashboard?utm_source=github.com&utm_medium=referral&utm_content=scriptex/attr-i18n&utm_campaign=Badge_Grade)
[![Codebeat Badge](https://codebeat.co/badges/d765a4c8-2c0e-44f2-89c3-fa364fdc14e6)](https://codebeat.co/projects/github-com-scriptex-attr-i18n-master)
[![CodeFactor Badge](https://www.codefactor.io/repository/github/scriptex/attr-i18n/badge)](https://www.codefactor.io/repository/github/scriptex/attr-i18n)
[![DeepScan grade](https://deepscan.io/api/teams/3574/projects/5257/branches/40799/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=3574&pid=5257&bid=40799)
[![Analytics](https://ga-beacon-361907.ew.r.appspot.com/UA-83446952-1/github.com/scriptex/attr-i18n/README.md?pixel)](https://github.com/scriptex/attr-i18n/)

> Translate your vanilla websites or web apps using HTML attributes and a pinch of Javascript

## Visitor stats

![GitHub stars](https://img.shields.io/github/stars/scriptex/attr-i18n?style=social)
![GitHub forks](https://img.shields.io/github/forks/scriptex/attr-i18n?style=social)
![GitHub watchers](https://img.shields.io/github/watchers/scriptex/attr-i18n?style=social)
![GitHub followers](https://img.shields.io/github/followers/scriptex?style=social)

## Code stats

![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/scriptex/attr-i18n)
![GitHub repo size](https://img.shields.io/github/repo-size/scriptex/attr-i18n?style=plastic)
![GitHub language count](https://img.shields.io/github/languages/count/scriptex/attr-i18n?style=plastic)
![GitHub top language](https://img.shields.io/github/languages/top/scriptex/attr-i18n?style=plastic)
![GitHub last commit](https://img.shields.io/github/last-commit/scriptex/attr-i18n?style=plastic)

## Install

```sh
npm i attr-i18n

# or

yarn add attr-i18n
```

## Usage

First import and initialize the module.

```typescript
import { AttrI18n } from 'attr-i18n';

const languages = ['English', 'हिन्दी', 'français'];

new AttrI18n(languages, {
attr: 'data-translation',
path: 'assets/translations',
debug: true,
togglerID: 'language-toggle',
defaultLang: languages[0]
});
```

Then in your HTML file(s):

1. Add an HTML select element with the ID corresponding to the `togglerID` option above. This select element will toggle between languages
2. Add the translation files in the folder you specified in the `path` option above. Each of the language files should be named after the language name as it appears in the `languages` array above.
3. Use the `data-translation` attribute as set in the option `attr` above by adding it to each element you want translated. The `data-translation` attribute accepts a dot-delimited string which points to the translation you want to use.

## Options

| Name | Type | Required | Default | Description |
| ------------- | --------- | -------- | ------------------- | --------------------------------------------------------------------------- |
| `attr` | `string` | false | `data-attr-i18n` | HTML attribute which contains the translation key |
| `path` | `string` | false | `assets/attr-i18n` | Path to the folder which contains the translation JSON file(s) |
| `debug` | `boolean` | false | `false` | Turns debug mode on/off |
| `togglerID` | `string` | false | `attr-i18n-toggler` | ID attribute for the language toggle HTML select element |
| `defaultLang` | `string` | false | `languages[0]` | The default language. If not provided, the first one from the array is used |

## Example HTML

### Language selector HTML select element

```html

English
हिन्दी
français

```

### Page content

```html

Fill Your Details!


Name:



Age:



Do you exercise at home?



  • Yes


  • No




```

## LICENSE

MIT

---


Connect with me:






 



 



 



 



 



 



 



 



 



 



 



---


Support and sponsor my work: