native获取语言环境,根据是否debug调试判断

This commit is contained in:
wkj 2024-07-02 15:47:26 +08:00
parent ce835e72a1
commit 92af3839f9
3 changed files with 9 additions and 4 deletions

View File

@ -2,7 +2,8 @@ import { Platform } from 'react-native';
import { getLocales } from 'react-native-localize';
import { getDeviceId } from 'react-native-device-info';
export async function getEnv() {
const language = getLocales()[0].languageTag;
const isDebuggingEnabled = typeof atob !== 'undefined';
const language = !isDebuggingEnabled ? getLocales()[0].languageTag : navigator.language;
const deviceId = getDeviceId();
const fullEnv = {
...Platform,
@ -13,7 +14,9 @@ export async function getEnv() {
const briefEnv = {
brand: fullEnv.constants.Brand,
model: fullEnv.constants.Model,
system: `${fullEnv.OS}/${fullEnv.constants.Version || fullEnv.constants.osVersion}/${language}`,
system: `${fullEnv.OS}/${
fullEnv.constants.Version || fullEnv.constants.osVersion
}/${language}`,
};
return {
fullEnv,

View File

@ -5,7 +5,8 @@ const react_native_1 = require("react-native");
const react_native_localize_1 = require("react-native-localize");
const react_native_device_info_1 = require("react-native-device-info");
async function getEnv() {
const language = (0, react_native_localize_1.getLocales)()[0].languageTag;
const isDebuggingEnabled = typeof atob !== 'undefined';
const language = !isDebuggingEnabled ? (0, react_native_localize_1.getLocales)()[0].languageTag : navigator.language;
const deviceId = (0, react_native_device_info_1.getDeviceId)();
const fullEnv = {
...react_native_1.Platform,

View File

@ -4,7 +4,8 @@ import { getLocales } from 'react-native-localize';
import { getDeviceId } from 'react-native-device-info';
export async function getEnv() {
const language = getLocales()[0].languageTag;
const isDebuggingEnabled = typeof atob !== 'undefined';
const language = !isDebuggingEnabled ? getLocales()[0].languageTag : navigator.language;
const deviceId = getDeviceId();
const fullEnv = {
...Platform,