first commit
This commit is contained in:
7
node_modules/hexo-i18n/LICENSE
generated
vendored
Normal file
7
node_modules/hexo-i18n/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2014 Tommy Chen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
102
node_modules/hexo-i18n/README.md
generated
vendored
Normal file
102
node_modules/hexo-i18n/README.md
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
# hexo-i18n
|
||||
|
||||
[](https://github.com/hexojs/hexo-i18n/actions?query=workflow%3ATester)
|
||||
[](https://www.npmjs.com/package/hexo-i18n)
|
||||
[](https://coveralls.io/r/hexojs/hexo-i18n?branch=master)
|
||||
|
||||
i18n module for [Hexo].
|
||||
|
||||
## Installation
|
||||
|
||||
``` bash
|
||||
$ npm install hexo-i18n --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Example
|
||||
|
||||
``` js
|
||||
var i18n = new require('hexo-i18n')({
|
||||
languages: ['zh-TW', 'en']
|
||||
});
|
||||
|
||||
i18n.set('en', {
|
||||
ok: 'OK',
|
||||
name: 'My name is %1$s %2$s.',
|
||||
index: {
|
||||
title: 'Home'
|
||||
},
|
||||
video: {
|
||||
zero: 'No videos',
|
||||
one: 'A video',
|
||||
other: '%d videos'
|
||||
}
|
||||
});
|
||||
|
||||
i18n.set('zh-TW', {
|
||||
name: '我的名字是 %2$s %1$s。',
|
||||
index: {
|
||||
title: '首頁'
|
||||
},
|
||||
video: {
|
||||
zero: '沒有影片',
|
||||
one: '一部影片',
|
||||
other: '%d 部影片'
|
||||
}
|
||||
});
|
||||
|
||||
var __ = i18n.__();
|
||||
var _p = i18n._p();
|
||||
|
||||
__('ok') // OK
|
||||
__('index.title') // 首頁
|
||||
__('name', '大呆', '王') // 我的名字是王大呆
|
||||
_p('video', 0) // 沒有影片
|
||||
_p('video', 1) // 一部影片
|
||||
_p('video', 10) // 10 部影片
|
||||
```
|
||||
|
||||
### new i18n([options])
|
||||
|
||||
Creates a new i18n instance.
|
||||
|
||||
Option | Description | Default
|
||||
--- | --- | ---
|
||||
`languages` | Default languages. It can be an array or a string | `default`
|
||||
|
||||
### i18n.get([lang]) → Object
|
||||
|
||||
Returns a set of localization data. `lang` can be an array or a string, or the default language defined in constructor if not set. This method will build the data in order of languages.
|
||||
|
||||
### i18n.set(lang, data)
|
||||
|
||||
Loads localization data.
|
||||
|
||||
### i18n.remove(lang)
|
||||
|
||||
Unloads localization data.
|
||||
|
||||
### i18n.list()
|
||||
|
||||
Lists loaded languages.
|
||||
|
||||
### i18n.__() → Function(key, arg...)
|
||||
|
||||
Returns a function for localization.
|
||||
|
||||
### i18n._p() → Function(key, count, ...)
|
||||
|
||||
This method is similar to `i18n.__`, but it returns pluralized string based on the second parameter. For example:
|
||||
|
||||
``` js
|
||||
_p('video', 0) = __('video.zero', 0)
|
||||
_p('video', 1) = __('video.one', 1)
|
||||
_p('video', 10) = __('video.other', 10)
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[Hexo]: https://hexo.io/
|
||||
15
node_modules/hexo-i18n/dist/i18n.d.ts
generated
vendored
Normal file
15
node_modules/hexo-i18n/dist/i18n.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
interface Options {
|
||||
languages?: string[];
|
||||
}
|
||||
declare class i18n {
|
||||
data: object;
|
||||
languages: string[];
|
||||
constructor(options?: Options);
|
||||
get(languages?: string[] | string): {};
|
||||
set(lang: string, data: object): this;
|
||||
remove(lang: string): this;
|
||||
list(): string[];
|
||||
__(lang?: string[]): (key: string, ...args: any[]) => string;
|
||||
_p(lang?: string[]): (key: string, ...args: any[]) => string;
|
||||
}
|
||||
export = i18n;
|
||||
96
node_modules/hexo-i18n/dist/i18n.js
generated
vendored
Normal file
96
node_modules/hexo-i18n/dist/i18n.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
const sprintf_js_1 = require("sprintf-js");
|
||||
class i18n {
|
||||
constructor(options = {}) {
|
||||
this.data = {};
|
||||
this.languages = options.languages || ['default'];
|
||||
if (!Array.isArray(this.languages)) {
|
||||
this.languages = [this.languages];
|
||||
}
|
||||
}
|
||||
get(languages) {
|
||||
const { data } = this;
|
||||
const result = {};
|
||||
if (languages) {
|
||||
if (!Array.isArray(languages)) {
|
||||
languages = [languages];
|
||||
}
|
||||
}
|
||||
else {
|
||||
languages = this.languages;
|
||||
}
|
||||
languages.forEach(lang => {
|
||||
const langData = data[lang];
|
||||
if (langData) {
|
||||
Object.keys(langData).forEach(key => {
|
||||
if (!Object.prototype.hasOwnProperty.call(result, key)) {
|
||||
result[key] = langData[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
set(lang, data) {
|
||||
if (typeof lang !== 'string')
|
||||
throw new TypeError('lang must be a string!');
|
||||
if (typeof data !== 'object')
|
||||
throw new TypeError('data is required!');
|
||||
this.data[lang] = flattenObject(data);
|
||||
return this;
|
||||
}
|
||||
remove(lang) {
|
||||
if (typeof lang !== 'string')
|
||||
throw new TypeError('lang must be a string!');
|
||||
delete this.data[lang];
|
||||
return this;
|
||||
}
|
||||
list() {
|
||||
return Object.keys(this.data);
|
||||
}
|
||||
__(lang) {
|
||||
const data = this.get(lang);
|
||||
return (key, ...args) => {
|
||||
if (!key)
|
||||
return '';
|
||||
const str = data[key] || key;
|
||||
return (0, sprintf_js_1.vsprintf)(str, args);
|
||||
};
|
||||
}
|
||||
_p(lang) {
|
||||
const data = this.get(lang);
|
||||
return (key, ...args) => {
|
||||
if (!key)
|
||||
return '';
|
||||
const number = args.length ? +args[0] : 0;
|
||||
let str = key;
|
||||
if (!number && Object.prototype.hasOwnProperty.call(data, `${key}.zero`)) {
|
||||
str = data[`${key}.zero`];
|
||||
}
|
||||
else if (number === 1 && Object.prototype.hasOwnProperty.call(data, `${key}.one`)) {
|
||||
str = data[`${key}.one`];
|
||||
}
|
||||
else if (Object.prototype.hasOwnProperty.call(data, `${key}.other`)) {
|
||||
str = data[`${key}.other`];
|
||||
}
|
||||
else if (Object.prototype.hasOwnProperty.call(data, key)) {
|
||||
str = data[key];
|
||||
}
|
||||
return (0, sprintf_js_1.vsprintf)(str, args);
|
||||
};
|
||||
}
|
||||
}
|
||||
function flattenObject(data, obj = {}, parent = '') {
|
||||
Object.keys(data).forEach(key => {
|
||||
const item = data[key];
|
||||
if (typeof item === 'object') {
|
||||
flattenObject(item, obj, `${parent + key}.`);
|
||||
}
|
||||
else {
|
||||
obj[parent + key] = item;
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
module.exports = i18n;
|
||||
//# sourceMappingURL=i18n.js.map
|
||||
1
node_modules/hexo-i18n/dist/i18n.js.map
generated
vendored
Normal file
1
node_modules/hexo-i18n/dist/i18n.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../lib/i18n.ts"],"names":[],"mappings":";AAAA,2CAAsC;AAMtC,MAAM,IAAI;IAIR,YAAY,UAAmB,EAAE;QAC/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ules/hexo-i18n/package.json
generated
vendored
Normal file
50
node_modules/hexo-i18n/package.json
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "hexo-i18n",
|
||||
"version": "2.0.0",
|
||||
"description": "i18n module for Hexo.",
|
||||
"main": "dist/i18n.js",
|
||||
"scripts": {
|
||||
"prepublish ": "npm run clean && npm run build",
|
||||
"build": "tsc -b",
|
||||
"clean": "tsc -b --clean",
|
||||
"eslint": "eslint .",
|
||||
"pretest": "npm run clean && npm run build",
|
||||
"test": "mocha test/index.js --require ts-node/register",
|
||||
"test-cov": "c8 --reporter=lcovonly npm run test"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "./lib"
|
||||
},
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"types": "./dist/i18n.d.ts",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"repository": "hexojs/hexo-i18n",
|
||||
"homepage": "https://hexo.io/",
|
||||
"keywords": [
|
||||
"hexo",
|
||||
"i18n",
|
||||
"localization"
|
||||
],
|
||||
"author": "Tommy Chen <tommy351@gmail.com> (https://zespia.tw)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"sprintf-js": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.8",
|
||||
"@types/sprintf-js": "^1.1.2",
|
||||
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
||||
"@typescript-eslint/parser": "^5.41.0",
|
||||
"c8": "^7.12.0",
|
||||
"chai": "^4.3.6",
|
||||
"eslint": "^8.26.0",
|
||||
"eslint-config-hexo": "^5.0.0",
|
||||
"mocha": "^10.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.8.4"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user