mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
ESLINT: Addressed remaining detected issues
This commit is contained in:
@ -5,11 +5,7 @@
|
||||
*/
|
||||
class Translator {
|
||||
|
||||
/**
|
||||
* Create an instance, Passing in the required translations
|
||||
* @param translations
|
||||
*/
|
||||
constructor(translations) {
|
||||
constructor() {
|
||||
this.store = new Map();
|
||||
this.parseTranslations();
|
||||
}
|
||||
@ -27,7 +23,7 @@ class Translator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a translation, Same format as laravel's 'trans' helper
|
||||
* Get a translation, Same format as Laravel's 'trans' helper
|
||||
* @param key
|
||||
* @param replacements
|
||||
* @returns {*}
|
||||
@ -38,8 +34,8 @@ class Translator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pluralised text, Dependant on the given count.
|
||||
* Same format at laravel's 'trans_choice' helper.
|
||||
* Get pluralised text, Dependent on the given count.
|
||||
* Same format at Laravel's 'trans_choice' helper.
|
||||
* @param key
|
||||
* @param count
|
||||
* @param replacements
|
||||
@ -52,7 +48,7 @@ class Translator {
|
||||
|
||||
/**
|
||||
* Parse the given translation and find the correct plural option
|
||||
* to use. Similar format at laravel's 'trans_choice' helper.
|
||||
* to use. Similar format at Laravel's 'trans_choice' helper.
|
||||
* @param {String} translation
|
||||
* @param {Number} count
|
||||
* @param {Object} replacements
|
||||
@ -117,14 +113,17 @@ class Translator {
|
||||
*/
|
||||
performReplacements(string, replacements) {
|
||||
if (!replacements) return string;
|
||||
const replaceMatches = string.match(/:([\S]+)/g);
|
||||
const replaceMatches = string.match(/:(\S+)/g);
|
||||
if (replaceMatches === null) return string;
|
||||
let updatedString = string;
|
||||
|
||||
replaceMatches.forEach(match => {
|
||||
const key = match.substring(1);
|
||||
if (typeof replacements[key] === 'undefined') return;
|
||||
string = string.replace(match, replacements[key]);
|
||||
updatedString = updatedString.replace(match, replacements[key]);
|
||||
});
|
||||
return string;
|
||||
|
||||
return updatedString;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user