How to use expo-localization - 10 common examples

To help you get started, we’ve selected a few expo-localization examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github digidem / mapeo-mobile / src / frontend / App.js View on Github external
const App = () => {
  const [locale, setLocale] = React.useState(Localization.locale || "en");
  const appState = useAppState();

  React.useEffect(() => {
    // Localization only changes in Android (in iOS the app is restarted) and
    // will only happen when the app comes back into the foreground
    if (Platform.OS !== "android" || appState !== "active") return;
    Localization.getLocalizationAsync()
      .then(({ locale }) => setLocale(locale || "en"))
      .catch(() => {});
  }, [appState]);

  // Add fallbacks for non-regional locales
  const localeMessages = {
    ...messages[locale.split("-")[0]],
    ...(messages[locale] || {})
  };
github shanhuiyang / TypeScript-MERN-Starter / client / App.tsx View on Github external
interface Props {}
interface States {
    isReady: boolean;
}

if (__DEV__) {
    setHostUrl(HOST_URL_DEV);
} else {
    setHostUrl(HOST_URL_PROD);
}

// initialize locale from system language
store.dispatch({
    type: SET_LOCALE,
    locale: Localization.locale
});
// initialize toast provider using Toast from NativeBase
initToast(new ToastWrapper(store));
// initialize local storage provider
initStorage(AsyncStorage);

export default class App extends React.Component {
    constructor(props: Props) {
        super(props);
        this.state = {
            isReady: false,
        };
    }

    async componentDidMount() {
        // Load font resources for NativeBase
github digidem / mapeo-mobile / src / frontend / App.js View on Github external
React.useEffect(() => {
    // Localization only changes in Android (in iOS the app is restarted) and
    // will only happen when the app comes back into the foreground
    if (Platform.OS !== "android" || appState !== "active") return;
    Localization.getLocalizationAsync()
      .then(({ locale }) => setLocale(locale || "en"))
      .catch(() => {});
  }, [appState]);
github DefinitelyTyped / DefinitelyTyped / types / expo-localization / expo-localization-tests.ts View on Github external
import { Localization } from "expo-localization";

Localization.getLocalizationAsync().then(localization => localization.locale);
Localization.locale;
github DefinitelyTyped / DefinitelyTyped / types / expo-localization / expo-localization-tests.ts View on Github external
import { Localization } from "expo-localization";

Localization.getLocalizationAsync().then(localization => localization.locale);
Localization.locale;
github leejh3224 / react-native-hello-talk / src / screens / Auth / register.tsx View on Github external
const user = navigation.getParam("userData");

      values.age = new Date().getFullYear() - values.birthday.getFullYear();
      delete values.birthday;

      if (user) {
        await firebase
          .database()
          .ref(`users/${user.uid}`)
          .set({
            ...values,
            description: "",
            profileImage: user.photoURL,
            lastActiveTime: Date.now(),
            country: Localization.country
          });

        navigation.navigate(getNavigationKey(["chat", "home"]));
      }
    } catch (error) {
      console.log(error);
    }
  };
github expo / expo / apps / native-component-list / src / screens / LocalizationScreen.tsx View on Github external
import i18n from 'i18n-js';
import chunk from 'lodash/chunk';
import React from 'react';
import { Picker, ScrollView, StyleSheet, Text, View } from 'react-native';
import * as Localization from 'expo-localization';

import HeadingText from '../components/HeadingText';
import ListButton from '../components/ListButton';
import MonoText from '../components/MonoText';

i18n.fallbacks = true;
i18n.locale = Localization.locale;
i18n.translations = {
  en: {
    phrase: 'Hello my friend',
    default: 'English language only',
  },
  ru: {
    phrase: 'Привет мой друг',
  },
};

interface State {
  isoCurrencyCodes: any;
  currentLocale: any;
  preferredLocales: any;
  locale?: string;
}
github daltonmenezes / aircnc / mobile / src / pages / Book.js View on Github external
import 'moment/min/locales'

import {
  SafeAreaView,
  Text,
  Alert,
  Platform,
  TouchableOpacity,
  AsyncStorage,
  StyleSheet
} from 'react-native'

import api from '../services/api'

const deviceLanguage =
  Localization.locale
    .replace(/_/g, '-')
    .toLowerCase()

moment.locale([
  deviceLanguage,
  'pt-br'
])

const DatePicker =
  Platform.OS === 'ios'
    ? require('DatePickerIOS')
    : require('../components/DatePickerAndroid')

export default ({ navigation }) => {
  const [date, setDate] = useState(Platform.OS === 'ios' ? new Date(): '')
  const id = navigation.getParam('id')
github bytefury / crater-mobile / src / api / lang / i18n.js View on Github external
import * as Localization from 'expo-localization';
import Lng from 'i18n-js';

import en from './en.json';
import fr from './fr.json';
import es from './es.json';

Lng.fallbacks = true;

Lng.translations = {
    en,
    fr,
    es
};

Lng.locale = Localization.locale;

export default Lng;