A toolbox for your React Native app localization.
—
Core functionality for accessing device regional settings including locales, country, timezone, and calendar information.
Retrieves an array of the device's preferred locales in order of preference.
/**
* Get device's preferred locales in order of preference
* @returns Array of Locale objects with language, country, and RTL information
*/
function getLocales(): Locale[];
interface Locale {
/** Language code (e.g., "en", "fr", "zh") */
languageCode: string;
/** Optional script code (e.g., "Latn", "Cyrl") */
scriptCode?: string;
/** Country code (e.g., "US", "FR", "CN") */
countryCode: string;
/** Complete language tag (e.g., "en-US", "fr-FR") */
languageTag: string;
/** Whether this locale uses right-to-left text direction */
isRTL: boolean;
}Usage Examples:
import { getLocales } from "react-native-localize";
const locales = getLocales();
console.log(locales);
// [
// { languageCode: "en", countryCode: "US", languageTag: "en-US", isRTL: false },
// { languageCode: "es", countryCode: "US", languageTag: "es-US", isRTL: false }
// ]
// Get primary locale
const primaryLocale = locales[0];
if (primaryLocale.isRTL) {
// Configure RTL layout
}Gets the device's country code based on regional settings.
/**
* Get device's country code
* @returns ISO country code (e.g., "US", "FR", "JP")
*/
function getCountry(): string;Usage Examples:
import { getCountry } from "react-native-localize";
const country = getCountry();
console.log(country); // "US"
// Use for country-specific logic
if (country === "US") {
// Use US-specific defaults
}Gets the device's current timezone identifier.
/**
* Get device's timezone identifier
* @returns Timezone identifier (e.g., "America/New_York", "Europe/London")
*/
function getTimeZone(): string;Usage Examples:
import { getTimeZone } from "react-native-localize";
const timezone = getTimeZone();
console.log(timezone); // "America/New_York"
// Use with date formatting
const date = new Date();
const formatter = new Intl.DateTimeFormat("en-US", {
timeZone: timezone,
year: "numeric",
month: "long",
day: "numeric"
});
console.log(formatter.format(date));Gets the device's calendar system preference.
/**
* Get device's calendar system
* @returns Calendar system identifier
*/
function getCalendar(): Calendar;
type Calendar =
| "gregorian" // Western/Christian calendar
| "buddhist" // Buddhist calendar
| "coptic" // Coptic calendar
| "ethiopic" // Ethiopian calendar
| "ethiopic-amete-alem" // Ethiopian Amete Alem calendar
| "hebrew" // Hebrew/Jewish calendar
| "indian" // Indian national calendar
| "islamic" // Islamic calendar
| "islamic-umm-al-qura" // Islamic Umm al-Qura calendar
| "islamic-civil" // Islamic civil calendar
| "islamic-tabular" // Islamic tabular calendar
| "iso8601" // ISO 8601 calendar
| "japanese" // Japanese calendar
| "persian"; // Persian calendarUsage Examples:
import { getCalendar } from "react-native-localize";
const calendar = getCalendar();
console.log(calendar); // "gregorian"
// Use for calendar-specific date formatting
if (calendar === "islamic") {
// Use Islamic calendar for date display
} else if (calendar === "hebrew") {
// Use Hebrew calendar for date display
}Install with Tessl CLI
npx tessl i tessl/npm-react-native-localize