vue3-gettext
Advanced tools
Comparing version 2.0.0-alpha.3 to 2.0.0-beta.1
@@ -95,3 +95,3 @@ #!/usr/bin/env node | ||
var explorer = cosmiconfig.cosmiconfigSync(moduleName, { | ||
searchPlaces: [moduleName + ".config.js", moduleName + ".config.json"], | ||
searchPlaces: ["".concat(moduleName, ".config.js"), "".concat(moduleName, ".config.json")], | ||
}); | ||
@@ -102,3 +102,3 @@ var configRes; | ||
if (!configRes) { | ||
throw new Error("Config not found: " + cliArgs.config); | ||
throw new Error("Config not found: ".concat(cliArgs.config)); | ||
} | ||
@@ -145,7 +145,7 @@ } | ||
var config = loadConfig(options); | ||
console.info("Language directory: " + chalk__default["default"].blueBright(config.output.path)); | ||
console.info("Locales: " + chalk__default["default"].blueBright(config.output.locales)); | ||
console.info("Language directory: ".concat(chalk__default["default"].blueBright(config.output.path))); | ||
console.info("Locales: ".concat(chalk__default["default"].blueBright(config.output.locales))); | ||
console.info(); | ||
var localesPaths = config.output.locales.map(function (loc) { | ||
return config.output.flat ? path__default["default"].join(config.output.path, loc + ".po") : path__default["default"].join(config.output.path, loc + "/app.po"); | ||
return config.output.flat ? path__default["default"].join(config.output.path, "".concat(loc, ".po")) : path__default["default"].join(config.output.path, "".concat(loc, "/app.po")); | ||
}); | ||
@@ -164,3 +164,3 @@ (function () { return tslib.__awaiter(void 0, void 0, void 0, function () { | ||
jsonRes = _b.apply(_a, [_c.sent()]); | ||
console.info(chalk__default["default"].green("Compiled json") + ": " + chalk__default["default"].grey(jsonRes)); | ||
console.info("".concat(chalk__default["default"].green("Compiled json"), ": ").concat(chalk__default["default"].grey(jsonRes))); | ||
return [4 /*yield*/, fsPromises__default["default"].writeFile(outputPath, jsonRes)]; | ||
@@ -170,3 +170,3 @@ case 3: | ||
console.info(); | ||
console.info(chalk__default["default"].green("Created") + ": " + chalk__default["default"].blueBright(outputPath)); | ||
console.info("".concat(chalk__default["default"].green("Created"), ": ").concat(chalk__default["default"].blueBright(outputPath))); | ||
return [2 /*return*/]; | ||
@@ -173,0 +173,0 @@ } |
@@ -30,3 +30,3 @@ #!/usr/bin/env node | ||
var explorer = cosmiconfig.cosmiconfigSync(moduleName, { | ||
searchPlaces: [moduleName + ".config.js", moduleName + ".config.json"], | ||
searchPlaces: ["".concat(moduleName, ".config.js"), "".concat(moduleName, ".config.json")], | ||
}); | ||
@@ -37,3 +37,3 @@ var configRes; | ||
if (!configRes) { | ||
throw new Error("Config not found: " + cliArgs.config); | ||
throw new Error("Config not found: ".concat(cliArgs.config)); | ||
} | ||
@@ -217,3 +217,3 @@ } | ||
extr.savePotFile(potPath); | ||
console.info(chalk__default["default"].green("Extraction successful") + ", " + chalk__default["default"].blueBright(potPath) + " created."); | ||
console.info("".concat(chalk__default["default"].green("Extraction successful"), ", ").concat(chalk__default["default"].blueBright(potPath), " created.")); | ||
extr.printStats(); | ||
@@ -265,3 +265,3 @@ return [2 /*return*/]; | ||
var searchPath = path__default["default"].join(config.input.path, pattern); | ||
console.info("Searching: " + chalk__default["default"].blueBright(searchPath)); | ||
console.info("Searching: ".concat(chalk__default["default"].blueBright(searchPath))); | ||
return globPromise(searchPath); | ||
@@ -273,3 +273,3 @@ }))]; | ||
var searchPath = path__default["default"].join(config.input.path, pattern); | ||
console.info("Excluding: " + chalk__default["default"].blueBright(searchPath)); | ||
console.info("Excluding: ".concat(chalk__default["default"].blueBright(searchPath))); | ||
return globPromise(searchPath); | ||
@@ -291,6 +291,6 @@ }))]; | ||
}); }; | ||
console.info("Input directory: " + chalk__default["default"].blueBright(config.input.path)); | ||
console.info("Output directory: " + chalk__default["default"].blueBright(config.output.path)); | ||
console.info("Output POT file: " + chalk__default["default"].blueBright(config.output.potPath)); | ||
console.info("Locales: " + chalk__default["default"].blueBright(config.output.locales)); | ||
console.info("Input directory: ".concat(chalk__default["default"].blueBright(config.input.path))); | ||
console.info("Output directory: ".concat(chalk__default["default"].blueBright(config.output.path))); | ||
console.info("Output POT file: ".concat(chalk__default["default"].blueBright(config.output.potPath))); | ||
console.info("Locales: ".concat(chalk__default["default"].blueBright(config.output.locales))); | ||
console.info(); | ||
@@ -316,19 +316,19 @@ (function () { return tslib.__awaiter(void 0, void 0, void 0, function () { | ||
poDir = config.output.flat ? config.output.path : path__default["default"].join(config.output.path, loc); | ||
poFile = config.output.flat ? path__default["default"].join(poDir, loc + ".po") : path__default["default"].join(poDir, "app.po"); | ||
poFile = config.output.flat ? path__default["default"].join(poDir, "".concat(loc, ".po")) : path__default["default"].join(poDir, "app.po"); | ||
fs__default["default"].mkdirSync(poDir, { recursive: true }); | ||
isFile = fs__default["default"].existsSync(poFile) && fs__default["default"].lstatSync(poFile).isFile(); | ||
if (!isFile) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, execShellCommand("msgmerge --lang=" + loc + " --update " + poFile + " " + config.output.potPath + " --backup=off")]; | ||
return [4 /*yield*/, execShellCommand("msgmerge --lang=".concat(loc, " --update ").concat(poFile, " ").concat(config.output.potPath, " --backup=off"))]; | ||
case 4: | ||
_b.sent(); | ||
console.info(chalk__default["default"].green("Merged") + ": " + chalk__default["default"].blueBright(poFile)); | ||
console.info("".concat(chalk__default["default"].green("Merged"), ": ").concat(chalk__default["default"].blueBright(poFile))); | ||
return [3 /*break*/, 8]; | ||
case 5: return [4 /*yield*/, execShellCommand("msginit --no-translator --locale=" + loc + " --input=" + config.output.potPath + " --output-file=" + poFile)]; | ||
case 5: return [4 /*yield*/, execShellCommand("msginit --no-translator --locale=".concat(loc, " --input=").concat(config.output.potPath, " --output-file=").concat(poFile))]; | ||
case 6: | ||
_b.sent(); | ||
fs__default["default"].chmodSync(poFile, 438); | ||
return [4 /*yield*/, execShellCommand("msgattrib --no-wrap --no-obsolete -o " + poFile + " " + poFile)]; | ||
return [4 /*yield*/, execShellCommand("msgattrib --no-wrap --no-obsolete -o ".concat(poFile, " ").concat(poFile))]; | ||
case 7: | ||
_b.sent(); | ||
console.info(chalk__default["default"].green("Created") + ": " + chalk__default["default"].blueBright(poFile)); | ||
console.info("".concat(chalk__default["default"].green("Created"), ": ").concat(chalk__default["default"].blueBright(poFile))); | ||
_b.label = 8; | ||
@@ -343,3 +343,3 @@ case 8: | ||
console.info(); | ||
console.info(chalk__default["default"].green("Created") + ": " + chalk__default["default"].blueBright(linguasPath)); | ||
console.info("".concat(chalk__default["default"].green("Created"), ": ").concat(chalk__default["default"].blueBright(linguasPath))); | ||
} | ||
@@ -346,0 +346,0 @@ return [2 /*return*/]; |
@@ -68,3 +68,3 @@ 'use strict'; | ||
if (!silent && MUSTACHE_SYNTAX_RE.test(msgid)) { | ||
console.warn("Mustache syntax cannot be used with vue-gettext. Please use \"%{}\" instead of \"{{}}\" in: " + msgid); | ||
console.warn("Mustache syntax cannot be used with vue-gettext. Please use \"%{}\" instead of \"{{}}\" in: ".concat(msgid)); | ||
} | ||
@@ -102,3 +102,3 @@ var result = msgid.replace(INTERPOLATION_RE, function (_match, token) { | ||
else { | ||
console.warn("Cannot evaluate expression: " + expression); | ||
console.warn("Cannot evaluate expression: ".concat(expression)); | ||
evaluated = expression; | ||
@@ -276,3 +276,3 @@ } | ||
*/ | ||
getTranslation: function (msgid, n, context, defaultPlural, languageKey) { | ||
getTranslation: function (msgid, n, context, defaultPlural, languageKey, parameters) { | ||
if (n === void 0) { n = 1; } | ||
@@ -284,2 +284,5 @@ if (context === void 0) { context = null; } | ||
} | ||
var interp = function (message, parameters) { | ||
return parameters ? language.interpolate(message, parameters) : message; | ||
}; | ||
if (!msgid) { | ||
@@ -301,5 +304,5 @@ return ""; // Allow empty strings. | ||
if (!silent) { | ||
console.warn("No translations found for " + languageKey); | ||
console.warn("No translations found for ".concat(languageKey)); | ||
} | ||
return untranslated; | ||
return interp(untranslated, parameters); | ||
} | ||
@@ -314,9 +317,9 @@ // spacing needs to be consistent even if a web template designer adds spaces between lines | ||
if (!silent) { | ||
var msg = "Untranslated " + languageKey + " key found: " + msgid; | ||
var msg = "Untranslated ".concat(languageKey, " key found: ").concat(msgid); | ||
if (context) { | ||
msg += " (with context: " + context + ")"; | ||
msg += " (with context: ".concat(context, ")"); | ||
} | ||
console.warn(msg); | ||
} | ||
return untranslated; | ||
return interp(untranslated, parameters); | ||
} | ||
@@ -329,3 +332,3 @@ // Avoid a crash when a msgid exists with and without a context, see #32. | ||
if (typeof translated === "string") { | ||
return translated; | ||
return interp(translated, parameters); | ||
} | ||
@@ -340,3 +343,3 @@ var translationIndex = plurals.getTranslationIndex(languageKey, n); | ||
} | ||
return translated[translationIndex]; | ||
return interp(translated[translationIndex], parameters); | ||
}, | ||
@@ -351,4 +354,4 @@ /* | ||
*/ | ||
gettext: function (msgid) { | ||
return this.getTranslation(msgid); | ||
gettext: function (msgid, parameters) { | ||
return this.getTranslation(msgid, undefined, undefined, undefined, undefined, parameters); | ||
}, | ||
@@ -364,4 +367,4 @@ /* | ||
*/ | ||
pgettext: function (context, msgid) { | ||
return this.getTranslation(msgid, 1, context); | ||
pgettext: function (context, msgid, parameters) { | ||
return this.getTranslation(msgid, 1, context, undefined, undefined, parameters); | ||
}, | ||
@@ -379,4 +382,4 @@ /* | ||
*/ | ||
ngettext: function (msgid, plural, n) { | ||
return this.getTranslation(msgid, n, null, plural); | ||
ngettext: function (msgid, plural, n, parameters) { | ||
return this.getTranslation(msgid, n, null, plural, undefined, parameters); | ||
}, | ||
@@ -395,4 +398,4 @@ /* | ||
*/ | ||
npgettext: function (context, msgid, plural, n) { | ||
return this.getTranslation(msgid, n, context, plural); | ||
npgettext: function (context, msgid, plural, n, parameters) { | ||
return this.getTranslation(msgid, n, context, plural, undefined, parameters); | ||
}, | ||
@@ -431,5 +434,6 @@ }); }; | ||
* Translate content according to the current language. | ||
* @deprecated | ||
*/ | ||
var Component = vue.defineComponent({ | ||
// eslint-disable-next-line vue/component-definition-name-casing | ||
// eslint-disable-next-line vue/multi-word-component-names, vue/component-definition-name-casing | ||
name: "translate", | ||
@@ -468,3 +472,3 @@ props: { | ||
if (!isPlural && (props.translateN || props.translatePlural)) { | ||
throw new Error("`translate-n` and `translate-plural` attributes must be used together: " + ((_c = (_b = (_a = context.slots).default) === null || _b === void 0 ? void 0 : _b.call(_a)[0]) === null || _c === void 0 ? void 0 : _c.children) + "."); | ||
throw new Error("`translate-n` and `translate-plural` attributes must be used together: ".concat((_c = (_b = (_a = context.slots).default) === null || _b === void 0 ? void 0 : _b.call(_a)[0]) === null || _c === void 0 ? void 0 : _c.children, ".")); | ||
} | ||
@@ -506,3 +510,3 @@ var root = vue.ref(); | ||
if (!language.silent && attrs["translate-params"]) { | ||
console.warn("`translate-params` is required as an expression for v-translate directive. Please change to `v-translate='params'`: " + msgid); | ||
console.warn("`translate-params` is required as an expression for v-translate directive. Please change to `v-translate='params'`: ".concat(msgid)); | ||
} | ||
@@ -528,2 +532,3 @@ var translation = translate(language).getTranslation(msgid, translateN, translateContext, isPlural ? translatePlural : null, language.current); | ||
* `<p v-translate="fullName + location">I am %{ fullName } and from %{ location }</p>` | ||
* @deprecated | ||
*/ | ||
@@ -568,3 +573,3 @@ function directive(language) { | ||
if (Object.keys(defaultOptions).indexOf(key) === -1) { | ||
throw new Error(key + " is an invalid option for the translate plugin."); | ||
throw new Error("".concat(key, " is an invalid option for the translate plugin.")); | ||
} | ||
@@ -604,3 +609,3 @@ }); | ||
if (mergedOptions.provideComponent) { | ||
// eslint-disable-next-line vue/component-definition-name-casing | ||
// eslint-disable-next-line vue/multi-word-component-names, vue/component-definition-name-casing | ||
app.component("translate", Component); | ||
@@ -607,0 +612,0 @@ } |
@@ -6,2 +6,3 @@ import * as vue from 'vue'; | ||
* Translate content according to the current language. | ||
* @deprecated | ||
*/ | ||
@@ -35,10 +36,28 @@ declare const Component: vue.DefineComponent<{ | ||
[key: string]: any; | ||
}>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, Record<string, any>, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<{ | ||
tag?: unknown; | ||
translateN?: unknown; | ||
translatePlural?: unknown; | ||
translateContext?: unknown; | ||
translateParams?: unknown; | ||
translateComment?: unknown; | ||
} & { | ||
}>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, Record<string, any>, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{ | ||
tag: { | ||
type: StringConstructor; | ||
default: string; | ||
}; | ||
translateN: { | ||
type: NumberConstructor; | ||
default: null; | ||
}; | ||
translatePlural: { | ||
type: StringConstructor; | ||
default: null; | ||
}; | ||
translateContext: { | ||
type: StringConstructor; | ||
default: null; | ||
}; | ||
translateParams: { | ||
type: ObjectConstructor; | ||
default: null; | ||
}; | ||
translateComment: { | ||
type: StringConstructor; | ||
default: null; | ||
}; | ||
}>>, { | ||
tag: string; | ||
@@ -50,9 +69,2 @@ translateN: number; | ||
translateComment: string; | ||
} & {}>, { | ||
tag: string; | ||
translateN: number; | ||
translatePlural: string; | ||
translateContext: string; | ||
translateParams: Record<string, any>; | ||
translateComment: string; | ||
}>; | ||
@@ -74,2 +86,3 @@ | ||
* `<p v-translate="fullName + location">I am %{ fullName } and from %{ location }</p>` | ||
* @deprecated | ||
*/ | ||
@@ -108,6 +121,14 @@ declare function directive(language: Language): ObjectDirective<HTMLElement, any>; | ||
current: string; | ||
$gettext: (msgid: string) => string; | ||
$pgettext: (context: string, msgid: string) => string; | ||
$ngettext: (msgid: string, plural: string, n: number) => string; | ||
$npgettext: (context: string, msgid: string, plural: string, n: number) => string; | ||
$gettext: (msgid: string, parameters?: { | ||
[key: string]: string; | ||
}) => string; | ||
$pgettext: (context: string, msgid: string, parameters?: { | ||
[key: string]: string; | ||
}) => string; | ||
$ngettext: (msgid: string, plural: string, n: number, parameters?: { | ||
[key: string]: string; | ||
}) => string; | ||
$npgettext: (context: string, msgid: string, plural: string, n: number, parameters?: { | ||
[key: string]: string; | ||
}) => string; | ||
interpolate: (msgid: string, context: object, disableHtmlEscaping?: boolean) => string; | ||
@@ -160,14 +181,16 @@ install: (app: App) => void; | ||
silent: boolean; | ||
translations: { | ||
[x: string]: { | ||
[x: string]: Message | { | ||
[x: string]: Message; | ||
}; | ||
}; | ||
}; | ||
translations: Translations; | ||
current: string; | ||
$gettext: (msgid: string) => string; | ||
$pgettext: (context: string, msgid: string) => string; | ||
$ngettext: (msgid: string, plural: string, n: number) => string; | ||
$npgettext: (context: string, msgid: string, plural: string, n: number) => string; | ||
$gettext: (msgid: string, parameters?: { | ||
[key: string]: string; | ||
} | undefined) => string; | ||
$pgettext: (context: string, msgid: string, parameters?: { | ||
[key: string]: string; | ||
} | undefined) => string; | ||
$ngettext: (msgid: string, plural: string, n: number, parameters?: { | ||
[key: string]: string; | ||
} | undefined) => string; | ||
$npgettext: (context: string, msgid: string, plural: string, n: number, parameters?: { | ||
[key: string]: string; | ||
} | undefined) => string; | ||
interpolate: (msgid: string, context: object, disableHtmlEscaping?: boolean | undefined) => string; | ||
@@ -221,10 +244,28 @@ install: (app: App<any>) => void; | ||
[key: string]: any; | ||
}>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, Record<string, any>, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<{ | ||
tag?: unknown; | ||
translateN?: unknown; | ||
translatePlural?: unknown; | ||
translateContext?: unknown; | ||
translateParams?: unknown; | ||
translateComment?: unknown; | ||
} & { | ||
}>, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, Record<string, any>, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{ | ||
tag: { | ||
type: StringConstructor; | ||
default: string; | ||
}; | ||
translateN: { | ||
type: NumberConstructor; | ||
default: null; | ||
}; | ||
translatePlural: { | ||
type: StringConstructor; | ||
default: null; | ||
}; | ||
translateContext: { | ||
type: StringConstructor; | ||
default: null; | ||
}; | ||
translateParams: { | ||
type: ObjectConstructor; | ||
default: null; | ||
}; | ||
translateComment: { | ||
type: StringConstructor; | ||
default: null; | ||
}; | ||
}>>, { | ||
tag: string; | ||
@@ -236,9 +277,2 @@ translateN: number; | ||
translateComment: string; | ||
} & {}>, { | ||
tag: string; | ||
translateN: number; | ||
translatePlural: string; | ||
translateContext: string; | ||
translateParams: Record<string, any>; | ||
translateComment: string; | ||
}>; | ||
@@ -245,0 +279,0 @@ }; |
{ | ||
"name": "vue3-gettext", | ||
"version": "2.0.0-alpha.3", | ||
"version": "2.0.0-beta.1", | ||
"description": "Translate your Vue.js 3 applications with gettext", | ||
@@ -35,3 +35,3 @@ "author": "Leo Zurbriggen", | ||
"engines": { | ||
"node": ">= 10.0.0" | ||
"node": ">= 12.0.0" | ||
}, | ||
@@ -44,38 +44,37 @@ "peerDependencies": { | ||
"chalk": "^4.1.2", | ||
"command-line-args": "^5.2.0", | ||
"command-line-args": "^5.2.1", | ||
"cosmiconfig": "^7.0.1", | ||
"gettext-extractor": "^3.5.3", | ||
"glob": "^7.2.0", | ||
"pofile": "^1.1.1" | ||
"pofile": "^1.1.3" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.6", | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
"@rollup/plugin-typescript": "^8.3.0", | ||
"@types/command-line-args": "^5.2.0", | ||
"@types/glob": "^7.2.0", | ||
"@types/jest": "^27.0.2", | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^16.11.1", | ||
"@typescript-eslint/parser": "^5.0.0", | ||
"@vitejs/plugin-vue": "^1.9.4", | ||
"@typescript-eslint/parser": "^5.10.2", | ||
"@vitejs/plugin-vue": "^2.1.0", | ||
"@vue/test-utils": "^2.0.0-rc.16", | ||
"@vuepress/bundler-vite": "^2.0.0-beta.27", | ||
"@vuepress/plugin-search": "^2.0.0-beta.27", | ||
"date-fns": "^2.25.0", | ||
"eslint": "^8.1.0", | ||
"date-fns": "^2.28.0", | ||
"eslint": "^8.8.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-vue": "^7.20.0", | ||
"jest": "^27.3.1", | ||
"eslint-plugin-vue": "^8.4.0", | ||
"jest": "^27.4.7", | ||
"json-loader": "^0.5.7", | ||
"markdown-it-fence": "^0.1.3", | ||
"prettier": "^2.4.1", | ||
"rollup": "^2.58.3", | ||
"rollup-plugin-dts": "^4.0.0", | ||
"prettier": "^2.5.1", | ||
"rollup": "^2.67.0", | ||
"rollup-plugin-dts": "^4.1.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"ts-jest": "^27.0.7", | ||
"ts-jest": "^27.1.3", | ||
"ts-node": "^10.4.0", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.4.4", | ||
"vite": "^2.6.13", | ||
"vue": "^3.2.20", | ||
"typescript": "^4.5.5", | ||
"vite": "^2.7.13", | ||
"vue": "^3.2.29", | ||
"vue-live": "^2.0.0-beta.2", | ||
@@ -82,0 +81,0 @@ "vuepress": "^2.0.0-beta.27" |
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
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
90728
30
1958
Updatedcommand-line-args@^5.2.1
Updatedpofile@^1.1.3