Skip to content

Commit e7a7165

Browse files
committed
Merge pull request #1117 from NativeScript/platformModule
region property added;change in how to get the language in android
2 parents 5ab780b + 68ca2bb commit e7a7165

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

platform/platform.android.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class device implements definition.device {
1919
private static _deviceType: string;
2020
private static _uuid: string;
2121
private static _language: string;
22+
private static _region: string;
2223

2324
static get os(): string {
2425
return platformNames.android;
@@ -85,11 +86,19 @@ export class device implements definition.device {
8586

8687
static get language(): string {
8788
if (!device._language) {
88-
device._language = java.util.Locale.getDefault().toString();
89+
device._language = java.util.Locale.getDefault().getLanguage();
8990
}
9091

9192
return device._language;
9293
}
94+
95+
static get region(): string {
96+
if(!device._region) {
97+
device._region = java.util.Locale.getDefault().getCountry();
98+
}
99+
100+
return device._region;
101+
}
93102
}
94103

95104
var mainScreen: MainScreen;

platform/platform.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ declare module "platform" {
6161
static uuid: string;
6262

6363
/**
64-
* Gets the preferred language. For example "en" or "en_US"
64+
* Gets the preferred language. For example "en"
6565
*/
6666
static language: string;
67+
68+
/**
69+
* Gets the preferred region. For example "US"
70+
*/
71+
static region: string;
6772
}
6873

6974
/**

platform/platform.ios.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class device implements definition.device {
1515
private static _sdkVersion: string;
1616
private static _deviceType: string;
1717
private static _language: string;
18+
private static _region: string;
1819

1920
static get manufacturer(): string {
2021
return "Apple";
@@ -84,6 +85,14 @@ export class device implements definition.device {
8485

8586
return device._language;
8687
}
88+
89+
static get region(): string {
90+
if(!device._region) {
91+
device._region = NSLocale.currentLocale().objectForKey(NSLocaleCountryCode);
92+
}
93+
94+
return device._region;
95+
}
8796
}
8897

8998
var mainScreen: MainScreen;

0 commit comments

Comments
 (0)