18034727885
2026-07-02 eb6124e310ae8875a0150ee5d2edd52d5a579d87
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.driver.igotrip.utils;
 
import android.content.Context;
import android.content.SharedPreferences;
 
public class LanguageSP {
    private static final String SP_NAME = "app_language";
    private static final String KEY_LANGUAGE = "current_language";
 
    // 保存当前选择的语言
    public static void saveLanguage(Context context, String language) {
        SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        sp.edit().putString(KEY_LANGUAGE, language).apply();
    }
 
    // 获取保存的语言(默认英文)
    public static String getLanguage(Context context) {
        SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        return sp.getString(KEY_LANGUAGE, LanguageConst.EN_US);
    }
 
    public static  class LanguageConst {
        // 中文(简体)
        public static final String ZH_CN = "zh-CN";
        // 英文(美国)
        public static final String EN_US = "en-US";
        // 法文(法国)
        public static final String FR_FR = "fr-FR";
    }
}