Skip to content

Commit

Permalink
Replaced internal parser with gettext-parser. Removed excess features…
Browse files Browse the repository at this point in the history
…. Bumped version to v1.0.0
  • Loading branch information
andris9 committed Jan 21, 2015
1 parent 242b434 commit c1a44ef
Show file tree
Hide file tree
Showing 22 changed files with 2,517 additions and 3,062 deletions.
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
npm-debug.log
.DS_Store
19 changes: 19 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"indent": 4,
"node": true,
"globalstrict": true,
"evil": true,
"unused": true,
"undef": true,
"newcap": true,
"esnext": true,
"curly": true,
"eqeqeq": true,
"expr": true,

"predef": [
"describe",
"it",
"beforeEach"
]
}
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
language: node_js
node_js:
- 0.6
- 0.7
- "0.10"
- "0.11"

before_install:
- npm install -g grunt-cli

notifications:
email:
recipients:
- andris@node.ee
- andris@kreata.ee
on_success: change
on_failure: change
webhooks:
urls:
- https://webhooks.gitter.im/e/0ed18fd9b3e529b3c2cc
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: false # default: false
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

## v1.0.0 2015-01-21

* Bumped version to 1.0.0 to be compatible with semver
* Removed built in parser/compiler in favor of gettext-parser module
* Moved tests from nodeunit to mocha

30 changes: 30 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
jshint: {
all: ['lib/*.js', 'test/*.js', 'index.js'],
options: {
jshintrc: '.jshintrc'
}
},

mochaTest: {
all: {
options: {
reporter: 'spec'
},
src: ['test/*-test.js']
}
}
});

// Load the plugin(s)
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-mocha-test');

// Tasks
grunt.registerTask('default', ['jshint', 'mochaTest']);
};
94 changes: 10 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

* Load binary *MO* or source *PO* files
* Supports contexts and plurals
* Add your own translations to the list
* Recompile current translation table into a *MO* or a *PO* file!

[![Build Status](https://secure.travis-ci.org/andris9/node-gettext.png)](http://travis-ci.org/andris9/node-gettext)

Expand All @@ -28,7 +26,7 @@
var Gettext = require("node-gettext");

var gt = new Gettext();

### Add a language

*addTextdomain(domain, file)*
Expand Down Expand Up @@ -72,13 +70,13 @@ The function also returns the current texdomain value
*gettext(msgid)*

var greeting = gt.gettext("Hello!");

### Load a string from a specific language file

*dgettext(domain, msgid)*

var greeting = gt.dgettext("et", "Hello!");

### Load a plural string from default language file

*ngettext(msgid, msgid_plural, count)*
Expand All @@ -90,7 +88,7 @@ The function also returns the current texdomain value
*dngettext(domain, msgid, msgid_plural, count)*

gt.dngettext("et", "%d Comment", "%d Comments", 10)

### Load a string of a specific context

*pgettext(msgctxt, msgid)*
Expand All @@ -102,13 +100,13 @@ The function also returns the current texdomain value
*dpgettext(domain, msgctxt, msgid)*

gt.dpgettext("et", "menu items", "File");

### Load a plural string of a specific context

*npgettext(msgctxt, msgid, msgid_plural, count)*

gt.npgettext("menu items", "%d Recent File", "%d Recent Files", 3);

### Load a plural string of a specific context from specific language file

*dnpgettext(domain, msgctxt, msgid, msgid_plural, count)*
Expand All @@ -121,85 +119,13 @@ The function also returns the current texdomain value

gt.getComment("et", "menu items", "%d Recent File");

Returns an object in the form of `{comment: "", code: "", note: "", flag: ""}`

### Sets a comments for a translation

*setComment(domain, msgctxt, msgid, comment)*

gt.getComment("et", "menu items", "%d Recent File", "This is a comment");

`comment` can either be a string or an object with the following properties: `{comment: "", code: "", note: "", flag: ""}`.

## String helpers

In order to make things really easy, it is possible to attach the gettext functions directly to string
prototypes with `gettext.registerStringHelpers()`

Example:

// setup gettext
var gettext = new Gettext();
gettext.registerStringHelpers();
gettext.addTextdomain("et", fs.readFileSync("et.mo"));

// translate any string
var translated = "translate this string".gettext();
// or
var plural = "translate %s string".ngettext("translate %s strings", 10);

// you can even change the default textdomain
"".textdomain("en");

The parameters for the gettext functions are the same as with regular gettext methods, except that the `msgid` parameter is not needed.

## Manage translations

### Add a translation

*setTranslation(domain, context, msgid, translation)*

gt.setTranslation("et", "", "Hello", "Tere");

Use an array for plurals

gt.setTranslation("et", "", "%s comments", ["%s kommentaar", "%s kommentaari"]);

### Remove a translation

*deleteTranslation(domain, context, msgid)*

gt.deleteTranslation("et", "", "Hello");

### List available contexts

*listContextNames([domain])*

var contextStrArr = gt.listContextNames("et");

### List translation keys for a context

*listKeys([domain], [context])*

var originalsStrArr = gt.listKeys("et", "");

## Compiling

### Compile to MO

Compile current translation table to a *MO* file

*compileMO([domain])*

fs.writeFile("out.mo", gt.compileMO("et"));

### Compile to PO
Returns an object in the form of `{translator: "", extracted: "", reference: "", flag: "", previous: ""}`

Compile current translation table to a *PO* file
## Advanced handling

*compilePO([domain])*
If you need the translation object for a domain, for example `et_EE`, you can access it from `gt.domains.et_EE`.

fs.writeFile("out.po", gt.compilePO("et"));
If you want modify it and compile it to *mo* or *po*, checkout [gettext-parser](https://github.com/andris9/gettext-parser) module.

## License

Expand Down
3 changes: 0 additions & 3 deletions index.js

This file was deleted.

Loading

0 comments on commit c1a44ef

Please sign in to comment.