|
@@ -74,9 +74,10 @@ class Lang {
|
|
|
args.forEach( (arg, i) => {
|
|
|
text = text.replaceSave( new RegExp( `\\$${i + 1}`, 'g' ), arg );
|
|
|
} );
|
|
|
- text = text.replace( /{{\s*GENDER:\s*([a-z]+)\s*\|\s*([^\{\}]*?)\s*}}/g, (m, type, cases) => {
|
|
|
+ if ( text.includes( 'GENDER:' ) ) text = text.replace( /{{\s*GENDER:\s*([a-z]+)\s*\|\s*([^\{\}]*?)\s*}}/g, (m, type, cases) => {
|
|
|
return gender(type, cases.split(/\s*\|\s*/));
|
|
|
- } ).replace( /{{\s*PLURAL:\s*[+-]?(\d+)\s*\|\s*([^\{\}]*?)\s*}}/g, (m, number, cases) => {
|
|
|
+ } );
|
|
|
+ if ( text.includes( 'PLURAL:' ) ) text = text.replace( /{{\s*PLURAL:\s*[+-]?(\d+)\s*\|\s*([^\{\}]*?)\s*}}/g, (m, number, cases) => {
|
|
|
return plural(lang, parseInt(number, 10), cases.split(/\s*\|\s*/));
|
|
|
} );
|
|
|
}
|
|
@@ -106,9 +107,10 @@ class Lang {
|
|
|
// args.forEach( (arg, i) => {
|
|
|
// text = text.replaceSave( new RegExp( `\\$${i + 1}`, 'g' ), arg );
|
|
|
// } );
|
|
|
-// text = text.replace( /{{\s*GENDER:\s*([a-z]+)\s*\|\s*([^\{\}]*?)\s*}}/g, (m, type, cases) => {
|
|
|
+// if ( text.includes( 'GENDER:' ) ) text = text.replace( /{{\s*GENDER:\s*([a-z]+)\s*\|\s*([^\{\}]*?)\s*}}/g, (m, type, cases) => {
|
|
|
// return gender(type, cases.split(/\s*\|\s*/));
|
|
|
-// } ).replace( /{{\s*PLURAL:\s*[+-]?(\d+)\s*\|\s*([^\{\}]*?)\s*}}/g, (m, number, cases) => {
|
|
|
+// } );
|
|
|
+// if ( text.includes( 'PLURAL:' ) ) text = text.replace( /{{\s*PLURAL:\s*[+-]?(\d+)\s*\|\s*([^\{\}]*?)\s*}}/g, (m, number, cases) => {
|
|
|
// return plural(lang, parseInt(number, 10), cases.split(/\s*\|\s*/));
|
|
|
// } );
|
|
|
// }
|
|
@@ -127,6 +129,28 @@ class Lang {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Parse gender text.
|
|
|
+ * @param {String} gender - The gender.
|
|
|
+ * @param {String[]} args - The possible text.
|
|
|
+ * @returns {String}
|
|
|
+ */
|
|
|
+function gender(gender, args) {
|
|
|
+ var text = args[0];
|
|
|
+ switch ( gender ) {
|
|
|
+ case 'male':
|
|
|
+ if ( args.length > 0 ) text = args[0];
|
|
|
+ break;
|
|
|
+ case 'female':
|
|
|
+ if ( args.length > 1 ) text = args[1];
|
|
|
+ break;
|
|
|
+ case 'unknown':
|
|
|
+ default:
|
|
|
+ if ( args.length > 2 ) text = args[2];
|
|
|
+ }
|
|
|
+ return text;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Parse plural text.
|
|
|
* @param {String} lang - The language code.
|
|
@@ -188,26 +212,4 @@ function getArg(args, index) {
|
|
|
return ( args.length > index ? args[index] : args[args.length - 1] );
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Parse gender text.
|
|
|
- * @param {String} gender - The gender.
|
|
|
- * @param {String[]} args - The possible text.
|
|
|
- * @returns {String}
|
|
|
- */
|
|
|
-function gender(gender, args) {
|
|
|
- var text = args[0];
|
|
|
- switch ( gender ) {
|
|
|
- case 'male':
|
|
|
- if ( args.length > 0 ) text = args[0];
|
|
|
- break;
|
|
|
- case 'female':
|
|
|
- if ( args.length > 1 ) text = args[1];
|
|
|
- break;
|
|
|
- case 'unknown':
|
|
|
- default:
|
|
|
- if ( args.length > 2 ) text = args[2];
|
|
|
- }
|
|
|
- return text;
|
|
|
-}
|
|
|
-
|
|
|
module.exports = Lang;
|