Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static getCurrentLanguage() {
// Get current language
var DeviceInfo = require('react-native-device-info');
var lang = DeviceInfo.getDeviceLocale();
if (lang.includes('-')) {
// Simplify -> ja-US to ja only
lang = lang.split('-').slice(0, -1);
// Basic filter
switch (lang[0]) {
case 'cs':
case 'de':
case 'en':
case 'es':
case 'fr':
case 'ja':
case 'pl':
case 'pt':
case 'ru':
case 'th':
case 'tr':
import defaultLang from '../../locales/default'
import enPH from '../../locales/en_P'
const supportedLocales = {
en_PH: enPH
}
// HEY YOU! just import and then add your locales to the supportedLocales array
// PROBABLY DO NOT CHANGE ANYTHING BELOW THIS LINE
import DeviceInfo from 'react-native-device-info'
const deviceLocale = DeviceInfo.getDeviceLocale()
const LocaleStrings = function (inputKey, reqLocale) {
// if no locale specified, use device
if (!reqLocale) {
reqLocale = deviceLocale
}
const localeFormatted = reqLocale.replace('-', '_') // in iOS, locales are - so we standardize to android
let localeStrings = defaultLang
if (supportedLocales[localeFormatted]) {
localeStrings = supportedLocales[localeFormatted]
}
if (localeStrings[inputKey] !== undefined) {
return localeStrings[inputKey]
} else if (defaultLang[inputKey] !== undefined) {
// An All Components Screen is a great way to dev and quick-test components
import React from 'react'
import { View, ScrollView, Text, Image, NetInfo, TouchableOpacity } from 'react-native'
import DeviceInfo from 'react-native-device-info'
import { Metrics, Images } from './DevTheme'
import styles from './Styles/DeviceInfoScreenStyles'
const HARDWARE_DATA = [
{title: 'Device Manufacturer', info: DeviceInfo.getManufacturer()},
{title: 'Device Name', info: DeviceInfo.getDeviceName()},
{title: 'Device Model', info: DeviceInfo.getModel()},
{title: 'Device Unique ID', info: DeviceInfo.getUniqueID()},
{title: 'Device Locale', info: DeviceInfo.getDeviceLocale()},
{title: 'Device Country', info: DeviceInfo.getDeviceCountry()},
{title: 'User Agent', info: DeviceInfo.getUserAgent()},
{title: 'Screen Width', info: Metrics.screenWidth},
{title: 'Screen Height', info: Metrics.screenHeight}
]
const OS_DATA = [
{title: 'Device System Name', info: DeviceInfo.getSystemName()},
{title: 'Device ID', info: DeviceInfo.getDeviceId()},
{title: 'Device Version', info: DeviceInfo.getSystemVersion()}
]
const APP_DATA = [
{title: 'Bundle Id', info: DeviceInfo.getBundleId()},
{title: 'Build Number', info: DeviceInfo.getBuildNumber()},
{title: 'App Version', info: DeviceInfo.getVersion()},
export const detectDeviceLocale = () => {
try {
// eslint-disable-next-line import/no-extraneous-dependencies
const deviceInfo = require('react-native-device-info');
return deviceInfo.getDeviceLocale();
} catch (e) {
try
{
return window.navigator.languages && window.navigator.languages.length > 0
? window.navigator.languages[0]
: window.navigator.language || window.navigator.userLanguage;
}
catch(ex){
return 'en-US';
}
}
};
import es from './strings/es.json'
import fr from './strings/fr.json'
import it from './strings/it.json'
import ja from './strings/ja.json'
import ko from './strings/ko.json'
import pt from './strings/pt.json'
import ru from './strings/ru.json'
import vi from './strings/vi.json'
import zh from './strings/zh.json'
const allLocales = { en, ru, es, it, pt, ja, fr, ko, vi, zh }
const strings: { [stringCode: string]: string } = {}
const out = { strings }
selectLocale(DeviceInfo.getDeviceLocale())
function mergeStrings(primary: Object, secondary: Object) {
for (const str in secondary) {
if (secondary.hasOwnProperty(str)) {
if (secondary[str]) {
primary[str] = secondary[str]
}
}
}
}
// Locale formats can be in the form 'en', 'en-US', 'en_US', or 'enUS'
export function selectLocale(locale: string = 'en'): boolean {
// Break up local into language and region
const normalizedLocale = locale
.replace('-', '')
render() {
const {init, isLandscape} = this.state;
if (!init) {
return null;
}
const theme = Preferences.THEMES.default;
const locale = DeviceInfo.getDeviceLocale().split('-')[0];
const initialRoute = {
component: ExtensionPost,
title: 'Mattermost',
passProps: {
authenticated: this.userIsLoggedIn(),
entities: this.entities,
onClose: this.onClose,
isLandscape,
theme,
},
wrapperStyle: {
borderRadius: 10,
backgroundColor: theme.centerChannelBg,
},
};
onFeedback = () => {
let body = `\n\n-------------\nWrite above this line\n${Device.getManufacturer()} | ${Device.getBrand()} | `
body += `${Device.getModel()} | ${Device.getDeviceId()}\n`
body += `${Device.getSystemName()} ${Device.getSystemVersion()} | Build: ${Device.getReadableVersion()} ${Device.getDeviceLocale()}`
Linking.openURL(`mailto:${mail}?subject=[${appName}]%20Feedback&body=${body}`).catch(err => console.log('About:onFeedback', err))
}
export function getDeviceInfo() {
const {height, width} = Dimensions.get('window');
return {
api_level: DeviceInfo.getAPILevel(),
build_number: DeviceInfo.getBuildNumber(),
bundle_id: DeviceInfo.getBundleId(),
brand: DeviceInfo.getBrand(),
country: DeviceInfo.getDeviceCountry(),
device_id: DeviceInfo.getDeviceId(),
device_locale: DeviceInfo.getDeviceLocale().split('-')[0],
device_type: DeviceInfo.getDeviceType(),
device_unique_id: DeviceInfo.getUniqueID(),
height: height ? Math.floor(height) : 0,
is_emulator: DeviceInfo.isEmulator(),
is_tablet: DeviceInfo.isTablet(),
manufacturer: DeviceInfo.getManufacturer(),
max_memory: DeviceInfo.getMaxMemory(),
model: DeviceInfo.getModel(),
system_name: DeviceInfo.getSystemName(),
system_version: DeviceInfo.getSystemVersion(),
timezone: DeviceInfo.getTimezone(),
app_version: DeviceInfo.getVersion(),
width: width ? Math.floor(width) : 0,
};
}
_getDeviceInfos() {
const infos = [];
infos.push({label:"Device Manufacturer", data: DeviceInfo.getManufacturer()});
infos.push({label:"Device Brand", data: DeviceInfo.getBrand()});
infos.push({label:"Device Model", data: DeviceInfo.getModel()});
infos.push({label:"Device ID", data: DeviceInfo.getDeviceId()});
infos.push({label:"System Name", data: DeviceInfo.getSystemName()});
infos.push({label:"System Version", data: DeviceInfo.getSystemVersion()});
infos.push({label:"Bundle ID", data: DeviceInfo.getBundleId()});
infos.push({label:"Build Number", data: DeviceInfo.getBuildNumber()});
infos.push({label:"App Version", data: DeviceInfo.getVersion()});
infos.push({label:"App Version Readable", data: DeviceInfo.getReadableVersion()});
infos.push({label:"Device name", data: DeviceInfo.getDeviceName()});
infos.push({label:"User Agent", data: DeviceInfo.getUserAgent()});
infos.push({label:"Device Locale", data: DeviceInfo.getDeviceLocale()});
infos.push({label:"Device Country", data: DeviceInfo.getDeviceCountry()});
infos.push({label:"Unique ID", data: DeviceInfo.getUniqueID()});
infos.push({label:"App Instance ID", data: DeviceInfo.getInstanceID()});
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
return ds.cloneWithRows(infos);
}
function MagnetMetrics(storage) {
this.storage = storage || AsyncStorage;
this.metrics = new exports.Metrics(DeviceInfo.getUniqueID(),
{
locale: DeviceInfo.getDeviceLocale(),
os: DeviceInfo.getSystemName(),
os_version: DeviceInfo.getSystemVersion(),
device: DeviceInfo.getDeviceName(),
app_name: 'org.mozilla.magnet',
app_version: DeviceInfo.getReadableVersion(),
app_build_id: DeviceInfo.getBuildNumber(),
app_platform: manufacturer
}
);
}