# Localize Utilities URL: /docs/native/expo/localize Device locale, timezone, and formatting utilities with react-native-localize fallback. ## Overview The `localize` module provides device locale detection, timezone, date/number/currency formatting, and measurement system detection. It requires `react-native-localize` for accurate native locale data and falls back to `Intl` APIs when unavailable. ## Installation ```bash npx expo install react-native-localize ``` **Dependencies:** - [react-native-localize](https://www.npmjs.com/package/react-native-localize) ### Expo Configuration Add `react-native-localize` as a plugin in your `app.config.ts` with the locales your app supports: ```ts { plugins: [ [ 'react-native-localize', { locales: ['en', 'tr', 'de', 'fr'] } ] ] } ``` > **Note:** Without this plugin config, locale detection may not work correctly on iOS. The `locales` array determines which languages your app declares support for. ## Usage ```tsx import { getDeviceLocale, getDeviceLanguage, getDeviceCountry, getDeviceTimeZone, uses24HourClock, usesMetricSystem, formatDate, formatNumber, formatCurrency, } from '@/lib/docyrus/localize'; // Device info const locale = getDeviceLocale(); // 'tr-TR' const lang = getDeviceLanguage(); // 'tr' const country = getDeviceCountry(); // 'TR' const tz = getDeviceTimeZone(); // 'Europe/Istanbul' const is24h = uses24HourClock(); // true const metric = usesMetricSystem(); // true // Formatting formatDate(new Date(), { dateStyle: 'long' }); // '5 Mart 2026' formatNumber(1234.56); // '1.234,56' formatCurrency(99.99, 'TRY'); // '₺99,99' ``` ## API Reference ### Device Info | Function | Return Type | Description | |----------|-------------|-------------| | `getDeviceLocale()` | `string` | Full locale tag (e.g., `'tr-TR'`). Falls back to `'en-US'` | | `getDeviceLanguage()` | `string` | Language code (e.g., `'tr'`). Falls back to `'en'` | | `getDeviceCountry()` | `string \| undefined` | Country code (e.g., `'TR'`) | | `getDeviceTimeZone()` | `string` | IANA timezone (e.g., `'Europe/Istanbul'`). Falls back to `'UTC'` | | `uses24HourClock()` | `boolean` | Whether device uses 24-hour clock | | `usesMetricSystem()` | `boolean` | Whether device uses metric system | | `getPreferredLocales()` | `string[]` | All preferred locale tags | ### Formatting | Function | Parameters | Description | |----------|-----------|-------------| | `formatNumber(value, options?, locale?)` | `number, Intl.NumberFormatOptions?, string?` | Locale-aware number formatting | | `formatDate(date, options?, locale?)` | `Date, Intl.DateTimeFormatOptions?, string?` | Locale-aware date formatting | | `formatCurrency(value, currencyCode?, locale?)` | `number, string?, string?` | Currency formatting (default: `'USD'`) | | `getCurrencySymbol(currencyCode)` | `string` | Get currency symbol (e.g., `'₺'` for `'TRY'`) | ## Fallback Behavior | Feature | With `react-native-localize` | Without (Intl fallback) | |---------|------------------------------|------------------------| | Locale detection | Device's preferred locale list | `Intl.DateTimeFormat` resolved locale | | Timezone | `RNLocalize.getTimeZone()` | `Intl.DateTimeFormat` resolved timezone | | 24h clock | `RNLocalize.uses24HourClock()` | AM/PM presence check | | Metric system | `RNLocalize.usesMetricSystem()` | Country code heuristic (US, LR, MM → imperial) | ## Compatibility | Platform | Support | |----------|---------| | Expo Go | Yes | | Dev Client | Yes | | Bare RN | Yes (auto-linked) |