mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2024-04-21 12:32:08 +00:00
23 lines
729 B
JavaScript
23 lines
729 B
JavaScript
export function t(str = "", replacementString, requestedKey) {
|
|
const calculatedKey = str.toUpperCase()
|
|
.replace(/ /g, "_")
|
|
.replace(/[^a-zA-Z0-9\-\_\*\{\}\?]/g, "")
|
|
.replace(/\_+$/, "");
|
|
const value = requestedKey === undefined ?
|
|
window.LNG && window.LNG[calculatedKey] :
|
|
window.LNG && window.LNG[requestedKey];
|
|
return reformat(
|
|
value || str || "",
|
|
str,
|
|
).replace("{{VALUE}}", replacementString);
|
|
}
|
|
|
|
function reformat(translated, initial) {
|
|
if (initial[0] && initial[0].toLowerCase() === initial[0]) {
|
|
return translated || "";
|
|
}
|
|
return (translated[0] && translated[0].toUpperCase() + translated.substring(1)) || "";
|
|
}
|
|
|
|
export default t;
|