Files
mixtape/zero.Web/App/Services/localization.js
T
2020-04-06 13:29:34 +02:00

40 lines
567 B
JavaScript

export default {
cache: zero.translations,
localize(key, force)
{
if (!key)
{
return '';
}
const hasAtSign = key.indexOf('@') === 0;
if (!force && !hasAtSign)
{
return key;
}
key = hasAtSign ? key.slice(1) : key;
let value = this.cache;
for (let part of key.split('.'))
{
if (!value[part])
{
break;
}
value = value[part];
}
if (!value || value === this.cache || typeof value !== 'string')
{
return '[' + key + ']';
}
return value;
}
};