Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/jaywcjlove/translater.js

♣︎ This is a use of HTML comments page translation solution. For a small amount of static pages, this solution is more simple. it has no dependents, Compression only (4KB)
https://github.com/jaywcjlove/translater.js

javascript translates

Last synced: 5 days ago
JSON representation

♣︎ This is a use of HTML comments page translation solution. For a small amount of static pages, this solution is more simple. it has no dependents, Compression only (4KB)

Awesome Lists containing this project

README

        

# translater.js

[![](https://jaywcjlove.github.io/sb/ico/npm.svg)](https://www.npmjs.com/package/translater.js) [![](http://jaywcjlove.github.io/sb/status/no-dependencies.svg)](#) [![](http://jaywcjlove.github.io/sb/status/stable.svg)](#) [![](https://jaywcjlove.github.io/sb/license/mit.svg)](#) [![jaywcjlove/sb](https://jaywcjlove.github.io/sb/lang/chinese.svg)](https://jaywcjlove.github.io/translater.js/?lang=cn) [![jaywcjlove/sb](https://jaywcjlove.github.io/sb/lang/english.svg)](https://jaywcjlove.github.io/translater.js/?lang=en) [![CDNJS version](https://img.shields.io/cdnjs/v/translater.js.svg)](https://cdnjs.com/libraries/translater.js)

这是一个利用HTML注释的页面翻译解决方案。对于少量的静态页面,这种解决方案显得更简单。它没有依赖,压缩只有只有(~2kb)。官方文档 [实例预览](http://jaywcjlove.github.io/translater.js/).

- 支持 `IMG` `文本` 切换
- 支持 URL 加载语言
- 支持本地缓存选择

![translater.js 动画效果](translater.js.gif)

## 安装

```bash
$ npm install translater.js
```

```
import 'translater.js';
```

或者手动下载并在HTML中链接 **[translater.js](https://unpkg.com/translater.js/dist/)**,也可以通过 [UNPKG](https://unpkg.com/translater.js/dist/) 下载:

```html


这里是中文


var tran = new Translater({
lang:"jp"
});

```

切换语言方法通过超链接

```html
English
日本語
中文
```

可以通过URL穿参数设置语言

```url
http://127.0.0.1:9005/test/test.html?lang=jp
```

## Text

```html


这里是中文



```

## Image

```html
image
```

## Input

```html

```

## getLang/setLang

获取或设置当前语言。

```html

var tran = new Translater();
if (tran.getLang() === "default") tran.setLang('en');

```