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

ziey-gettext

v0.7.2

Published

gettext in javascript

Downloads

30

Readme

Getext in javascript

NPM version

NPM

i18n tool, gnu gettext

  1. po format string to/from javascript object
  2. load po format file
  3. save to po format file
  • node version: 8+

Install

npm install ziey-gettext

Usage

var gettext = require( 'ziey-gettext' );

gettext.getLang

/**
 * @return {string}   # 当前语言
 */
gettext.getLang()

gettext.setLang

/**
 * @param {string} lang         # 设置当前语言,Exp: zh_CN, en_US ...
 * @return {string}             # 当前语言
 */
gettext.setLang( lang )

gettext.handlePo

/**
 * @param {string} lang         # 设置的语言名称,Exp: zh_CN, en_US ...
 * @param {string} po_file_path # po 文件路径
 * @return {object|undefined}   # 设置成功返回 Object
 */
gettext.handlePo( lang, po_file_path )

gettext.handlePoTxt

/**
 * @param {string} lang       # 设置的语言名称,Exp: zh_CN, en_US ...
 * @param {string} po_text    # po 格式内容
 * @return {object|undefined} # 设置成功返回 Object
 */
gettext.handlePo( lang, po_text )

gettext.gettext

/**
 * @param {string} str # 要翻译的文本
 * @return {string}    # 返回翻译结果
 */
gettext.gettext( str )
gettext._( str ) // alias

gettext.clear

/**
 * @description 清空翻译词条
 */
gettext.clear()

gettext.updateCurrentDict

/**
 * @param {string} msgid             # 词条原文,新增或者更新现有词典
 * @param {object} opts              # 更新明细
 * @param {string} opts.str          # 词条译文
 * @param {reference} opts.reference # 词条来源
 */
gettext.updateCurrentDict( msgid, opts )

gettext.cleanCurrentDictReference

/**
 * @description 清空当前词典中的来源
 */
gettext.cleanCurrentDictReference()

gettext.clearCurrentDictEmptyItem [Discard]

/**
 * @description 清空当前词典中的空词条 (废弃)
 *              建议使用 clearDict
 */
gettext.clearCurrentDictEmptyItem()

gettext.clearDict

/**
 * @description 清理字典
 * @param {boolean} options.str 是否要根据 str 为空来清理
 * @param {boolean} options.reference 是否要根据 reference 为空来清理
 * @param {string} options.lang? 指定语言,默认为当前选中语言
 */
gettext.clearDict()

gettext.po2obj

/**
 * @param {string} po_text # po 格式内容
 * @return {object}        # 根据 po 文本生成的 object 对象
 */
gettext.po2obj( po_text );

gettext.obj2po

/**
 * @param {object} obj    # 带翻译标识的 object 对象
 * @param {string} header # 需要补充到  header 的文本
 * @return {string}       # 生成的 po 格式文本
 */
gettext.obj2po( obj, header );

Test

npm test