A method to transform a nonlocal model into a gradient one within elasticity and plasticity