@kotori-bot/i18n
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -1,26 +0,11 @@ | ||
export declare enum LocaleIdentifier { | ||
ja_JP = 0, | ||
en_US = 1, | ||
zh_TW = 2, | ||
zh_CN = 3 | ||
import { I18n as I18nCommon, LocaleType, localeData } from './common'; | ||
export * from './common'; | ||
export declare class I18n<T extends LocaleType = LocaleType> extends I18nCommon<T> { | ||
private ext; | ||
private loader; | ||
constructor(config?: ConstructorParameters<typeof I18nCommon<T>>[0] & { | ||
ext?: string; | ||
}); | ||
use(locales: localeData | string, lang?: T): void; | ||
} | ||
export type LocaleType = keyof typeof LocaleIdentifier; | ||
export interface localeData { | ||
[propName: string]: string; | ||
} | ||
export type LocaleDataList = { | ||
[K in LocaleType]: localeData; | ||
}; | ||
export declare class Locale { | ||
private readonly localeDataList; | ||
private lang; | ||
constructor(type?: LocaleType); | ||
use(data: { | ||
type: LocaleType; | ||
locales: localeData; | ||
}): void; | ||
locale(val: string, type?: LocaleType): string; | ||
set(lang: LocaleType): void; | ||
get(): "ja_JP" | "en_US" | "zh_TW" | "zh_CN"; | ||
} | ||
export default Locale; | ||
export default I18n; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Locale = exports.LocaleIdentifier = void 0; | ||
var LocaleIdentifier; | ||
(function (LocaleIdentifier) { | ||
LocaleIdentifier[LocaleIdentifier["ja_JP"] = 0] = "ja_JP"; | ||
LocaleIdentifier[LocaleIdentifier["en_US"] = 1] = "en_US"; | ||
LocaleIdentifier[LocaleIdentifier["zh_TW"] = 2] = "zh_TW"; | ||
LocaleIdentifier[LocaleIdentifier["zh_CN"] = 3] = "zh_CN"; | ||
})(LocaleIdentifier || (exports.LocaleIdentifier = LocaleIdentifier = {})); | ||
class Locale { | ||
localeDataList = { | ||
ja_JP: {}, | ||
en_US: {}, | ||
zh_TW: {}, | ||
zh_CN: {}, | ||
}; | ||
lang; | ||
constructor(type = 'en_US') { | ||
this.lang = LocaleIdentifier[type]; | ||
} | ||
use(data) { | ||
Object.keys(this.localeDataList[data.type]).forEach(locale => { | ||
if (!(locale in data.locales)) | ||
exports.I18n = void 0; | ||
const fs_1 = require("fs"); | ||
const path_1 = require("path"); | ||
const common_1 = require("./common"); | ||
const const_1 = require("./const"); | ||
__exportStar(require("./common"), exports); | ||
class I18n extends common_1.I18n { | ||
ext; | ||
loader(dir) { | ||
this.supports.forEach((lang) => { | ||
const file = (0, path_1.join)(dir, `${lang}${this.ext}`); | ||
if (!(0, fs_1.existsSync)(file)) | ||
return; | ||
delete this.localeDataList[data.type][locale]; | ||
try { | ||
const locales = JSON.parse((0, fs_1.readFileSync)(file).toString()); | ||
this.use(locales, lang); | ||
} | ||
catch { | ||
JSON.stringify(''); | ||
} | ||
}); | ||
this.localeDataList[data.type] = Object.assign(this.localeDataList[data.type], data.locales); | ||
} | ||
locale(val, type = LocaleIdentifier[this.lang]) { | ||
if (!(type in this.localeDataList)) | ||
return val; | ||
return val in this.localeDataList[type] ? this.localeDataList[type][val] : val; | ||
constructor(config = { lang: const_1.DEFAULT_LANG }) { | ||
super(config); | ||
this.ext = config.ext ?? const_1.DEFAULT_EXT; | ||
} | ||
set(lang) { | ||
this.lang = LocaleIdentifier[lang]; | ||
use(locales, lang = this.lang) { | ||
if (typeof locales === 'string') { | ||
this.loader(locales); | ||
return; | ||
} | ||
Object.keys(locales).forEach((locale) => { | ||
this.localesData.get(lang).set(locale, locales[locale]); | ||
}); | ||
} | ||
get() { | ||
return LocaleIdentifier[this.lang]; | ||
} | ||
} | ||
exports.Locale = Locale; | ||
exports.default = Locale; | ||
exports.I18n = I18n; | ||
exports.default = I18n; |
{ | ||
"name": "@kotori-bot/i18n", | ||
"version": "1.1.2", | ||
"version": "v1.2.0", | ||
"description": "i18n For Kotori", | ||
"main": "dist/index.js", | ||
"browser": "dist/common.js", | ||
"license": "GPL-3.0", | ||
"author": "Hotaru <biyuehuya@gmail.com>", | ||
"keywords": [ | ||
"kotori", | ||
"chatbot", | ||
"bot", | ||
"robotics", | ||
"kotori" | ||
"i18n", | ||
"tools" | ||
], | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
@@ -17,0 +20,0 @@ "bugs": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
47614
11
278
1
43
1
2