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

xplates-string-table

v0.9.2

Published

A string table format for XPlates

Downloads

4

Readme

XPlates String Table

What is this?

This is a string table reader for XPlates, for use in internationalization.

It reads easy-to-use string tables that have the full power of JavaScript and XPlates.

String Table Format

//Very simple string map:  call bundle.hello_world()
hello_world: Hello, World!    

//Comments are supported with double slashes
welcome_msg:  Welcome! //At the ends of lines too.

//Arguments are fully supported, call bundle.hello("World")
hello(name): Hello, <%= name %>!

//Full code execution example
party: Party like it's <%= new Date().getFullYear() %>

//Conditional example for pluralization
messages(count):  You have <%= count %> <%? count === 1 %>message<%??%>messages<%?%>

//Multi-line example.
poem:
  Roses are red,      
  Violets are blue,
  
  XPlates is awesome,      
  String tables are too!      
  
//Map example, with a "__default" fallback
//  bundle.color("red") -> "rojo"
//  bundle.color("purple") -> "purple"   (will fall back on __default function)
color$red:          rojo
color$green:        verde
color$blue:         azul
color$__default(c): <%= c %>

//Maps can have arguments too!    
date_part$year(d):        Year <%= d.getFullYear() %>
date_part$month(d):       Month <%= d.getMonth()+1 %>
date_part$day(d):         Day <%= d.getDate() %>
date_part$__default(k,d): Unknown <%= d.toISOString() %>

//It's an XPlate bundle, so you can use the full logic of other pieces too!
copyright_year: 2017
copyright_statement:  Copyright <%% copyright_year() %>, all right reserved.

//You can override the default language by adding it as a prefix.  Any XPlates-supported language works.
html:greeting(name): <b>Hello, <i><%= name %></i>!</b>

Usage:

//Require
var XPlatesStringTable = require('xplates-string-table');

//Create a bundle
var bundle = new XPlates.bundle;

//Read a file synchronously
XPlatesStringTable.parseFileIntoBundleSync(bundle, { language: "text" }, "/path/to/file.txt");

//Read a file asynchronously
XPlatesStringTable.parseFileIntoBundle(bundle, { language: "text" }, "/path/to/file.txt", function(err) { ... });

//Read a buffer or string synchronously
XPlatesStringTable.parseIntoBundleSync(bundle, { language: "text" }, my_string_table_buffer);

//Read a buffer or string asynchronously
XPlatesStringTable.parseIntoBundle(bundle, { language: "text" }, my_string_table_buffer, function(err) { ... });

//It automatically trims every line, but you can turn that off.
XPlatesStringTable.parseFileIntoBundleSync(bundle, { language: "text", trim: false }, "/path/to/file.txt");

//JavaScript style //comments will be automatically removed - but you can turn that off too:
XPlatesStringTable.parseFileIntoBundleSync(bundle, { language: "text", comments: false }, "/path/to/file.txt");

//Additional paramaters that XPlates processes will be passed along, such as "predefined":
XPlatesStringTable.parseFileIntoBundleSync(bundle, { language: "text", predefined: { abc: 123 } }, "/path/to/file.txt");

//Get map keys
//Example:  if you had a string table with this:
//  color$red:          rojo
//  color$green:        verde
//  color$blue:         azul
//  color$__default(c): <%= c %>
//.. then calling it would give you the keys defined, not including __default
//  XPlatesStringTable.getMapKeys(bundle) -> { "color": ["red","green","blue"] }

//This adds additional functions to the bundle named "map__keys" that return the set of keys
//Example:  using the same as above,
//  bundle.color__keys() --> ["red","green","blue"]
XPlatesStringTable.addKeyFunctions(bundle);

//You can also require all new templates to start with a prefix you're worried about bad matches.
//For example, this makes line "TEMPLATE:foo:" start a template, and line "bar:" not start a template.
XPlatesStringTable.parseFileIntoBundleSync(bundle, { language: "text", prefix: "TEMPLATE:" }, "/path/to/file.txt");