Any generator has to be rotated wid something to generate electricity this is called prime mover...in diesel generetor ...a diesel engine is there to rotate generator here diesel engin is acting like prime mover ....in diesel locomotives diesel generator generates AC current which in turn is converted to DC current to drive dc motors which we call it as traction motors...this is how a diesel locomotives work