I'm living in a country which language I have been learning for less
than 5 months.
The preceding sentence is certainly ungrammatical. Your proposed correction is right:
I'm living in a country whose language I have been learning for less
than 5 months.
If the sentence must be formulated without whose, I think it would be grammatical to use one of the following structures:
I'm living in a country the language of which I have been learning for less than 5 months.
(but, some linguists have claimed sentences of this type are not allowed. See discussion in section on pied-piping)
I'm living in a country of which I have been learning the language for less than 5 months.
I'm living in a country which/that/__ I have been learning the language of for less than 5 months.†
But even though sentences 3-5 are all grammatical, they're arguably all stylistically worse than sentence 2. There's really nothing wrong with whose here. It's often considered fully acceptable in contexts like this even by grammatical prescriptivists.*
The "which policies" example: "which" as a relative determiner
The following sentence has quite a different structure:
Schedule 3.23 sets forth list and description of all insurance
policies currently owned by the Company relating to the Development
Work or the assets of the Company, which policies are in full force
and effect, and the Company is not in default under any of them.
Here, you can see that the relative clause refers back to "policies"; this word is repeated after "which", probably to avoid confusion about the referent which is quite far back and separated from "which" by several intervening noun phrases. So "which" here serves as a determiner, rather than as a pronoun. This use of "which" as a determiner with a repeated noun phrase is rare outside of legal documents, but not ungrammatical. When which is a determiner, it can only be used in non-integrated relative clauses (the kind set of with commas); see StoneyB's answer to the following ELL question: “which” as relative determiner? (which also mentions another, more common use of determiner-which: it can be used with a preceding preposition and a following noun like "point" or "case" that "refers to the entire head clause or to some implicit aspect of that clause’s content").
So sentence 1 cannot be using the same structure as sentence 5. It is different on two counts: it lacks co-reference ("country" and "language" do not refer to the same thing) and it is a restrictive or integrated relative clause rather than a non-integrated relative clause.
A sentence where "which language I have been learning for less than 5 months" would be grammatical (although it probably would still sound awkward) is the following:
I spoke to them in the language of the country where I am living, which language I have been learning for less than 5 months.
A brief discussion of pied-piping
Wh-words in English often show “movement” to the front of their clause. (It’s actually debated in linguistics what the exact process is, but for simplicity let’s stick with “movement”.) This is called, naturally enough, “fronting”.
Sometimes, another word moves with the wh-word. (For this to happen, the two words have to be in the same phrase.) This is called “pied-piping”: the idea is that the wh-word leads the other word like the Pied Piper of Hamelin led rats and children.
The sentences discussed above show several examples of different kinds of pied-piping.
Obligatory Pied Piping due to an "Island Effect"
I'm living in a country whose language I have been learning for less than 5 months.
If we split this sentence into two independent clauses, we would have something like “I'm living in a country, and I have been learning its language for less than 5 months.” So it seems the relative possessive determiner “whose” has been moved to the front of its clause, and has taken the associated noun “language” with it. In this case, pied piping is mandatory—for some reason, we can’t say “I'm living in a country whose I have been learning language for less than 5 months.” (Apparently, the preceding sentence is unacceptable due to an “island effect”; see “Wh- movement in English” from The syntax of natural language: An online introduction using the Trees program by Beatrice Santorini and Anthony Kroch. Island effects seem to be a currently active object of study in syntax and there doesn't seem to be a consensus on whether they are rules of grammar, strictly speaking, or just caused by processing constraints).
"Massive Pied Piping": so awkward it's been (mistakenly, I think) called "completely disallowed" in restrictive relative clauses!
I'm living in a country the language of which I have been learning for less than 5 months.
Sentence 3 shows pied-piping of the preposition "of" and the noun phrase "the language" along with the relative pronoun "which". This sounds acceptable to me, but I did find a paper by a linguist that states that
pied-piping of NP by its complement is completely disallowed in restrictive relative
clauses (26a), but is rather more acceptable in appositive relatives (26b).
(26) a. * I don’t want to see any boy [ [ pictures of whom ] you bought on the internet ].
b. ? I don’t want to see Dave, [ [ pictures of whom ] you bought on the internet"
(“Pied-Piping: Comparing Two Recent Approaches”, Seth Cable 2011)
I think Cable is wrong when he says NP pied piping like this is "completely disallowed" in restrictive relative clauses (and apparently, so would the 5 people who upvoted my answer without commenting to say that sentence 3 is unacceptable). Another example can be found in Jon Purdy's comment on the following page: "Using "who" for things (nonliving beings)"
"Whose" is used in these situations because "words in which the first
letter originates" or "words the first letter of which originates" are
both somewhat stilted.
I agree with Purdy's judgement, but I think this supports my disagreement with Cable: "somewhat stilted" is a pretty long ways off from "completely disallowed". Cable's specific example may be disallowed, but I think it must be for some more specific reason.
Prepositional Phrase Pied Piping: puts the relevant words far apart
I'm living in a country of which I have been learning the language for less than 5 months.
Sentence 4 shows that the pied-piping of the noun phrase, even if possible, is definitely not mandatory: it is possible for it to stay in place. In fact, the pied-piping of the preposition "of" is also optional, although certain prescriptivists would incorrectly say it is required†.
Lack of Prepositional Phrase Pied Piping: grammatical, but it'll annoy some prescriptivists who think it isn't!
I'm living in a country which I have been learning the language of for less than 5 months.
Sentence 5 has no pied-piping at all; the only thing fronted is the relative pronoun "which". It would be possible in this sentence to use the relativiser "that" instead, or no explicit relativizer at all. (In fact, many would prefer "that" over "which".†)
*H.W. Fowler said in his Dictionary of Modern English Usage (1926):
In the starch that stiffens English style, one of the most effective ingredients is the rule that whose shall refer only to persons [...]
Let us, in the name of common sense, prohibit the prohibition of whose inanimate; good writing is surely difficult enough without the forbidding of things that have historical grammar, & present intelligibility, & obvious convenience, on their side & lack only—starch.
†If you think sentence 5 is ungrammatical because it has a "stranded preposition", see this Language Log article: "Hot Dryden-on-Jonson Action". If you think the version of sentence 5 with "which" is ungrammatical because restrictive clauses must have "that", see this Language Log article: "A decline in which-hunting?" The idea that "which" is ungrammatical in this sort of sentence seems to have arisen from zealous misinterpretation of a style recommendation made by Fowler (among others; he wasn't the originator of the idea):
The two kinds of relative clause, to one of which that & to the other of which which is more appropriate, are the defining & the non-defining, & if the writers would agree to regard that as the defining relative pronoun, & which as the non-defining, there would be much gain in both lucidity & ease. Some there are who follow this principle now; but it would be idle to pretend that it is the practice either of most or of the best writers.