How to use the i18n-js.fallbacks function in i18n-js

To help you get started, we’ve selected a few i18n-js 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 ovr / ghubber / utils / i18n.js View on Github external
// @flow

import { getDeviceLocale } from 'react-native-device-info';
import I18n from 'i18n-js';

import locales from 'locales';

I18n.fallbacks = true;
I18n.locale = getDeviceLocale();
I18n.translations = locales;

I18n.pluralization['ru'] = function (count) {
    const key = count % 10 == 1 && count % 100 != 11 ? 'one' : [2, 3, 4].indexOf(count % 10) >= 0 && [12, 13, 14].indexOf(count % 100) < 0 ? 'few' : count % 10 == 0 || [5, 6, 7, 8, 9].indexOf(count % 10) >= 0 || [11, 12, 13, 14].indexOf(count % 100) >= 0 ? 'many' : 'other';
    return [key];
};

export const __ = I18n.t.bind(I18n);

export default I18n;
github tsirlucas / PayIt / functions / src / i18n / i18n.ts View on Github external
import en from './locales/en';
import pt from './locales/pt-BR';

// tslint:disable-next-line:no-require-imports
const I18nCreator = require('i18n-js');

I18nCreator.defaultLocale = 'en';
I18nCreator.fallbacks = true;

I18nCreator.translations = {
  en: {...I18nCreator.translations.en, notification: en},
  'pt-BR': {...I18nCreator.translations['pt-BR'], notification: pt},
};

export const I18n = I18nCreator;
github jolocom / smartwallet-app / src / locales / i18n.ts View on Github external
// TODO
// don't load all translations in memory, when we have a lot of translations
// see
// https://github.com/react-native-community/react-native-localize/blob/master/example/src/AsyncExample.js

import * as RNLocalize from 'react-native-localize'
import I18n from 'i18n-js'

const de = require('./de.json')
const nl = require('./nl.json')

I18n.defaultLocale = 'en'
I18n.fallbacks = true
I18n.missingTranslation = scope => scope
I18n.translations = {
  de,
  nl,
}
export const locales = ['en', 'de', 'nl']

const fallback = { languageTag: 'en', isRTL: false }
const { languageTag } =
  RNLocalize.findBestAvailableLanguage(locales) || fallback
I18n.locale = languageTag

const localeSpecificImages = {
  en: {
    '01.jpg': require('src/resources/img/en/01.jpg'),
    '02.jpg': require('src/resources/img/en/02.jpg'),
github shoutem / extensions / shoutem.i18n / app / app.js View on Github external
export const appDidMount = app => {
  // Load the current locale from extension settings
  const state = app.getState();
  const defaultLocale = 'en';
  const { locale = defaultLocale } = getExtensionSettings(state, ext());

  I18n.fallbacks = defaultLocale;
  I18n.defaultLocale = defaultLocale;
  I18n.locale = locale;

  // Configure the moment library to use the same locale as the app
  moment.locale(locale);
};
github Cyphexl / WePeiyang-RN / app / i18n / i18n.ts View on Github external
},
  es: {
    native: "Espanol",
    common: "Spanish",
  },
  ar: {
    native: "عربى",
    common: "Arabic",
  },
  th: {
    native: "ไทย",
    common: "Thai",
  },
}

i18n.fallbacks = true
i18n.translations = { en, ja, zh, es, ar, th }
github infinitered / ignite-bowser / boilerplate / app / i18n / i18n.ts View on Github external
import * as RNLocalize from "react-native-localize"
import i18n from "i18n-js"

const en = require("./en")
const ja = require("./ja")

i18n.fallbacks = true
i18n.translations = { en, ja }

const fallback = { languageTag: "en", isRTL: false }
const { languageTag } = RNLocalize.findBestAvailableLanguage(Object.keys(i18n.translations)) || fallback
i18n.locale = languageTag
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 saucelabs / sample-app-mobile / src / js / config / I18n.js View on Github external
import I18n from 'i18n-js';
import * as RNLocalize from 'react-native-localize';
import en from './translations/en';

const locales = RNLocalize.getLocales();

if (Array.isArray(locales)) {
	I18n.locale = locales[ 0 ].languageTag;
}

I18n.fallbacks = true;
I18n.translations = {
	en,
};

export default I18n;
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;