File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Native \Mobile \Data ;
4+
5+ class Localization
6+ {
7+ public function __construct (
8+ public readonly string $ locale ,
9+ public readonly string $ languageCode ,
10+ public readonly string $ regionCode ,
11+ public readonly string $ timezone ,
12+ public readonly string $ currencyCode ,
13+ public readonly string $ preferredLanguage ,
14+ ) {}
15+ }
Original file line number Diff line number Diff line change 22
33namespace Native \Mobile ;
44
5+ use Native \Mobile \Data \Localization ;
6+
57class Device
68{
79 public function getId (): ?string
@@ -46,6 +48,28 @@ public function getBatteryInfo(): ?string
4648 return null ;
4749 }
4850
51+ public function localization (): ?Localization
52+ {
53+ if (function_exists ('nativephp_call ' )) {
54+ $ result = nativephp_call ('Device.GetLocale ' , '{} ' );
55+ if ($ result ) {
56+ $ decoded = json_decode ($ result , true );
57+ $ info = json_decode ($ decoded ['info ' ] ?? '{} ' , true );
58+
59+ return new Localization (
60+ locale: $ info ['locale ' ] ?? '' ,
61+ languageCode: $ info ['languageCode ' ] ?? '' ,
62+ regionCode: $ info ['regionCode ' ] ?? '' ,
63+ timezone: $ info ['timezone ' ] ?? '' ,
64+ currencyCode: $ info ['currencyCode ' ] ?? '' ,
65+ preferredLanguage: $ info ['preferredLanguage ' ] ?? '' ,
66+ );
67+ }
68+ }
69+
70+ return null ;
71+ }
72+
4973 /**
5074 * Vibrate the device with a short haptic feedback.
5175 *
Original file line number Diff line number Diff line change 88 * @method static string|null getId()
99 * @method static string|null getInfo()
1010 * @method static string|null getBatteryInfo()
11+ * @method static \Native\Mobile\Data\Localization|null localization()
1112 * @method static bool vibrate()
1213 * @method static array toggleFlashlight()
1314 */
You can’t perform that action at this time.
0 commit comments