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

txty

v1.1.4

Published

A basic language pack manager to make it easy to swap between languages in your node.js app.

Downloads

2

Readme

Txty

Build Status Coverage Status

A basic language pack manager to make it easy to swap out all the text in your node.js app interface.

It doesn't translate anything though :-) You will need to go get all the translations you need for your dictionary files yourself. There may be better alternatives out there, but this is a simple project with no bells and whistles.

  • Just use it with a single language, to help keep the wording used within your interface elements consistent and easy to update in one place, e.g. page_title: "Welcome to txty" or homepage_download_button: "Download Free Now!"
  • Turn on debugging to [highlight] your txty-fied text in the front-end, so you can easily hunt down un-txty-fied text!
  • Add other language dictionary files so you can easily and consistently change language
  • No dependencies

Installation

This is just Javascript, but it is intended for Node.js use

  1. Download and Install Node.js
  2. Create your project any way you like, e.g. using Express
  3. Install txty npm install txty --save

Require

Include txty at the top of any js file where you wish to txty-fy your plain text var txty = require("txty");

or, e.g. if you are using Express, simply include once in your main app.js, and just pass the txty variable around as needed using locals req.app.locals.txty = require("txty");

init(options)

Initialise txty with it's default options (see defaults below) txty.init();

Or Initialise with options (see options below). txty.init( { lang: "en" } );

Run the same command with different settings later, e.g. to change language, or alter the dictionary txty.init( { lang: "fr" } );

Then, wherever required in your js, replace any instances of plain text... var outputText = "Download Free Now!" ...with a txty call to your predefined key/value pair var outputText = txty.get("homepage_download_button")

Options

dictionary

Should contain one object for each language, e.g. English, French and Klingon. Minimum one language.

dictionary: {
    en: {},
    fr: {},
    kl: {}
}

Then within each language, simply create the same keys with the relevant values for each language, e.g.

dictionary: {
    en: {
        hello: "Hello",
        goodbye: "Goodbye"
    },
    fr: {
        hello: "Bonjour",
        goodbye: "Au Revoir"
    },
    kl: {
        hello: "nuqneH",
        goodbye: "DaH jImej"
    }
}

or define your dictionaries in separate files, and require them

dictionary: {
    en: require("./languages/en.js"),
    fr: require("./languages/fr.js"),
    kl: require("./languages/kl.js")
}

in which case the 'kl.js' file would contain...

"use strict";
module.exports = kl: {
    hello: "nuqneH",
    goodbye: "DaH jImej"
};

Note: you may not want all your text to be changed during debug mode, such as URLs. Simply wrap the string in an array, and it will be ignored by the debug_prefix or debug_suffix wrappers, e.g.

"use strict";
module.exports = en: {
    admin_url: ["/myadmin/subpage"],//this will not be wrapped during debugging
    admin_title: "My admin Subpage" //this will
};

dictionary: default

Includes a very basic starter! Keep these items in your language files for nice debug output.

dictionary: {
    en: {
      module_language: ["Txty language set to "],
      module_thislang: ["English"],
      module_debug_start: ["###Txty debug mode is on. "],
      module_debug_end: ["###Txty"],
      module_settings: ["Settings are..."],
      module_test: "Test"
    }
}

lang

Sets the language dictionary which txty should refer to. Must match one of those in your dictionary, e.g. lang: "kl" You can change language at any time using init (see above)

lang: default

lang: "en"

debug

To help you identify any stray text which you may not yet have txty-fied, debug will wrap each txty.get() output with the prefix and suffix of your choice.

Note: See above to exclude certain text from the debug wrapping.

debug: default

e.g. with the default settings...

debug: true,
debug_prefix: "<lang='",
debug_suffix: "'/>",

This would change...

var outputText = txty.get("homepage_download_button")

from Download Free Now! to <lang=Download Free Now!/>

License

This project is licensed under the MIT License.