Refactor setLocale