aboutsummaryrefslogtreecommitdiff
path: root/node_modules/y18n
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/y18n')
-rw-r--r--node_modules/y18n/README.md18
-rw-r--r--node_modules/y18n/index.js16
-rw-r--r--node_modules/y18n/package.json16
3 files changed, 43 insertions, 7 deletions
diff --git a/node_modules/y18n/README.md b/node_modules/y18n/README.md
index 9859458f2..826474f20 100644
--- a/node_modules/y18n/README.md
+++ b/node_modules/y18n/README.md
@@ -4,6 +4,7 @@
[![Coverage Status][coveralls-image]][coveralls-url]
[![NPM version][npm-image]][npm-url]
[![js-standard-style][standard-image]][standard-url]
+[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
The bare-bones internationalization library used by yargs.
@@ -23,6 +24,19 @@ output:
`my awesome string foo`
+_using tagged template literals_
+
+```js
+var __ = require('y18n').__
+var str = 'foo'
+
+console.log(__`my awesome string ${str}`)
+```
+
+output:
+
+`my awesome string foo`
+
_pluralization support:_
```js
@@ -60,6 +74,10 @@ Create an instance of y18n with the config provided, options include:
Print a localized string, `%s` will be replaced with `arg`s.
+This function can also be used as a tag for a template literal. You can use it
+like this: <code>__&#96;hello ${'world'}&#96;</code>. This will be equivalent to
+`__('hello %s', 'world')`.
+
### y18n.\_\_n(singularString, pluralString, count, arg, arg, arg)
Print a localized string with appropriate pluralization. If `%d` is provided
diff --git a/node_modules/y18n/index.js b/node_modules/y18n/index.js
index 91b159e34..d72068162 100644
--- a/node_modules/y18n/index.js
+++ b/node_modules/y18n/index.js
@@ -16,6 +16,9 @@ function Y18N (opts) {
}
Y18N.prototype.__ = function () {
+ if (typeof arguments[0] !== 'string') {
+ return this._taggedLiteral.apply(this, arguments)
+ }
var args = Array.prototype.slice.call(arguments)
var str = args.shift()
var cb = function () {} // start with noop.
@@ -40,6 +43,19 @@ Y18N.prototype.__ = function () {
return util.format.apply(util, [this.cache[this.locale][str] || str].concat(args))
}
+Y18N.prototype._taggedLiteral = function (parts) {
+ var args = arguments
+ var str = ''
+ parts.forEach(function (part, i) {
+ var arg = args[i + 1]
+ str += part
+ if (typeof arg !== 'undefined') {
+ str += '%s'
+ }
+ })
+ return this.__.apply(null, [str].concat([].slice.call(arguments, 1)))
+}
+
Y18N.prototype._enqueueWrite = function (work) {
this.writeQueue.push(work)
if (this.writeQueue.length === 1) this._processWriteQueue()
diff --git a/node_modules/y18n/package.json b/node_modules/y18n/package.json
index e4e594430..f44d52d35 100644
--- a/node_modules/y18n/package.json
+++ b/node_modules/y18n/package.json
@@ -1,12 +1,13 @@
{
"name": "y18n",
- "version": "3.2.1",
+ "version": "4.0.0",
"description": "the bare-bones internationalization library used by yargs",
"main": "index.js",
"scripts": {
"pretest": "standard",
"test": "nyc mocha",
- "coverage": "nyc report --reporter=text-lcov | coveralls"
+ "coverage": "nyc report --reporter=text-lcov | coveralls",
+ "release": "standard-version"
},
"repository": {
"type": "git",
@@ -27,11 +28,12 @@
},
"homepage": "https://github.com/yargs/y18n",
"devDependencies": {
- "chai": "^3.4.1",
- "coveralls": "^2.11.6",
- "mocha": "^2.3.4",
- "nyc": "^6.1.1",
+ "chai": "^4.0.1",
+ "coveralls": "^3.0.0",
+ "mocha": "^4.0.1",
+ "nyc": "^11.0.1",
"rimraf": "^2.5.0",
- "standard": "^5.4.1"
+ "standard": "^10.0.0-beta.0",
+ "standard-version": "^4.2.0"
}
}