Skip to content

Commit

Permalink
changelog, readme; bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumepotier committed Aug 12, 2022
1 parent af3a2c6 commit 4f79209
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# gettext.js changelog

**[2.0.0]** [BC Break]

- ngettext, dcnpgettext bc break change to match better the GNU gettext
plural form specification.

**[1.0.0]**

- add support for single plural languages
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,30 @@ i18n.setLocale('fr');
* **`pgettext(msgctxt, msgid)`**: Translate a string specified by context. Shorthand is **`_p()`**.
* **`dcnpgettext(domain, msgctxt, msgid, msgid_plural, n)`**: Translate a potentially pluralizable string, potentially specified by context, and potentially of a different domain (as specified in `setMessages` or `loadJSON`). No shorthand.


### Plural forms

`ngettext` and `dcnpgettext` accept a `n` parameter to specify the plural form.

```javascript
i18n.ngettext('There is an apple', 'There are many apples', 1); // There is an apple
i18n.ngettext('There is an apple', 'There are many apples', 10); // There are many apples
i18n.ngettext('There is %1 apple', 'There are %1 apples', 10); // There are %1 apples
i18n.ngettext('There is %1 apple', 'There are %1 apples', 10, 10); // There are 10 apples
```

### Variabilized strings

All four functions above can take extra arguments for variablization.

`gettext('There are %1 in the %2', 'apples', 'bowl');` -> "There are apples in the bowl

`ngettext('One %2', '%1 %2', 10, 'bananas');` -> "10 bananas"
`ngettext('One %2', '%1 %2', 10, 10, 'bananas');` -> "10 bananas"

It uses the public method `i18n.strfmt("string", var1, var2, ...)` you could
reuse elsewhere in your project.


#### Literal percent sign (%)

When you need to have literal percent sign followed by a number (common in Hebrew or Turkish) you can escape it using another percent sign, for example:
Expand Down
4 changes: 2 additions & 2 deletions dist/gettext.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ define(function () { 'use strict';
/*! gettext.js - Guillaume Potier - MIT Licensed */
var i18n = function (options) {
options = options || {};
this && (this.__version = '1.1.1');
this && (this.__version = '2.0.0');

// default values that could be overriden in i18n() construct
var defaults = {
Expand Down Expand Up @@ -131,7 +131,7 @@ define(function () { 'use strict';
if ('undefined' === typeof plural.plural || plural.plural > plural.nplurals || messages.length <= plural.plural)
plural.plural = 0;

return strfmt.apply(this, [removeContext(messages[plural.plural])].concat(Array.prototype.slice.call(arguments, 3)));
return strfmt.apply(this, [removeContext(messages[plural.plural]), n].concat(Array.prototype.slice.call(arguments, 3)));
};

return {
Expand Down
2 changes: 1 addition & 1 deletion dist/gettext.amd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/gettext.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*! gettext.js - Guillaume Potier - MIT Licensed */
var i18n = function (options) {
options = options || {};
this && (this.__version = '1.1.1');
this && (this.__version = '2.0.0');

// default values that could be overriden in i18n() construct
var defaults = {
Expand Down Expand Up @@ -131,7 +131,7 @@ var i18n = function (options) {
if ('undefined' === typeof plural.plural || plural.plural > plural.nplurals || messages.length <= plural.plural)
plural.plural = 0;

return strfmt.apply(this, [removeContext(messages[plural.plural])].concat(Array.prototype.slice.call(arguments, 3)));
return strfmt.apply(this, [removeContext(messages[plural.plural]), n].concat(Array.prototype.slice.call(arguments, 3)));
};

return {
Expand Down
2 changes: 1 addition & 1 deletion dist/gettext.cjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/gettext.esm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! gettext.js - Guillaume Potier - MIT Licensed */
var i18n = function (options) {
options = options || {};
this && (this.__version = '1.1.1');
this && (this.__version = '2.0.0');

// default values that could be overriden in i18n() construct
var defaults = {
Expand Down Expand Up @@ -129,7 +129,7 @@ var i18n = function (options) {
if ('undefined' === typeof plural.plural || plural.plural > plural.nplurals || messages.length <= plural.plural)
plural.plural = 0;

return strfmt.apply(this, [removeContext(messages[plural.plural])].concat(Array.prototype.slice.call(arguments, 3)));
return strfmt.apply(this, [removeContext(messages[plural.plural]), n].concat(Array.prototype.slice.call(arguments, 3)));
};

return {
Expand Down
Loading

0 comments on commit 4f79209

Please sign in to comment.