Giter Club home page Giter Club logo

lang-hant's Introduction

lang-hant

网页简体繁体转换工具,无需配置导入即可实现转换,默认转换为繁体

安装

npm

npm install lang-hant

使用

基础使用

直接导入,默认转换为繁体

import 'lang-hant'

进阶使用

如果有简体繁体互相切换的需求,使用内部提供的changeLanguage方法

import { changeLanguage } from 'lang-hant'
changeLanguage('简体') // 切换为简体
changeLanguage('繁体') // 切换为繁体

其他使用

如果有手动更新的需求,内部提供了handleTran方法

import { handleTran } from 'lang-hant'
handleTran()

暂停、重新开始转换

暂停转换,调用内部提供的pauseObserver方法

重新开始转换,调用内部提供的restartObserver方法

import { pauseObserver } from 'lang-hant'
pauseObserver() // 暂停
restartObserver() // 重新开始

实现原理

handleTran方法递归body,将全部文字进行转换

使用MutationObserverAPI,监听Body子节点和文本变化,节流调用handleTran方法

lang-hant's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.