npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chinese-translate

v1.0.2

Published

根据本地繁体字库,实现监听页面文字变动,实时简繁体自动转换。vue和react都实测可以。

Downloads

5

Readme

#########使用说明############

##简繁体转换
####只测过谷歌浏览器,理论上都行####
###安装###
npm i chinese-translate

###测试 test.html 服务启动(live server)###; ###########方法引入###########

import {
  chineseTranslateAll,
  chineseAjaxTranslate,
  chineseStringTranslate,
} from "chinese-translate";
或者分别调用 chineseTranslate,
  chineseObserverTranslate,
  chineseTagNameTranslate,自己配置
import {
  chineseTranslate,
  chineseObserverTranslate,
  chineseTagNameTranslate,
  chineseAjaxTranslate,
  chineseStringTranslate,
} from "chinese-translate";

#########根据本地存储,转繁还是转简体,默认;转简体######

localStorage.setItem('zh-language',"zh-mo") 转繁体;
不设或者localStorage.setItem('zh-language',"zh-cn") 转简体;

############dom 加载完成后,比如 vue 的 mounted 里调用,固定执行方法#########

chineseTranslateAll();
一步到位
//标签外文字,转译
chineseTranslate();

//标签属性文字,转译
chineseTagNameTranslate({
  tagNames: ["input"],
  attributes: ["placeholder"],
});

############@chineseTranslate(obj)也可传参数#########
@chineseTranslate({id:"domId",type:"zh-cn"})

@标签 id 为空时,默认 document

@字体 type 为空时,默认转简体"zh-cn"。转繁体"zh-mo"

@id 可换为 ele 元素,nodes 元素组

chineseTranslate({ ele: ele, });


############@chineseTagNameTranslate(obj)也可传参数#########
@chineseTagNameTranslate({
id,//ele
tagNames:["input","span"],
attributes:["placeholder","data-content"],
type,
})

@标签 id 为空时,默认 document

@obj.equalVal 默认 false ,true 直接赋值,

@tagNames 标签类型,为空,所有标签,document.getElementsByTagName('*')


@attributes,标签属性,必传。为空,不执行

@字体 type 为空时,默认简体


###变动区域文字@chineseObserverTranslate(obj)###

@chineseObserverTranslate({ id,type, childList,characterData,attributes,attributeFilter, callback,callbackContent,callbackAttribute })

@childList 默认 true;characterData、attributes 默认 false;

@obj.callback callback 若没有默认翻译 html, 标签需手动加上 callback(nodes){ chineseTranslate({nodes:nodes,type:obj.type}); }

@obj.callbackContent,characterData 为 true 生效,也可不写

callbackContent(item){ chineseTagNameTranslate({ id:"info_table_prev", tagNames:["div"], attributes:["title"], }) chineseTranslate({ //id:"info_table_prev", ele:ele, }) }

@obj.callbackAttribute,attributes 为 true 生效,也可不写.

@attributeFilter 一个属性名数组 attributeFilter:["value"],

callbackAttribute:function(ele){
console.log(33)
console.log(ele)
chineseTagNameTranslate({
ele:ele,
type:"zh-mo",
tagNames:["input"],
attributes:["value"],
})
},

######实例######


chineseObserverTranslate({
childList: true, //that.state.isChildList,
characterData: true,
callback: function (ele) {
//console.log("1",ele)
chineseTagNameTranslate({
ele: ele,
tagNames: ["div", "input", "select"],
attributes: ["title", "placeholder"],
});

chineseTranslate({
ele: ele,
});
// that.setState({
// isChildList:false
// })
},
callbackContent: function (ele) {
// console.log("2",ele)
chineseTagNameTranslate({
ele: ele,
tagNames: ["div", "input", "select"],
attributes: ["title", "placeholder"],
});
chineseTranslate({
ele: ele,
});
},
});

###@chineseAjaxTranslate(obj)json 或者对象数据转译###


@chineseAjaxTranslate({value,type,lei:"OBJECT"})

@value 为空时,返回空对象

@字体 type 为空时,默认简体

@传入返回否 JSON 或者 OBJECT,lei 为空时,默认 OBJECT


###@chineseStringTranslate(obj)字符串转译###

@chineseStringTranslate({value:"澳门国际"})

@obj 必传,否则返回空字符串

@obj.value 为空时,返回空字符串 也可为字符串 chineseStringTranslate("")

@chineseStringTranslate("澳门国际")