2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 23:00:56 +00:00

fix: minor changes and use T when class required

This commit is contained in:
18alantom 2022-01-20 14:33:41 +05:30 committed by Alan
parent 5d9b2d66bb
commit 6cb08940ea
2 changed files with 25 additions and 10 deletions

View File

@ -1,5 +1,5 @@
const { pesa } = require('pesa');
const { T } = require('./translation');
const { T, t } = require('./translation');
Array.prototype.equals = function (array) {
return (
@ -55,7 +55,9 @@ function asyncHandler(fn) {
* @param {Number} n
*/
function range(n) {
return Array.from(Array(4)).map((d, i) => i);
return Array(n)
.fill()
.map((_, i) => i);
}
function unique(list, key = (it) => it) {
@ -86,7 +88,8 @@ function isPesa(value) {
}
module.exports = {
_: T,
_: t,
t,
T,
slug,
getRandomString,

View File

@ -1,3 +1,5 @@
import { ValueError } from '../common/errors';
function stringReplace(str, args) {
if (!Array.isArray(args)) {
args = [args];
@ -32,13 +34,23 @@ class TranslationString {
}
#translate(segment) {
if (this.context) {
// do something
}
// TODO: implement translation backend
return segment;
}
#stitch() {
if (typeof this.args[0] === 'string') {
return stringReplace(this.args[0], this.args.slice(1));
}
if (!(this.args[0] instanceof Array)) {
throw new ValueError(
`invalid args passed to TranslationString ${
this.args
} of type ${typeof this.args[0]}`
);
}
const strList = this.args[0];
const argList = this.args.slice(1);
return strList
@ -60,9 +72,9 @@ class TranslationString {
}
export function T(...args) {
if (typeof args[0] === 'string') {
return stringReplace(args[0], args.slice(1));
}
return new TranslationString(...args);
}
export function t(...args) {
return new TranslationString(...args).s;
}