Skip to content

Instantly share code, notes, and snippets.

@dsternlicht
Created November 13, 2017 11:38
Show Gist options
  • Save dsternlicht/3fc1bc9ceec9ea7e7a298cb7f00e5e38 to your computer and use it in GitHub Desktop.
Save dsternlicht/3fc1bc9ceec9ea7e7a298cb7f00e5e38 to your computer and use it in GitHub Desktop.
i18n.js file with moment.js
import ReactNative from 'react-native';
import I18n from 'react-native-i18n';
import moment from 'moment';
// Import all locales
import en from './en.json';
import he from './he.json';
// Should the app fallback to English if user locale doesn't exists
I18n.fallbacks = true;
// Define the supported translations
I18n.translations = {
en,
he
};
const currentLocale = I18n.currentLocale();
// Is it a RTL language?
export const isRTL = currentLocale.indexOf('he') === 0 || currentLocale.indexOf('ar') === 0;
// Allow RTL alignment in RTL languages
ReactNative.I18nManager.allowRTL(isRTL);
// Localizing momentjs to Hebrew or English
if (currentLocale.indexOf('he') === 0) {
require('moment/locale/he.js');
moment.locale('he');
} else {
moment.locale('en');
}
// The method we'll use instead of a regular string
export function strings(name, params = {}) {
return I18n.t(name, params);
};
export default I18n;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment