Does insincere flattery get you want you want? I would think having the power and might of the United States in your back pocket would be more effective. I would also think none of those leaders would ever interpret it as flattery, and I'm convinced Trump didn't mean it to be. This was not anything like a mistake, which implies honest effort.
Trump may or may not have known English is the official language of Liberia—that's a debatable, and insignificant, proposition—but his condescending question was purposeful in his bigotry toward the “colored guy” and in the appeal of that to ardent true-believer MAGAs.
You may not be aware of this because you’re surrounded by highly-educated academics for whom pursuit of high knowledge is its own worthy goal, but from firsthand experience, I can confirm for you that among certain people of the working class, it is socially advantageous to overtly demonstrate to those around them that they don’t know things that are considered eggheaded, such as what the official language of any given African country is. If someone traveling with that group were to show they know such things, they would—they do—get suspicious looks and comments from the people they hang out with, and it would—it does—actually hurt their standing with the guys (and it’s almost always guys), because then they can't trust that the undercover egghead is one of them. So it’s best to show, actively and overtly, that they absolutely don’t know stuff like that. And the way I see it, since a large portion of Trump’s fan base is made up of certain people of the working class, that appears to be what he’s trying to accomplish here.
Trump doesn’t have to be a genius or well-educated to know that it’s advantageous for him to demonstrate his ignorance of that kind of thing. None of the guys I inexplicably tried to ingratiate myself with back in those dark days of my life were any smarter than Trump, and yet, they knew how to show ignorance of eggheaded things, even when I knew they knew such things. It's an integral part of getting approval from that crowd. And when Trump does this, at least that portion of his base swoon over it. This is an example of him knowing just what he’s doing in situations like this.