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

grunt-i18n-finder

v0.0.6

Published

Looks into files for references to i18n function calls. If found, verifies if all resource files contains entries for them. If not, a new entry is created.

Downloads

3

Readme

grunt-i18n-finder

Looks into files for references to i18n function calls. If found, verifies if all resource files contains entries for them. If not, a new entry is created. See https://github.com/mashpie/i18n-node

Eg: If you have a jade Template, or any other file ...

h1 !{__('This is a resource')}

Eg: if you have resource files, like en.js or en.json

{
"This is a resource":"This is a resource"

}

You can use this tool, to, search all your source files (jade, js, coffee ...), for references to the i18n library. The tool will, based on all configured languages, create or update all language files and add the resources missing.

This is usefull since, you wont need to add new resources manually to the language files, or to wait for the library to add them for you there.

The implementation that detects the resources into files is very basic, so, based on what you do, you might want to modify that by implementing a function and passing as the options.findExpressions fileContent, options

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-i18n-finder --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-i18n-finder');

The "i18n_finder" task

Overview

In your project's Gruntfile, add a section named i18n_finder to the data object passed into grunt.initConfig().

grunt.initConfig({
  i18n_finder: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

Options

options.findExpressions

Type: Function Default value:

You can implement this function, that receives two arguments: fileContent as String, and options.

This function must return an array of Strings, where each String represents a resource key.

options.write

Type: Boolean Default value: true

If false, changes wont be saved into disk. But you can still use the tool as a report tool.

options.resetFile

Type: Boolean Default value: false

If true, all language files will be created from stratch. This means, if you had resources not used, they wont be there anymore, if not detected.

options.supportedLanguages

Type: Array Default value: ["en"]

All the languages described here will have its language files processed.

options.translationExtension

Type: String Default value: ".json"

The extension where the resource files are stored.

options.debug

Type: Boolean Default value: false

If true, grunt will output debug messages.

Usage Examples

Default Options

In this example, the default options are used to do something with whatever. So if the testing file has the content Testing and the 123 file had the content 1 2 3, the generated result would be Testing, 1 2 3.

grunt.initConfig({
  i18n_finder: {
			default_options: {
				options: {}
				cwd: 'test/fixtures/'
				src: ['**/*.coffee'] // all source files that should be analyzed for i18n references
				dest: 'tmp' // where its stored the resource files eg: en.json
			}
  },
})

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Most code is written in coffe-script, so, use Grunt to compile. The task is written in Javascript.

Release History

  • 0.0.6 - michalkow changed the regex, added lazy to find multiple translations per line
  • 0.0.5 - Improved Regex - Now it finds resources even if you use parameters like eg: __('alsdalasd', params, zzz)
  • 0.0.4 - Fixed underscore dependencies (by Pierre-Antoine Delnatte)
  • 0.0.3 - Improved Detection of __("Resource"), now checks for spaces between ( and " ...
  • 0.0.2 - Improved Stats, now they are logged in grunt output
  • 0.0.1 - First Version, Support for __() expressions built in.