How to use the expo-localization.locale function in expo-localization

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 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;
github Vivify-Ideas / expo-boilerplate / i18n / index.js View on Github external
import i18n from 'i18n-js';
import * as Localization from 'expo-localization';

import en from './locale/en';

i18n.fallbacks = true;

i18n.translations = {
  en
};

i18n.locale = Localization.locale;

export default function $t(key, params = {}) {
  return i18n.t(key, params);
}
github dooboolab / hackatalk-mobile / STRINGS.ts View on Github external
PASSWORD_CHANGE: '비밀번호 변경하기',
  PASSWORD_CURRENT: '기존 비밀번호',
  PASSWORD_NEW: '새로운 비밀번호',
  PASSWORD_NEW_REPEAT: '새로운 비밀번호 확인',
  NEXT: '다음',
  OK: '확인',
  CONFIRM: '확인',
  LOGIN_INFORMATION: '계정 정보',
  SIGNED_IN_WITH_GOOGLE: '구글 계정으로 로그인 됨',
  SIGNED_IN_WITH_FACEBOOK: '페이스북 계정으로 로그인 됨',
  SIGNED_IN_WITH_EMAIL: '이메일로 로그인 됨',
};

i18n.fallbacks = true;
i18n.translations = { en, ko };
i18n.locale = Localization.locale;

export const getString = (param: string, mapObj?: object): string => {
  if (mapObj) {
    i18n.t(param, mapObj);
  }
  return i18n.t(param);
};
github dodie / tracing-paper-sketching / i18n / i18n.js View on Github external
it: it,
  hu: hu,
  fr: fr,
  cz: cz,
  ar: ar,
  bn: bn,
  hi: hi,
  id: id,
  zh: zh,
  "zh_Hans-CN": zh_CN,
  "zh-Hant-TW": zh_TW,
  ka: ka,
  tr: tr,
  kn : kn
};
i18n.locale = Localization.locale;
i18n.defaultLocale = "en-EN";

export default i18n;
github Flaque / quirk / src / i18n.ts View on Github external
it,
  ko,
  pl,
  es,
  de,
  fi,
  nl,
  ru,
  "zh-Hans": zhHans,
  "pt-PT": ptPT,
  "pt-BR": ptBR,
  nb,
  sv,
  ro,
};
i18n.locale = Localization.locale;

export default i18n;