0
# Device Settings
1
2
Core functionality for accessing device regional settings including locales, country, timezone, and calendar information.
3
4
## Capabilities
5
6
### Get Device Locales
7
8
Retrieves an array of the device's preferred locales in order of preference.
9
10
```typescript { .api }
11
/**
12
* Get device's preferred locales in order of preference
13
* @returns Array of Locale objects with language, country, and RTL information
14
*/
15
function getLocales(): Locale[];
16
17
interface Locale {
18
/** Language code (e.g., "en", "fr", "zh") */
19
languageCode: string;
20
/** Optional script code (e.g., "Latn", "Cyrl") */
21
scriptCode?: string;
22
/** Country code (e.g., "US", "FR", "CN") */
23
countryCode: string;
24
/** Complete language tag (e.g., "en-US", "fr-FR") */
25
languageTag: string;
26
/** Whether this locale uses right-to-left text direction */
27
isRTL: boolean;
28
}
29
```
30
31
**Usage Examples:**
32
33
```typescript
34
import { getLocales } from "react-native-localize";
35
36
const locales = getLocales();
37
console.log(locales);
38
// [
39
// { languageCode: "en", countryCode: "US", languageTag: "en-US", isRTL: false },
40
// { languageCode: "es", countryCode: "US", languageTag: "es-US", isRTL: false }
41
// ]
42
43
// Get primary locale
44
const primaryLocale = locales[0];
45
if (primaryLocale.isRTL) {
46
// Configure RTL layout
47
}
48
```
49
50
### Get Device Country
51
52
Gets the device's country code based on regional settings.
53
54
```typescript { .api }
55
/**
56
* Get device's country code
57
* @returns ISO country code (e.g., "US", "FR", "JP")
58
*/
59
function getCountry(): string;
60
```
61
62
**Usage Examples:**
63
64
```typescript
65
import { getCountry } from "react-native-localize";
66
67
const country = getCountry();
68
console.log(country); // "US"
69
70
// Use for country-specific logic
71
if (country === "US") {
72
// Use US-specific defaults
73
}
74
```
75
76
### Get Device Timezone
77
78
Gets the device's current timezone identifier.
79
80
```typescript { .api }
81
/**
82
* Get device's timezone identifier
83
* @returns Timezone identifier (e.g., "America/New_York", "Europe/London")
84
*/
85
function getTimeZone(): string;
86
```
87
88
**Usage Examples:**
89
90
```typescript
91
import { getTimeZone } from "react-native-localize";
92
93
const timezone = getTimeZone();
94
console.log(timezone); // "America/New_York"
95
96
// Use with date formatting
97
const date = new Date();
98
const formatter = new Intl.DateTimeFormat("en-US", {
99
timeZone: timezone,
100
year: "numeric",
101
month: "long",
102
day: "numeric"
103
});
104
console.log(formatter.format(date));
105
```
106
107
### Get Device Calendar
108
109
Gets the device's calendar system preference.
110
111
```typescript { .api }
112
/**
113
* Get device's calendar system
114
* @returns Calendar system identifier
115
*/
116
function getCalendar(): Calendar;
117
118
type Calendar =
119
| "gregorian" // Western/Christian calendar
120
| "buddhist" // Buddhist calendar
121
| "coptic" // Coptic calendar
122
| "ethiopic" // Ethiopian calendar
123
| "ethiopic-amete-alem" // Ethiopian Amete Alem calendar
124
| "hebrew" // Hebrew/Jewish calendar
125
| "indian" // Indian national calendar
126
| "islamic" // Islamic calendar
127
| "islamic-umm-al-qura" // Islamic Umm al-Qura calendar
128
| "islamic-civil" // Islamic civil calendar
129
| "islamic-tabular" // Islamic tabular calendar
130
| "iso8601" // ISO 8601 calendar
131
| "japanese" // Japanese calendar
132
| "persian"; // Persian calendar
133
```
134
135
**Usage Examples:**
136
137
```typescript
138
import { getCalendar } from "react-native-localize";
139
140
const calendar = getCalendar();
141
console.log(calendar); // "gregorian"
142
143
// Use for calendar-specific date formatting
144
if (calendar === "islamic") {
145
// Use Islamic calendar for date display
146
} else if (calendar === "hebrew") {
147
// Use Hebrew calendar for date display
148
}
149
```