JSFiddle - React, Tailwind, and code Playground

by kougiland

HTML

<script src="http://knockoutjs.com/downloads/knockout-2.2.1.js"></script>
<input type="text" data-bind="value: someValue"/>
<label data-bind="text: someValue"></label>

JavaScript

ko.extenders.translate = function(target, defaultValue) {
    var result = ko.computed({
        read: target,
        write: function(newValue) {
            if (!newValue) {
                target("leer");
            } 
            if (newValue == "Work") {
               target("Arbeit");
            } 
            if (newValue == "Medic"){
               target("Arzt");
            }
            if (newValue == "agency"){
               target("Behörde");
            }
            if (newValue == "Education"){
               target("Bildung");
            }
            if (newValue == "leisure"){
               target("Freizeit");
            }
            if (newValue == "court"){
               target("Gericht");
            }
            if (newValue == "Miscellaneous"){
               target("Sonstiges");
            }
        }
    });
    
    result(target());
    
    return result;
};

var viewModel = function() {
    this.someValue = ko.observable().extend({ translate: false });
};

ko.applyBindings(new viewModel());