更新
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 kazuya kawaguchi
|
||||
|
||||
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.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
# @intlify/runtime
|
||||
|
||||
The runtime for intlify project
|
||||
|
||||
## :copyright: License
|
||||
|
||||
[MIT](http://opensource.org/licenses/MIT)
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*!
|
||||
* @intlify/runtime v9.1.9
|
||||
* (c) 2021 kazuya kawaguchi
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var shared = require('@intlify/shared');
|
||||
|
||||
const DEFAULT_MODIFIER = (str) => str;
|
||||
const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
|
||||
const DEFAULT_MESSAGE_DATA_TYPE = 'text';
|
||||
const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
|
||||
const DEFAULT_INTERPOLATE = shared.toDisplayString;
|
||||
function pluralDefault(choice, choicesLength) {
|
||||
choice = Math.abs(choice);
|
||||
if (choicesLength === 2) {
|
||||
// prettier-ignore
|
||||
return choice
|
||||
? choice > 1
|
||||
? 1
|
||||
: 0
|
||||
: 1;
|
||||
}
|
||||
return choice ? Math.min(choice, 2) : 0;
|
||||
}
|
||||
function getPluralIndex(options) {
|
||||
// prettier-ignore
|
||||
const index = shared.isNumber(options.pluralIndex)
|
||||
? options.pluralIndex
|
||||
: -1;
|
||||
// prettier-ignore
|
||||
return options.named && (shared.isNumber(options.named.count) || shared.isNumber(options.named.n))
|
||||
? shared.isNumber(options.named.count)
|
||||
? options.named.count
|
||||
: shared.isNumber(options.named.n)
|
||||
? options.named.n
|
||||
: index
|
||||
: index;
|
||||
}
|
||||
function normalizeNamed(pluralIndex, props) {
|
||||
if (!props.count) {
|
||||
props.count = pluralIndex;
|
||||
}
|
||||
if (!props.n) {
|
||||
props.n = pluralIndex;
|
||||
}
|
||||
}
|
||||
function createMessageContext(options = {}) {
|
||||
const locale = options.locale;
|
||||
const pluralIndex = getPluralIndex(options);
|
||||
const pluralRule = shared.isObject(options.pluralRules) &&
|
||||
shared.isString(locale) &&
|
||||
shared.isFunction(options.pluralRules[locale])
|
||||
? options.pluralRules[locale]
|
||||
: pluralDefault;
|
||||
const orgPluralRule = shared.isObject(options.pluralRules) &&
|
||||
shared.isString(locale) &&
|
||||
shared.isFunction(options.pluralRules[locale])
|
||||
? pluralDefault
|
||||
: undefined;
|
||||
const plural = (messages) => messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
||||
const _list = options.list || [];
|
||||
const list = (index) => _list[index];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const _named = options.named || {};
|
||||
shared.isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
|
||||
const named = (key) => _named[key];
|
||||
// TODO: need to design resolve message function?
|
||||
function message(key) {
|
||||
// prettier-ignore
|
||||
const msg = shared.isFunction(options.messages)
|
||||
? options.messages(key)
|
||||
: shared.isObject(options.messages)
|
||||
? options.messages[key]
|
||||
: false;
|
||||
return !msg
|
||||
? options.parent
|
||||
? options.parent.message(key) // resolve from parent messages
|
||||
: DEFAULT_MESSAGE
|
||||
: msg;
|
||||
}
|
||||
const _modifier = (name) => options.modifiers
|
||||
? options.modifiers[name]
|
||||
: DEFAULT_MODIFIER;
|
||||
const normalize = shared.isPlainObject(options.processor) && shared.isFunction(options.processor.normalize)
|
||||
? options.processor.normalize
|
||||
: DEFAULT_NORMALIZE;
|
||||
const interpolate = shared.isPlainObject(options.processor) &&
|
||||
shared.isFunction(options.processor.interpolate)
|
||||
? options.processor.interpolate
|
||||
: DEFAULT_INTERPOLATE;
|
||||
const type = shared.isPlainObject(options.processor) && shared.isString(options.processor.type)
|
||||
? options.processor.type
|
||||
: DEFAULT_MESSAGE_DATA_TYPE;
|
||||
const ctx = {
|
||||
["list" /* LIST */]: list,
|
||||
["named" /* NAMED */]: named,
|
||||
["plural" /* PLURAL */]: plural,
|
||||
["linked" /* LINKED */]: (key, modifier) => {
|
||||
// TODO: should check `key`
|
||||
const msg = message(key)(ctx);
|
||||
return shared.isString(modifier) ? _modifier(modifier)(msg) : msg;
|
||||
},
|
||||
["message" /* MESSAGE */]: message,
|
||||
["type" /* TYPE */]: type,
|
||||
["interpolate" /* INTERPOLATE */]: interpolate,
|
||||
["normalize" /* NORMALIZE */]: normalize
|
||||
};
|
||||
return ctx;
|
||||
}
|
||||
|
||||
exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
|
||||
exports.createMessageContext = createMessageContext;
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*!
|
||||
* @intlify/runtime v9.1.9
|
||||
* (c) 2021 kazuya kawaguchi
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var shared = require('@intlify/shared');
|
||||
|
||||
const DEFAULT_MODIFIER = (str) => str;
|
||||
const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
|
||||
const DEFAULT_MESSAGE_DATA_TYPE = 'text';
|
||||
const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
|
||||
const DEFAULT_INTERPOLATE = shared.toDisplayString;
|
||||
function pluralDefault(choice, choicesLength) {
|
||||
choice = Math.abs(choice);
|
||||
if (choicesLength === 2) {
|
||||
// prettier-ignore
|
||||
return choice
|
||||
? choice > 1
|
||||
? 1
|
||||
: 0
|
||||
: 1;
|
||||
}
|
||||
return choice ? Math.min(choice, 2) : 0;
|
||||
}
|
||||
function getPluralIndex(options) {
|
||||
// prettier-ignore
|
||||
const index = shared.isNumber(options.pluralIndex)
|
||||
? options.pluralIndex
|
||||
: -1;
|
||||
// prettier-ignore
|
||||
return options.named && (shared.isNumber(options.named.count) || shared.isNumber(options.named.n))
|
||||
? shared.isNumber(options.named.count)
|
||||
? options.named.count
|
||||
: shared.isNumber(options.named.n)
|
||||
? options.named.n
|
||||
: index
|
||||
: index;
|
||||
}
|
||||
function normalizeNamed(pluralIndex, props) {
|
||||
if (!props.count) {
|
||||
props.count = pluralIndex;
|
||||
}
|
||||
if (!props.n) {
|
||||
props.n = pluralIndex;
|
||||
}
|
||||
}
|
||||
function createMessageContext(options = {}) {
|
||||
const locale = options.locale;
|
||||
const pluralIndex = getPluralIndex(options);
|
||||
const pluralRule = shared.isObject(options.pluralRules) &&
|
||||
shared.isString(locale) &&
|
||||
shared.isFunction(options.pluralRules[locale])
|
||||
? options.pluralRules[locale]
|
||||
: pluralDefault;
|
||||
const orgPluralRule = shared.isObject(options.pluralRules) &&
|
||||
shared.isString(locale) &&
|
||||
shared.isFunction(options.pluralRules[locale])
|
||||
? pluralDefault
|
||||
: undefined;
|
||||
const plural = (messages) => messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
||||
const _list = options.list || [];
|
||||
const list = (index) => _list[index];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const _named = options.named || {};
|
||||
shared.isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
|
||||
const named = (key) => _named[key];
|
||||
// TODO: need to design resolve message function?
|
||||
function message(key) {
|
||||
// prettier-ignore
|
||||
const msg = shared.isFunction(options.messages)
|
||||
? options.messages(key)
|
||||
: shared.isObject(options.messages)
|
||||
? options.messages[key]
|
||||
: false;
|
||||
return !msg
|
||||
? options.parent
|
||||
? options.parent.message(key) // resolve from parent messages
|
||||
: DEFAULT_MESSAGE
|
||||
: msg;
|
||||
}
|
||||
const _modifier = (name) => options.modifiers
|
||||
? options.modifiers[name]
|
||||
: DEFAULT_MODIFIER;
|
||||
const normalize = shared.isPlainObject(options.processor) && shared.isFunction(options.processor.normalize)
|
||||
? options.processor.normalize
|
||||
: DEFAULT_NORMALIZE;
|
||||
const interpolate = shared.isPlainObject(options.processor) &&
|
||||
shared.isFunction(options.processor.interpolate)
|
||||
? options.processor.interpolate
|
||||
: DEFAULT_INTERPOLATE;
|
||||
const type = shared.isPlainObject(options.processor) && shared.isString(options.processor.type)
|
||||
? options.processor.type
|
||||
: DEFAULT_MESSAGE_DATA_TYPE;
|
||||
const ctx = {
|
||||
["list" /* LIST */]: list,
|
||||
["named" /* NAMED */]: named,
|
||||
["plural" /* PLURAL */]: plural,
|
||||
["linked" /* LINKED */]: (key, modifier) => {
|
||||
// TODO: should check `key`
|
||||
const msg = message(key)(ctx);
|
||||
return shared.isString(modifier) ? _modifier(modifier)(msg) : msg;
|
||||
},
|
||||
["message" /* MESSAGE */]: message,
|
||||
["type" /* TYPE */]: type,
|
||||
["interpolate" /* INTERPOLATE */]: interpolate,
|
||||
["normalize" /* NORMALIZE */]: normalize
|
||||
};
|
||||
return ctx;
|
||||
}
|
||||
|
||||
exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
|
||||
exports.createMessageContext = createMessageContext;
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
import { Path } from '@intlify/message-resolver';
|
||||
|
||||
export declare type CoreMissingType = 'translate' | 'datetime format' | 'number format';
|
||||
|
||||
export declare function createMessageContext<T = string, N = {}>(options?: MessageContextOptions<T, N>): MessageContext<T>;
|
||||
|
||||
export declare const DEFAULT_MESSAGE_DATA_TYPE = "text";
|
||||
|
||||
declare type ExtractToStringFunction<T> = T[ExtractToStringKey<T>];
|
||||
|
||||
declare type ExtractToStringKey<T> = Extract<keyof T, 'toString'>;
|
||||
|
||||
/** @VueI18nGeneral */
|
||||
export declare type FallbackLocale = Locale | Locale[] | {
|
||||
[locale in string]: Locale[];
|
||||
} | false;
|
||||
|
||||
/** @VueI18nGeneral */
|
||||
export declare type LinkedModifiers<T = string> = {
|
||||
[key: string]: LinkedModify<T>;
|
||||
};
|
||||
|
||||
export declare type LinkedModify<T = string> = (value: T) => MessageType<T>;
|
||||
|
||||
/** @VueI18nGeneral */
|
||||
export declare type Locale = string;
|
||||
|
||||
export declare interface MessageContext<T = string> {
|
||||
list(index: number): unknown;
|
||||
named(key: string): unknown;
|
||||
plural(messages: T[]): T;
|
||||
linked(key: Path, modifier?: string): MessageType<T>;
|
||||
message(key: Path): MessageFunction<T>;
|
||||
type: string;
|
||||
interpolate: MessageInterpolate<T>;
|
||||
normalize: MessageNormalize<T>;
|
||||
}
|
||||
|
||||
export declare interface MessageContextOptions<T = string, N = {}> {
|
||||
parent?: MessageContext<T>;
|
||||
locale?: string;
|
||||
list?: unknown[];
|
||||
named?: NamedValue<N>;
|
||||
modifiers?: LinkedModifiers<T>;
|
||||
pluralIndex?: number;
|
||||
pluralRules?: PluralizationRules;
|
||||
messages?: MessageFunctions<T> | MessageResolveFunction<T>;
|
||||
processor?: MessageProcessor<T>;
|
||||
}
|
||||
|
||||
export declare type MessageFunction<T = string> = MessageFunctionCallable | MessageFunctionInternal<T>;
|
||||
|
||||
export declare type MessageFunctionCallable = <T = string>(ctx: MessageContext<T>) => MessageType<T>;
|
||||
|
||||
export declare type MessageFunctionInternal<T = string> = {
|
||||
(ctx: MessageContext<T>): MessageType<T>;
|
||||
key?: string;
|
||||
locale?: string;
|
||||
source?: string;
|
||||
};
|
||||
|
||||
export declare type MessageFunctions<T = string> = Record<string, MessageFunction<T>>;
|
||||
|
||||
export declare type MessageInterpolate<T = string> = (val: unknown) => MessageType<T>;
|
||||
|
||||
export declare type MessageNormalize<T = string> = (values: MessageType<string | T>[]) => MessageType<T | T[]>;
|
||||
|
||||
export declare interface MessageProcessor<T = string> {
|
||||
type?: string;
|
||||
interpolate?: MessageInterpolate<T>;
|
||||
normalize?: MessageNormalize<T>;
|
||||
}
|
||||
|
||||
export declare type MessageResolveFunction<T = string> = (key: string) => MessageFunction<T>;
|
||||
|
||||
export declare type MessageType<T = string> = T extends string ? string : StringConvertable<T>;
|
||||
|
||||
/** @VueI18nGeneral */
|
||||
export declare type NamedValue<T = {}> = T & Record<string, unknown>;
|
||||
|
||||
export declare type PluralizationProps = {
|
||||
n?: number;
|
||||
count?: number;
|
||||
};
|
||||
|
||||
export declare type PluralizationRule = (choice: number, choicesLength: number, orgRule?: PluralizationRule) => number;
|
||||
|
||||
/** @VueI18nGeneral */
|
||||
export declare type PluralizationRules = {
|
||||
[locale: string]: PluralizationRule;
|
||||
};
|
||||
|
||||
declare type StringConvertable<T> = ExtractToStringKey<T> extends never ? unknown : ExtractToStringFunction<T> extends (...args: any) => string ? T : unknown;
|
||||
|
||||
export { }
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/*!
|
||||
* @intlify/runtime v9.1.9
|
||||
* (c) 2021 kazuya kawaguchi
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
import { isNumber, isObject, isString, isFunction, isPlainObject, toDisplayString } from '@intlify/shared';
|
||||
|
||||
const DEFAULT_MODIFIER = (str) => str;
|
||||
const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
|
||||
const DEFAULT_MESSAGE_DATA_TYPE = 'text';
|
||||
const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
|
||||
const DEFAULT_INTERPOLATE = toDisplayString;
|
||||
function pluralDefault(choice, choicesLength) {
|
||||
choice = Math.abs(choice);
|
||||
if (choicesLength === 2) {
|
||||
// prettier-ignore
|
||||
return choice
|
||||
? choice > 1
|
||||
? 1
|
||||
: 0
|
||||
: 1;
|
||||
}
|
||||
return choice ? Math.min(choice, 2) : 0;
|
||||
}
|
||||
function getPluralIndex(options) {
|
||||
// prettier-ignore
|
||||
const index = isNumber(options.pluralIndex)
|
||||
? options.pluralIndex
|
||||
: -1;
|
||||
// prettier-ignore
|
||||
return options.named && (isNumber(options.named.count) || isNumber(options.named.n))
|
||||
? isNumber(options.named.count)
|
||||
? options.named.count
|
||||
: isNumber(options.named.n)
|
||||
? options.named.n
|
||||
: index
|
||||
: index;
|
||||
}
|
||||
function normalizeNamed(pluralIndex, props) {
|
||||
if (!props.count) {
|
||||
props.count = pluralIndex;
|
||||
}
|
||||
if (!props.n) {
|
||||
props.n = pluralIndex;
|
||||
}
|
||||
}
|
||||
function createMessageContext(options = {}) {
|
||||
const locale = options.locale;
|
||||
const pluralIndex = getPluralIndex(options);
|
||||
const pluralRule = isObject(options.pluralRules) &&
|
||||
isString(locale) &&
|
||||
isFunction(options.pluralRules[locale])
|
||||
? options.pluralRules[locale]
|
||||
: pluralDefault;
|
||||
const orgPluralRule = isObject(options.pluralRules) &&
|
||||
isString(locale) &&
|
||||
isFunction(options.pluralRules[locale])
|
||||
? pluralDefault
|
||||
: undefined;
|
||||
const plural = (messages) => messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
|
||||
const _list = options.list || [];
|
||||
const list = (index) => _list[index];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const _named = options.named || {};
|
||||
isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
|
||||
const named = (key) => _named[key];
|
||||
// TODO: need to design resolve message function?
|
||||
function message(key) {
|
||||
// prettier-ignore
|
||||
const msg = isFunction(options.messages)
|
||||
? options.messages(key)
|
||||
: isObject(options.messages)
|
||||
? options.messages[key]
|
||||
: false;
|
||||
return !msg
|
||||
? options.parent
|
||||
? options.parent.message(key) // resolve from parent messages
|
||||
: DEFAULT_MESSAGE
|
||||
: msg;
|
||||
}
|
||||
const _modifier = (name) => options.modifiers
|
||||
? options.modifiers[name]
|
||||
: DEFAULT_MODIFIER;
|
||||
const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize)
|
||||
? options.processor.normalize
|
||||
: DEFAULT_NORMALIZE;
|
||||
const interpolate = isPlainObject(options.processor) &&
|
||||
isFunction(options.processor.interpolate)
|
||||
? options.processor.interpolate
|
||||
: DEFAULT_INTERPOLATE;
|
||||
const type = isPlainObject(options.processor) && isString(options.processor.type)
|
||||
? options.processor.type
|
||||
: DEFAULT_MESSAGE_DATA_TYPE;
|
||||
const ctx = {
|
||||
["list" /* LIST */]: list,
|
||||
["named" /* NAMED */]: named,
|
||||
["plural" /* PLURAL */]: plural,
|
||||
["linked" /* LINKED */]: (key, modifier) => {
|
||||
// TODO: should check `key`
|
||||
const msg = message(key)(ctx);
|
||||
return isString(modifier) ? _modifier(modifier)(msg) : msg;
|
||||
},
|
||||
["message" /* MESSAGE */]: message,
|
||||
["type" /* TYPE */]: type,
|
||||
["interpolate" /* INTERPOLATE */]: interpolate,
|
||||
["normalize" /* NORMALIZE */]: normalize
|
||||
};
|
||||
return ctx;
|
||||
}
|
||||
|
||||
export { DEFAULT_MESSAGE_DATA_TYPE, createMessageContext };
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
module.exports = require('./dist/runtime.cjs.prod.js')
|
||||
} else {
|
||||
module.exports = require('./dist/runtime.cjs.js')
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "@intlify/runtime",
|
||||
"version": "9.1.9",
|
||||
"description": "@intlify/runtime",
|
||||
"keywords": [
|
||||
"i18n",
|
||||
"internationalization",
|
||||
"intlify",
|
||||
"runtime"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "kazuya kawaguchi",
|
||||
"email": "kawakazu80@gmail.com"
|
||||
},
|
||||
"homepage": "https://github.com/intlify/vue-i18n-next/tree/master/packages/runtime#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/intlify/vue-i18n-next.git",
|
||||
"directory": "packages/runtime"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/intlify/vue-i18n-next/issues"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"dist"
|
||||
],
|
||||
"main": "index.js",
|
||||
"module": "dist/runtime.esm-bundler.js",
|
||||
"types": "dist/runtime.d.ts",
|
||||
"dependencies": {
|
||||
"@intlify/message-compiler": "9.1.9",
|
||||
"@intlify/message-resolver": "9.1.9",
|
||||
"@intlify/shared": "9.1.9"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"buildOptions": {
|
||||
"name": "IntlifyRuntime",
|
||||
"formats": [
|
||||
"esm-bundler",
|
||||
"cjs"
|
||||
]
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"sideEffects": false
|
||||
}
|
||||
Reference in New Issue
Block a user