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

jquery.gettext

v0.1.0

Published

Simple gettext library.

Downloads

5

Readme

Javascript i18n using gettext, jQuery and Python

This toolkit uses a combination of gettext, a jQuery plugin and a Python script to enable the internationalization of Javascript files.

This technique is to be used before deploying or commiting javascript code. It take the form of a single console command which goes through multiple parsing and conversion steps. After this command is executed, a JSON file is available and can be used via a jQuery plugin.

Requirements

Sample javascript code

function write(txt) {
    $("#console").append(txt + "<br/>")
}
write(_("Humpty Dumpty sat on a wall,"));
write(_("Humpty Dumpty had a great fall."));
write(_("All the king's horses, And all the king's men,"));
write(_("Couldn't put Humpty together again."));

Setup needed in the HTML document

<html lang="fr">
    <link href="javascript.en.json" lang="en" rel="gettext" />
    <link href="javascript.fr.json" lang="fr" rel="gettext" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.gettext.js"></script>
<script type="text/javascript">$.gt.load();</script>
<script type="text/javascript" src="test.js"></script>

Console command and expected output

C:\gettext> makemessages.bat
Extracting keys from javascript code
Merging new keys with existing keys
Converting message files to binary
0 translated messages, 4 untranslated messages.
4 translated messages.
Converting binary files to JSON
Removing temp files

Resulting JSON files

{
"": "Project-Id-Version: \nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2009-01-29 14:30-0500\nPO-Revision-Date: 2009-01-30 11:05-0500\nLast-Translator: John Doe <[email protected]>\nLanguage-Team: fr <[email protected]>\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n", 
"Couldn't put Humpty together again.": "Ne purent jamais Remonter Humpty.", 
"Humpty Dumpty sat on a wall,": "Humpty Dumpty s'assit sur le mur,", 
"All the king's horses, And all the king's men,": "Tous les chevaux du roi, Et tous les soldats du roi", 
"Humpty Dumpty had a great fall.": "Humpty Dumpty se cassa la figure."
}