Macroscopic and microscopic kinetics of hydrogen in magnesium-rich compounds