locale_gen: Support complex locale name

Alternative implementation of #8674.