fix bug #19855, unify locale loading code