<commit_before>package me.echeung.moemoekyun.utils;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.util.Log;

import java.util.Locale;

import me.echeung.moemoekyun.App;

// https://proandroiddev.com/change-language-programmatically-at-runtime-on-android-5e6bc15c758
public class LocaleUtil {

    protected static final String DEFAULT = "default";

    public static Context setLocale(@NonNull Context context) {
        if (App.getPreferenceUtil() == null) {
            return context;
        }

        final String language = App.getPreferenceUtil().getLanguage();
        return setLocale(context, language);
    }

    public static Context setLocale(@NonNull Context context, String language) {
        final Resources res = context.getResources();
        final Configuration config = new Configuration(res.getConfiguration());

        if (!language.equals(DEFAULT)) {
            final Locale locale = new Locale(language);
            Locale.setDefault(locale);
            config.setLocale(locale);<commit_msg>Fix setting for regionalized locales<commit_after>package me.echeung.moemoekyun.utils;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.util.Log;

import java.util.Locale;

import me.echeung.moemoekyun.App;

// https://proandroiddev.com/change-language-programmatically-at-runtime-on-android-5e6bc15c758
public class LocaleUtil {

    protected static final String DEFAULT = "default";

    public static Context setLocale(@NonNull Context context) {
        if (App.getPreferenceUtil() == null) {
            return context;
        }

        final String language = App.getPreferenceUtil().getLanguage();
        return setLocale(context, language);
    }

    public static Context setLocale(@NonNull Context context, String language) {
        final Resources res = context.getResources();
        final Configuration config = new Configuration(res.getConfiguration());

        if (!language.equals(DEFAULT)) {
            Locale locale;
            if (language.contains("-r")) {
                String[] languageParts = language.split("-r");
                locale = new Locale(languageParts[0], languageParts[1]);
            } else {
                locale = new Locale(language);
            }
            Locale.setDefault(locale);
            config.setLocale(locale);
{'fraction_non_alphanumeric': 0.10174526550315634, 'fraction_numerical': 0.005941329372447085, 'mean_word_length': 3.2425196850393703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3018127', 'n_tokens_mistral': 715, 'n_tokens_neox': 694, 'n_words': 161}