Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ type getLocales = () => Array<{
scriptCode?: string;
countryCode: string;
languageTag: string;
languageTagWithExtensions: string;
isRTL: boolean;
}>;
```
Expand All @@ -215,9 +216,9 @@ import { getLocales } from "react-native-localize";

console.log(getLocales());
/* -> [
{ countryCode: "GB", languageTag: "en-GB", languageCode: "en", isRTL: false },
{ countryCode: "US", languageTag: "en-US", languageCode: "en", isRTL: false },
{ countryCode: "FR", languageTag: "fr-FR", languageCode: "fr", isRTL: false },
{ countryCode: "GB", languageTag: "en-GB", languageTagWithExtensions: "en-GB", languageCode: "en", isRTL: false },
{ countryCode: "US", languageTag: "en-US", languageTagWithExtensions: "en-US", languageCode: "en", isRTL: false },
{ countryCode: "SA", languageTag: "ar-SA", languageTagWithExtensions: "ar-SA-u-nu-latn", languageCode: "ar", isRTL: true },
] */
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ object RNLocalizeModuleImpl {
putString("languageCode", languageCode)
putString("countryCode", countryCode)
putString("languageTag", languageTag)
putString("languageTagWithExtensions", systemLocale.toLanguageTag())

val rtl = TextUtils.getLayoutDirectionFromLocale(systemLocale) == View.LAYOUT_DIRECTION_RTL
putBoolean("isRTL", rtl)
Expand Down
1 change: 1 addition & 0 deletions ios/RNLocalize.mm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ - (NSArray *)getLocalesImpl {
@"languageCode": languageCode,
@"countryCode": countryCode,
@"languageTag": languageTag,
@"languageTagWithExtensions": identifier,
@"isRTL": @(isRTL),
}];

Expand Down
16 changes: 14 additions & 2 deletions src/extras/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ export const getCurrencies = () => ["USD", "EUR"]; // can be empty array

export const getLocales = () => [
// extend if needed, add the locales you want
{ countryCode: "US", languageTag: "en-US", languageCode: "en", isRTL: false },
{ countryCode: "FR", languageTag: "fr-FR", languageCode: "fr", isRTL: false },
{
countryCode: "US",
languageTag: "en-US",
languageTagWithExtensions: "en-US",
languageCode: "en",
isRTL: false,
},
{
countryCode: "FR",
languageTag: "fr-FR",
languageTagWithExtensions: "fr-FR",
languageCode: "fr",
isRTL: false,
},
];

export const getNumberFormatSettings = () => ({
Expand Down
1 change: 1 addition & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const convertLanguageTagToLocale = (
languageCode,
countryCode,
languageTag: `${languageCode}-${countryCode}`,
languageTagWithExtensions: languageTag,
isRTL: USES_RTL_LAYOUT.has(languageCode),
};
};
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export type Locale = Readonly<{
countryCode: string;
/** Full BCP 47 language tag (e.g., `"en-US"`, `"zh-Hans-CN"`) */
languageTag: string;
/** Full BCP 47 language tag, including Unicode extensions when available (e.g., `"ar-SA-u-nu-latn"`) */
languageTagWithExtensions: string;
/** Whether the locale uses right-to-left text direction */
isRTL: boolean;
}>;
Expand Down