Files
mixtape/zero.Web/App/Directives/localize.js
T

31 lines
829 B
JavaScript
Raw Normal View History

2020-04-06 13:24:46 +02:00
import Vue from 'vue';
import Localization from 'zeroservices/localization';
/// <summary>
/// Localizes the given property and sets the inner-text of the node to its result
/// </summary>
Vue.directive('localize', (el, binding) =>
{
if (binding.value !== binding.oldValue)
2020-04-06 13:24:46 +02:00
{
const isObject = typeof binding.value === 'object';
let key = isObject ? binding.value.key : binding.value;
let options = isObject ? binding.value : null;
2020-04-06 13:24:46 +02:00
2020-04-09 19:35:57 +02:00
// set content as html
if (binding.arg === 'html')
{
el.innerHTML = Localization.localize(key, options);
}
2020-04-08 15:16:05 +02:00
// set attribute
2020-04-09 19:35:57 +02:00
else if (binding.arg)
2020-04-08 15:16:05 +02:00
{
el.setAttribute(binding.arg, Localization.localize(key, options));
}
2020-04-09 19:35:57 +02:00
// set content as plain text
2020-04-08 15:16:05 +02:00
else
{
el.innerText = Localization.localize(key, options);
}
2020-04-06 13:24:46 +02:00
}
});