What is the grammar behind using:
- It took me 2 years to learn 'X' (to cook/read/write) rather than
- It took me to learn 'X' 2 years
Because your rewrite makes no sense at all. What does it take? It takes time. It does not take "to learn". That's not the object of take. The two years is the object of take. You can’t jumble up the parts of the verb phrase this way.
The object of transitive take in this sense is a measure phrase representing time spent. But it can also be other sorts of complements.
You are not allowed to interpose other words to interfere with interpreting the ordering of a verb’s core arguments, here specifically VERB INDIRECT-OBJECT DIRECT-OBJECT. You have lost the direct object altogether! The object of take is the measure phrase. It doesn't take you learning French two years from now to see this either. :)
The OED gives this sense, with which I include one of their many citations:
b. transitive. With preposition, adverb, or adverbial phrase: to bring to a specified state or non-physical position; to raise or lower in degree, intensity, or status; to advance or put back.
- 2001 Sugar Feb. 61
It takes time to find the right boy, so don’t despair if your crush doesn’t want to take things further.
When there are two complements, the first is sometimes accounted an indirect object or dative of person. It no longer has a special dative inflection as it did originally.
The reason your example has it out front is simple it-extraposition as occurs so often in English.
Those are all syntactically well-formed and semantically equivalent. What you wrote, however, is neither.
By the way, you should not use numeric shortcuts like 2 years in normal English prose. You should write out the figure as words: two years. This rule does not apply in charts or tables or science reports with specific quantities, or even recipes with differing measurements called for.
But to do so in English prose looks slipshod and sloppy, even disrespectful of the established standards of written English.
So do please take the time to type it out fully. Do not under any circumstances attempt to take to type it out fully the time. :)