@amazon-devices/expo-localization 2.0.9000000000 → 2.0.9000000001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CMakeLists.txt CHANGED
@@ -15,15 +15,26 @@ set(PACKAGE_NAME "expo-localization")
15
15
  set(AUTO_LINK_PACKAGE_NAME "${PACKAGE_NAME}-${KEPLER_REACT_NATIVE_MAJOR_VERSION}")
16
16
  set(SOURCES_KEPLER kepler/ExpoLocalization.cpp)
17
17
 
18
- find_package(ICU COMPONENTS i18n)
18
+ # ICU::uc is an explicit dependency — previously resolved transitively through expo-kepler-utils -> keplerscript-2
19
+ find_package(ICU COMPONENTS i18n uc)
19
20
 
20
21
  add_library(${PACKAGE_NAME} STATIC ${SOURCES_KEPLER})
21
22
 
23
+ kepler_add_idl_import_library(
24
+ expo_localization_idl_pkg
25
+ PACKAGES
26
+ com.amazon.kepler.env
27
+ com.amazon.kepler.device_config
28
+ com.amazon.kepler.experimental_mr33.messaging
29
+ )
30
+
22
31
  target_link_libraries(
23
32
  ${PACKAGE_NAME}
24
33
  PUBLIC
25
- keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
34
+ turbomoduleAPI::turbomoduleAPI
26
35
  ICU::i18n
36
+ ICU::uc
37
+ expo_localization_idl_pkg
27
38
  )
28
39
 
29
40
  add_library(${AUTO_LINK_PACKAGE_NAME} SHARED kepler/KeplerInit.cpp)
@@ -41,8 +52,9 @@ add_executable(${AUTO_LINK_PACKAGE_NAME}_exe kepler/KeplerInit.cpp)
41
52
  target_link_libraries(${AUTO_LINK_PACKAGE_NAME}_exe
42
53
  PRIVATE
43
54
  ${AUTO_LINK_PACKAGE_NAME}
44
- keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
55
+ turbomoduleAPI::turbomoduleAPI
45
56
  ICU::i18n
57
+ expo_localization_idl_pkg
46
58
  )
47
59
 
48
60
  install(TARGETS ${AUTO_LINK_PACKAGE_NAME}
package/README.kepler.md CHANGED
@@ -107,3 +107,4 @@ Check out the dedicated documentation page for info about this library, API refe
107
107
  | Package version | Based on | @amazon-devices/react-native-kepler version |
108
108
  | ---------------- | -------- | --------------------------------- |
109
109
  | 2.0.x | expo-localization v14.6.0 | 2.0.x |
110
+ | 2.0.x | expo-localization v14.6.0 | 4.0.x+rn0.83.0 |
@@ -1,12 +1,12 @@
1
- import { Subscription } from 'expo-modules-core';
1
+ import type { Subscription } from 'expo-modules-core';
2
2
  import { Calendar, Locale } from './Localization.types';
3
- export declare function addLocaleListener(listener: (event: any) => void): void;
4
- export declare function addCalendarListener(listener: (event: any) => void): void;
3
+ export declare function addLocaleListener(listener: () => void): Subscription;
4
+ export declare function addCalendarListener(listener: () => void): Subscription;
5
5
  export declare function removeSubscription(subscription: Subscription): void;
6
6
  declare const module: {
7
7
  getLocales: () => Locale[];
8
8
  getCalendars: () => Calendar[];
9
- locale: any;
9
+ locale: string;
10
10
  };
11
11
  export default module;
12
12
  //# sourceMappingURL=ExpoLocalization.kepler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoLocalization.kepler.d.ts","sourceRoot":"","sources":["../src/ExpoLocalization.kepler.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAUtD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,CAAC,KAAK,KAAA,KAAK,IAAI,QAE1D;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,CAAC,KAAK,KAAA,KAAK,IAAI,QAE5D;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,QAE5D;AAED,QAAA,MAAM,MAAM;sBAnBM,MAAM,EAAE;wBACN,QAAQ,EAAE;;CAsB7B,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"ExpoLocalization.kepler.d.ts","sourceRoot":"","sources":["../src/ExpoLocalization.kepler.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAUxD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,YAAY,CAEpE;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,YAAY,CAStE;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,QAE5D;AAED,QAAA,MAAM,MAAM;sBA1BM,MAAM,EAAE;wBACN,QAAQ,EAAE;;CA6B7B,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -6,21 +6,28 @@
6
6
  * Use is subject to license terms.
7
7
  */
8
8
  import { TurboModuleRegistry } from '@amazon-devices/keplerscript-turbomodule-api';
9
+ import { DeviceEventEmitter } from 'react-native';
9
10
  const nativeModule = TurboModuleRegistry.getEnforcing('ExpoLocalization');
10
- const i18nManager = TurboModuleRegistry.getEnforcing('I18nManager');
11
11
  export function addLocaleListener(listener) {
12
- i18nManager.addListener('Locale', listener);
12
+ return DeviceEventEmitter.addListener('onLocaleSettingsChanged', listener);
13
13
  }
14
14
  export function addCalendarListener(listener) {
15
- i18nManager.addListener('Timezone', listener);
15
+ const localeSubscription = DeviceEventEmitter.addListener('onLocaleSettingsChanged', listener);
16
+ const timezoneSubscription = DeviceEventEmitter.addListener('onCalendarSettingsChanged', listener);
17
+ return {
18
+ remove: () => {
19
+ localeSubscription.remove();
20
+ timezoneSubscription.remove();
21
+ },
22
+ };
16
23
  }
17
24
  export function removeSubscription(subscription) {
18
- i18nManager.removeListeners();
25
+ subscription.remove();
19
26
  }
20
27
  const module = {
21
28
  getLocales: nativeModule.getLocales,
22
29
  getCalendars: nativeModule.getCalendars,
23
- locale: i18nManager.getAppLocale(),
30
+ locale: nativeModule.getLocale(),
24
31
  };
25
32
  export default module;
26
33
  //# sourceMappingURL=ExpoLocalization.kepler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoLocalization.kepler.js","sourceRoot":"","sources":["../src/ExpoLocalization.kepler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAoB,mBAAmB,EAAC,MAAM,oCAAoC,CAAC;AAU1F,MAAM,YAAY,GAAG,mBAAmB,CAAC,YAAY,CAAO,kBAAkB,CAAS,CAAC;AACxF,MAAM,WAAW,GAAG,mBAAmB,CAAC,YAAY,CAAC,aAAa,CAAQ,CAAC;AAE3E,MAAM,UAAU,iBAAiB,CAAC,QAAyB;IACvD,WAAW,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAyB;IACzD,WAAW,CAAC,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,YAA0B;IACzD,WAAW,CAAC,eAAe,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,MAAM,GAAG;IACX,UAAU,EAAE,YAAY,CAAC,UAAU;IACnC,YAAY,EAAE,YAAY,CAAC,YAAY;IACvC,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE;CACrC,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["/*\n * Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * PROPRIETARY/CONFIDENTIAL\n *\n * Use is subject to license terms.\n */\n\nimport {KeplerTurboModule, TurboModuleRegistry} from '@amazon-devices/keplerscript-turbomodule-api';\nimport {Subscription} from 'expo-modules-core';\n\nimport {Calendar, Locale} from './Localization.types';\n\ninterface Spec extends KeplerTurboModule {\n getLocales(): Locale[];\n getCalendars(): Calendar[];\n}\n\nconst nativeModule = TurboModuleRegistry.getEnforcing<Spec>('ExpoLocalization') as Spec;\nconst i18nManager = TurboModuleRegistry.getEnforcing('I18nManager') as any;\n\nexport function addLocaleListener(listener: (event) => void) {\n i18nManager.addListener('Locale', listener);\n}\n\nexport function addCalendarListener(listener: (event) => void) {\n i18nManager.addListener('Timezone', listener);\n}\n\nexport function removeSubscription(subscription: Subscription) {\n i18nManager.removeListeners();\n}\n\nconst module = {\n getLocales: nativeModule.getLocales,\n getCalendars: nativeModule.getCalendars,\n locale: i18nManager.getAppLocale(),\n};\n\nexport default module;\n"]}
1
+ {"version":3,"file":"ExpoLocalization.kepler.js","sourceRoot":"","sources":["../src/ExpoLocalization.kepler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAqB,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAE5F,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAUlD,MAAM,YAAY,GAAG,mBAAmB,CAAC,YAAY,CAAO,kBAAkB,CAAC,CAAC;AAEhF,MAAM,UAAU,iBAAiB,CAAC,QAAoB;IAClD,OAAO,kBAAkB,CAAC,WAAW,CAAC,yBAAyB,EAAE,QAAQ,CAAC,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAoB;IACpD,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,WAAW,CAAC,yBAAyB,EAAE,QAAQ,CAAC,CAAC;IAC/F,MAAM,oBAAoB,GAAG,kBAAkB,CAAC,WAAW,CAAC,2BAA2B,EAAE,QAAQ,CAAC,CAAC;IACnG,OAAO;QACH,MAAM,EAAE,GAAG,EAAE;YACT,kBAAkB,CAAC,MAAM,EAAE,CAAC;YAC5B,oBAAoB,CAAC,MAAM,EAAE,CAAC;QAClC,CAAC;KACY,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,YAA0B;IACzD,YAAY,CAAC,MAAM,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,MAAM,GAAG;IACX,UAAU,EAAE,YAAY,CAAC,UAAU;IACnC,YAAY,EAAE,YAAY,CAAC,YAAY;IACvC,MAAM,EAAE,YAAY,CAAC,SAAS,EAAE;CACnC,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["/*\n * Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * PROPRIETARY/CONFIDENTIAL\n *\n * Use is subject to license terms.\n */\n\nimport { KeplerTurboModule, TurboModuleRegistry } from '@amazon-devices/keplerscript-turbomodule-api';\nimport type { Subscription } from 'expo-modules-core';\nimport { DeviceEventEmitter } from 'react-native';\n\nimport { Calendar, Locale } from './Localization.types';\n\ninterface Spec extends KeplerTurboModule {\n getLocales(): Locale[];\n getCalendars(): Calendar[];\n getLocale(): string;\n}\n\nconst nativeModule = TurboModuleRegistry.getEnforcing<Spec>('ExpoLocalization');\n\nexport function addLocaleListener(listener: () => void): Subscription {\n return DeviceEventEmitter.addListener('onLocaleSettingsChanged', listener);\n}\n\nexport function addCalendarListener(listener: () => void): Subscription {\n const localeSubscription = DeviceEventEmitter.addListener('onLocaleSettingsChanged', listener);\n const timezoneSubscription = DeviceEventEmitter.addListener('onCalendarSettingsChanged', listener);\n return {\n remove: () => {\n localeSubscription.remove();\n timezoneSubscription.remove();\n },\n } as Subscription;\n}\n\nexport function removeSubscription(subscription: Subscription) {\n subscription.remove();\n}\n\nconst module = {\n getLocales: nativeModule.getLocales,\n getCalendars: nativeModule.getCalendars,\n locale: nativeModule.getLocale(),\n};\n\nexport default module;\n"]}
@@ -8,8 +8,20 @@
8
8
 
9
9
  #include "ExpoLocalization.h"
10
10
 
11
- #include <Volta/i18n/I18nManager.h>
12
- #include <uchar.h>
11
+ #include <Kepler/turbomodule/NativeObject.h>
12
+ #include <Kepler/turbomodule/TMLog.h>
13
+ #include <apmf/fn.h>
14
+ #include <apmf/iface/com/amazon/kepler/device_config/DeviceConfigNotFoundError.h>
15
+ #include <apmf/iface/com/amazon/kepler/device_config/DeviceConfigResult.h>
16
+ #include <apmf/iface/com/amazon/kepler/device_config/IDeviceConfig.h>
17
+ #include <apmf/iface/com/amazon/kepler/device_config/IDeviceConfigModule.h>
18
+ #include <apmf/iface/com/amazon/kepler/env/IEnvModule.h>
19
+ #include <apmf/iface/com/amazon/kepler/env/ILocaleConfig.h>
20
+ #include <apmf/iface/com/amazon/kepler/env/IResolvedLocalesListener.h>
21
+ #include <apmf/iface/com/amazon/kepler/experimental_mr33/messaging/IKeplerMessagingModule.h>
22
+ #include <apmf/iface/com/amazon/kepler/experimental_mr33/messaging/IMessageFilterBuilder.h>
23
+ #include <apmf/iface/com/amazon/kepler/experimental_mr33/messaging/IMessageListener.h>
24
+ #include <apmf/apmf_base.h>
13
25
  #include <unicode/currunit.h>
14
26
  #include <unicode/dcfmtsym.h>
15
27
  #include <unicode/dtptngen.h>
@@ -17,112 +29,186 @@
17
29
  #include <unicode/ulocdata.h>
18
30
 
19
31
  #include <memory>
32
+ #include <string>
33
+ #include <fmt/core.h>
20
34
 
21
- std::string toUTF8String(icu::UnicodeString from) {
35
+ namespace env = apmf::iface::com::amazon::kepler::env;
36
+ namespace devConf = apmf::iface::com::amazon::kepler::device_config;
37
+ namespace messaging = apmf::iface::com::amazon::kepler::experimental_mr33::messaging;
38
+
39
+ static const std::string g_timeZoneConfig{"com.amazon.devconf/system/configuration/time-zone"};
40
+
41
+ apmf::Ptr<devConf::IDeviceConfig> getDeviceConfig() {
42
+ return apmf::detail::GetProcessObject()
43
+ ->getComponent("/com.amazon.kepler.device_config")
44
+ .TryQueryInterface<devConf::IDeviceConfigModule>()
45
+ ->getDeviceConfig();
46
+ }
47
+
48
+ std::string toUTF8String(const icu::UnicodeString& from) {
22
49
  std::string result;
23
50
  from.toUTF8String(result);
24
51
  return result;
25
52
  }
26
53
 
27
- ExpoLocalization::ExpoLocalization() : volta::react::KeplerTurboModule("ExpoLocalization") {}
54
+ apmf::Ptr<env::IEnvModule> getEnvModule() {
55
+ return apmf::detail::GetProcessObject()
56
+ ->getComponent("/com.amazon.kepler.env")
57
+ .TryQueryInterface<env::IEnvModule>();
58
+ }
59
+
60
+ ExpoLocalization::ExpoLocalization() : KeplerTurboModule("ExpoLocalization") {
61
+ TMDEBUG(fmt::format("ExpoLocalization constructor {}", name()));
62
+
63
+ getEnvModule()->getLocaleConfig()->addResolvedLocalesListener(nullptr, apmf::Fn1([this](auto locales) {
64
+ this->emit("onLocaleSettingsChanged", nullptr);
65
+ }));
66
+
67
+ // Subscribe to timezone config changes via MR33 messaging
68
+ auto proc = apmf::detail::GetProcessObject();
69
+ auto messagingModule = proc->getComponent("/com.amazon.kepler.experimental_mr33.messaging")
70
+ .TryQueryInterface<messaging::IKeplerMessagingModule>();
71
+ if (messagingModule) {
72
+ struct TZListener : apmf::ApmfBase<TZListener, messaging::IMessageListener> {
73
+ ExpoLocalization* owner;
74
+ explicit TZListener(ExpoLocalization* o) : owner(o) {}
75
+ void onMessage(apmf::View<messaging::IMessage> /*message*/) {
76
+ owner->emit("onCalendarSettingsChanged", nullptr);
77
+ }
78
+ void onError(apmf::View<apmf::IError> /*error*/) {}
79
+ };
80
+
81
+ auto channel = messagingModule->makeMessageChannel(
82
+ "ExpoLocalization_TZ",
83
+ apmf::detail::Ptr<TZListener>::Make(this));
84
+
85
+ apmf::detail::Array<apmf::detail::Ptr<messaging::IMessageFilter>> filters;
86
+ filters.push_back(
87
+ messagingModule->makeMessageFilterBuilder()
88
+ ->baseUri("broadcast://*/com.amazon.devconf/system/configuration/time-zone")
89
+ ->build());
90
+ channel->registerMessageFilter(filters);
91
+ m_timezoneChannel = std::move(channel);
92
+ }
93
+ };
28
94
 
29
- volta::react::NativeJSArray ExpoLocalization::getLocales() {
30
- volta::react::NativeJSObject result;
31
- UErrorCode status = U_ZERO_ERROR;
95
+ std::string ExpoLocalization::getLocale() {
96
+ auto locales = getEnvModule()->getLocaleConfig()->getResolvedLocales(nullptr);
97
+ if (locales.empty()) {
98
+ return "";
99
+ }
100
+ return locales[0].identifier;
101
+ }
32
102
 
33
- auto appLocale = volta::i18n::I18nManager::getInstance().getAppLocale();
34
- icu::Locale loc(appLocale.c_str());
103
+ tbm::NativeJSArray ExpoLocalization::getLocales() {
104
+ auto locales = getEnvModule()->getLocaleConfig()->getResolvedLocales(nullptr);
105
+ tbm::NativeJSArray resultArray(locales.size());
35
106
 
36
- result["languageCode"] = std::string(loc.getLanguage());
37
- result["languageTag"] = appLocale;
107
+ for (std::size_t i = 0; i < locales.size(); i++) {
108
+ tbm::NativeJSObject result;
109
+ const std::string& identifier = locales[i].identifier;
38
110
 
39
- std::unique_ptr<icu::NumberFormat> nf(icu::NumberFormat::createInstance(loc, status));
40
- if (U_SUCCESS(status)) {
41
- result["currencyCode"] = toUTF8String(nf->getCurrency());
42
- } else {
43
- result["currencyCode"] = nullptr;
44
- }
111
+ const icu::Locale loc(identifier.c_str());
112
+ result["languageCode"] = std::string(loc.getLanguage());
113
+ result["languageTag"] = identifier;
45
114
 
46
- status = U_ZERO_ERROR;
47
- icu::DecimalFormatSymbols dfs(loc, status);
48
- if (U_SUCCESS(status)) {
49
- result["currencySymbol"] = toUTF8String(dfs.getSymbol(icu::DecimalFormatSymbols::kCurrencySymbol));
50
- result["decimalSeparator"] = toUTF8String(dfs.getSymbol(icu::DecimalFormatSymbols::kDecimalSeparatorSymbol));
51
- result["digitGroupingSeparator"] =
52
- toUTF8String(dfs.getSymbol(icu::DecimalFormatSymbols::kGroupingSeparatorSymbol));
53
- } else {
54
- result["currencySymbol"] = nullptr;
55
- result["decimalSeparator"] = nullptr;
56
- result["digitGroupingSeparator"] = nullptr;
57
- }
115
+ UErrorCode status = U_ZERO_ERROR;
116
+ std::unique_ptr<icu::NumberFormat> nf(icu::NumberFormat::createInstance(loc, status));
117
+ if (U_SUCCESS(status) != 0) {
118
+ result["currencyCode"] = toUTF8String(nf->getCurrency());
119
+ } else {
120
+ result["currencyCode"] = nullptr;
121
+ }
58
122
 
59
- status = U_ZERO_ERROR;
60
- auto measurementSystem = ulocdata_getMeasurementSystem(loc.getLanguage(), &status);
61
- if (measurementSystem == UMS_SI) {
62
- result["measurementSystem"] = "metric";
63
- } else if (measurementSystem == UMS_US) {
64
- result["measurementSystem"] = "imperial";
65
- } else if (measurementSystem == UMS_UK) {
66
- result["measurementSystem"] = "uk";
67
- } else {
68
- result["measurementSystem"] = nullptr;
69
- }
123
+ status = U_ZERO_ERROR;
124
+ const icu::DecimalFormatSymbols dfs(loc, status);
125
+ if (U_SUCCESS(status) != 0) {
126
+ result["currencySymbol"] = toUTF8String(dfs.getSymbol(icu::DecimalFormatSymbols::kCurrencySymbol));
127
+ result["decimalSeparator"] =
128
+ toUTF8String(dfs.getSymbol(icu::DecimalFormatSymbols::kDecimalSeparatorSymbol));
129
+ result["digitGroupingSeparator"] =
130
+ toUTF8String(dfs.getSymbol(icu::DecimalFormatSymbols::kGroupingSeparatorSymbol));
131
+ } else {
132
+ result["currencySymbol"] = nullptr;
133
+ result["decimalSeparator"] = nullptr;
134
+ result["digitGroupingSeparator"] = nullptr;
135
+ }
136
+
137
+ status = U_ZERO_ERROR;
138
+ auto measurementSystem = ulocdata_getMeasurementSystem(loc.getLanguage(), &status);
139
+ if (measurementSystem == UMS_SI) {
140
+ result["measurementSystem"] = "metric";
141
+ } else if (measurementSystem == UMS_US) {
142
+ result["measurementSystem"] = "imperial";
143
+ } else if (measurementSystem == UMS_UK) {
144
+ result["measurementSystem"] = "uk";
145
+ } else {
146
+ result["measurementSystem"] = nullptr;
147
+ }
70
148
 
71
- result["textDirection"] = loc.isRightToLeft() ? "rtl" : "ltr";
149
+ result["textDirection"] = (loc.isRightToLeft() != 0) ? "rtl" : "ltr";
72
150
 
73
- result["regionCode"] = nullptr;
151
+ result["regionCode"] = nullptr;
74
152
 
75
- return {result};
153
+ resultArray[i] = result;
154
+ }
155
+
156
+ return resultArray;
76
157
  }
77
158
 
78
- volta::react::NativeJSArray ExpoLocalization::getCalendars() {
79
- volta::react::NativeJSObject calendar;
159
+ tbm::NativeJSArray ExpoLocalization::getCalendars() {
160
+ const auto& locales = getEnvModule()->getLocaleConfig()->getResolvedLocales(nullptr);
161
+ tbm::NativeJSArray calendarArray(locales.size());
80
162
 
81
- auto appLocale = volta::i18n::I18nManager::getInstance().getAppLocale();
82
- icu::Locale loc(appLocale.c_str());
163
+ for (std::size_t i = 0; i < locales.size(); i++) {
164
+ tbm::NativeJSObject calendar;
165
+ const std::string& identifier = locales[i].identifier;
83
166
 
84
- std::string timezone = volta::i18n::I18nManager::getInstance().getTimezone();
85
- icu::UnicodeString timezoneUc(timezone.c_str());
86
- std::unique_ptr<icu::TimeZone> tz(icu::TimeZone::createTimeZone(timezoneUc));
167
+ const icu::Locale loc(identifier.c_str());
87
168
 
88
- UErrorCode status = U_ZERO_ERROR;
89
- std::unique_ptr<icu::Calendar> c(icu::Calendar::createInstance(loc, status));
90
- if (U_SUCCESS(status)) {
91
- calendar["calendar"] = std::string(c->getType());
92
- } else {
93
- calendar["calendar"] = nullptr;
94
- }
169
+ UErrorCode status = U_ZERO_ERROR;
170
+ std::unique_ptr<icu::Calendar> c(icu::Calendar::createInstance(loc, status));
171
+ if (U_SUCCESS(status) != 0) {
172
+ calendar["calendar"] = std::string(c->getType());
173
+ } else {
174
+ calendar["calendar"] = nullptr;
175
+ }
95
176
 
96
- status = U_ZERO_ERROR;
97
- int firstWeekday = (int) c->getFirstDayOfWeek(status);
98
- if (U_SUCCESS(status)) {
99
- calendar["firstWeekday"] = firstWeekday;
100
- } else {
101
- calendar["firstWeekday"] = nullptr;
102
- }
177
+ status = U_ZERO_ERROR;
178
+ const int firstWeekday = static_cast<int>(c->getFirstDayOfWeek(status));
179
+ if (U_SUCCESS(status) != 0) {
180
+ calendar["firstWeekday"] = firstWeekday;
181
+ } else {
182
+ calendar["firstWeekday"] = nullptr;
183
+ }
103
184
 
104
- calendar["uses24hourClock"] = nullptr;
105
- status = U_ZERO_ERROR;
106
- std::unique_ptr<icu::DateTimePatternGenerator> dtp(icu::DateTimePatternGenerator::createInstance(loc, status));
107
- if (U_SUCCESS(status)) {
185
+ calendar["uses24hourClock"] = nullptr;
108
186
  status = U_ZERO_ERROR;
109
- auto cycle = dtp->getDefaultHourCycle(status);
110
- if (U_SUCCESS(status)) {
111
- calendar["uses24hourClock"] = (cycle == UDAT_HOUR_CYCLE_23 || cycle == UDAT_HOUR_CYCLE_24);
187
+ std::unique_ptr<icu::DateTimePatternGenerator> dtp(icu::DateTimePatternGenerator::createInstance(loc, status));
188
+ if (U_SUCCESS(status) != 0) {
189
+ status = U_ZERO_ERROR;
190
+ auto cycle = dtp->getDefaultHourCycle(status);
191
+ if (U_SUCCESS(status) != 0) {
192
+ calendar["uses24hourClock"] = (cycle == UDAT_HOUR_CYCLE_23 || cycle == UDAT_HOUR_CYCLE_24);
193
+ }
194
+ }
195
+
196
+ apmf::Ptr<devConf::IDeviceConfig> component = getDeviceConfig();
197
+ try {
198
+ calendar["timezone"] = component->get(g_timeZoneConfig);
199
+ } catch (const apmf::BaseError& e) {
200
+ TMERROR(fmt::format("Error while processing time zone data: {}", e.what()));
201
+ calendar["timezone"] = nullptr;
112
202
  }
113
- }
114
203
 
115
- if (timezone.length() == 0) {
116
- calendar["timezone"] = nullptr;
117
- } else {
118
- calendar["timezone"] = timezone;
204
+ calendarArray[i] = calendar;
119
205
  }
120
206
 
121
- return {calendar};
207
+ return calendarArray;
122
208
  }
123
209
 
124
- void ExpoLocalization::aggregateMethods(
125
- volta::react::MethodAggregator<volta::react::KeplerTurboModule>& methodAggregator) const noexcept {
210
+ void ExpoLocalization::aggregateMethods(tbm::MethodAggregator<KeplerTurboModule>& methodAggregator) const noexcept {
211
+ methodAggregator.addMethod("getLocale", 0, &ExpoLocalization::getLocale);
126
212
  methodAggregator.addMethod("getLocales", 0, &ExpoLocalization::getLocales);
127
213
  methodAggregator.addMethod("getCalendars", 0, &ExpoLocalization::getCalendars);
128
214
  }
@@ -8,15 +8,24 @@
8
8
 
9
9
  #pragma once
10
10
 
11
- #include <KeplerScript/modules/KeplerTurboModule.h>
11
+ #include <Kepler/turbomodule/KeplerTurboModule.h>
12
+ #include <apmf/iface/com/amazon/kepler/experimental_mr33/messaging/IMessageChannel.h>
13
+ #include <apmf/ptr.h>
12
14
 
13
- class KEPLERSCRIPT_EXPORT ExpoLocalization : public volta::react::KeplerTurboModule {
15
+ #include "expo-export.h"
16
+
17
+ namespace tbm = com::amazon::kepler::turbomodule;
18
+
19
+ class EXPO_EXPORT ExpoLocalization : public tbm::KeplerTurboModule {
14
20
  public:
15
21
  ExpoLocalization();
16
- volta::react::NativeJSArray getLocales();
17
- volta::react::NativeJSArray getCalendars();
22
+ std::string getLocale();
23
+ tbm::JSArray getLocales();
24
+ tbm::JSArray getCalendars();
25
+
26
+ void aggregateMethods(tbm::MethodAggregator<tbm::KeplerTurboModule>& methodAggregator) const noexcept override;
18
27
 
19
- protected:
20
- void aggregateMethods(
21
- volta::react::MethodAggregator<volta::react::KeplerTurboModule>& methodAggregator) const noexcept override;
28
+ private:
29
+ apmf::detail::Ptr<apmf::iface::com::amazon::kepler::experimental_mr33::messaging::IMessageChannel>
30
+ m_timezoneChannel;
22
31
  };
@@ -6,18 +6,15 @@
6
6
  * Use is subject to license terms.
7
7
  */
8
8
 
9
- #include <KeplerScript/logger/KPLog.h>
10
- #include <KeplerScript/utils/autolink/KeplerAutoLinkInfo.h>
11
- #include <keplerui-072/keplerscript-export.h>
9
+ #include <Kepler/turbomodule/KeplerTurboModuleRegistration.h>
10
+ #include <Kepler/turbomodule/TMLog.h>
12
11
 
13
12
  #include "ExpoLocalization.h"
14
- #include "RegisterModule.h"
15
13
 
16
14
  extern "C" {
17
- KEPLERSCRIPT_EXPORT void keplerAutoLinkInitV1(const kepler::autolink::v1::KeplerAutoLinkInfo* autoLinkInfo) noexcept {
18
- volta::react::KPLog.debug("keplerAutoLinkInitV1 for ExpoLocalization");
19
-
20
- REGISTER_MODULE(autoLinkInfo, ExpoLocalization, "ExpoLocalization");
15
+ __attribute__((visibility("default"))) void autoLinkKeplerTurboModulesV1() noexcept {
16
+ TMDEBUG("autoLinkKeplerTurboModulesV1 for expo-localization");
17
+ KEPLER_REGISTER_TURBO_MODULE_WITH_NAME("ExpoLocalization", ExpoLocalization);
21
18
  }
22
19
  }
23
20
 
@@ -0,0 +1,7 @@
1
+ {
2
+ "versions": {
3
+ "2.0.0": "/com.amazon.kepler.expo_localization_2@IExpoLocalization_0",
4
+ "2.0.9000000000": "/com.amazon.kepler.expo_localization_2@IExpoLocalization_0",
5
+ "2.0.9000000001": "/com.amazon.kepler.expo_localization_2@IExpoLocalization_0"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@amazon-devices/expo-localization", "version": "2.0.9000000000+14.6.0", "description": "Provides an interface for native user localization information.", "main": "build/Localization.js", "types": "build/Localization.d.ts", "sideEffects": false, "scripts": {"build": "expo-module build", "clean": "expo-module clean", "lint": "expo-module lint", "test": "expo-module test", "prepublishOnly": "expo-module prepublishOnly", "expo-module": "expo-module"}, "kepler": {"temporary-alias-for-package": {"name": "expo-localization", "version": "14.6.0"}}, "keywords": ["react-native", "expo", "localization", "locales", "l10n"], "repository": {"type": "git", "url": "https://github.com/expo/expo.git", "directory": "packages/expo-localization"}, "bugs": {"url": "https://github.com/expo/expo/issues"}, "contributors": ["Evan Bacon <bacon@expo.io> (https://github.com/evanbacon)"], "author": "650 Industries, Inc.", "license": "See license in LICENSE", "homepage": "https://docs.expo.dev/versions/latest/sdk/localization/", "jest": {"preset": "expo-module-scripts"}, "dependencies": {"rtl-detect": "^1.0.2"}, "devDependencies": {"expo-module-scripts": "^3.0.0", "i18n-js": "^3.1.0", "@types/minimatch": "^3.0.5"}, "peerDependencies": {"expo": "*"}}
1
+ {"name": "@amazon-devices/expo-localization", "version": "2.0.9000000001+14.6.0", "description": "Provides an interface for native user localization information.", "main": "build/Localization.js", "types": "build/Localization.d.ts", "sideEffects": false, "scripts": {"build": "expo-module build", "clean": "expo-module clean", "lint": "expo-module lint", "test": "expo-module test", "prepublishOnly": "expo-module prepublishOnly", "expo-module": "expo-module"}, "kepler": {"temporary-alias-for-package": {"name": "expo-localization", "version": "14.6.0"}}, "keywords": ["react-native", "expo", "localization", "locales", "l10n"], "repository": {"type": "git", "url": "https://github.com/expo/expo.git", "directory": "packages/expo-localization"}, "bugs": {"url": "https://github.com/expo/expo/issues"}, "contributors": ["Evan Bacon <bacon@expo.io> (https://github.com/evanbacon)"], "author": "650 Industries, Inc.", "license": "See license in LICENSE", "homepage": "https://docs.expo.dev/versions/latest/sdk/localization/", "jest": {"preset": "expo-module-scripts"}, "dependencies": {"rtl-detect": "^1.0.2"}, "devDependencies": {"expo-module-scripts": "^3.0.0", "i18n-js": "^3.1.0", "@types/minimatch": "^3.0.5"}, "peerDependencies": {"expo": "^50.0.0-alpha.1"}}
@@ -12,6 +12,7 @@ module.exports = {
12
12
  autolink: {
13
13
  ExpoLocalizationLib: {
14
14
  provider: 'system',
15
+ libraryName: 'libexpo-localization-2.so.2',
15
16
  turbomodules: ['ExpoLocalization'],
16
17
  },
17
18
  },
@@ -6,35 +6,43 @@
6
6
  * Use is subject to license terms.
7
7
  */
8
8
 
9
- import {KeplerTurboModule, TurboModuleRegistry} from '@amazon-devices/keplerscript-turbomodule-api';
10
- import {Subscription} from 'expo-modules-core';
9
+ import { KeplerTurboModule, TurboModuleRegistry } from '@amazon-devices/keplerscript-turbomodule-api';
10
+ import type { Subscription } from 'expo-modules-core';
11
+ import { DeviceEventEmitter } from 'react-native';
11
12
 
12
- import {Calendar, Locale} from './Localization.types';
13
+ import { Calendar, Locale } from './Localization.types';
13
14
 
14
15
  interface Spec extends KeplerTurboModule {
15
16
  getLocales(): Locale[];
16
17
  getCalendars(): Calendar[];
18
+ getLocale(): string;
17
19
  }
18
20
 
19
- const nativeModule = TurboModuleRegistry.getEnforcing<Spec>('ExpoLocalization') as Spec;
20
- const i18nManager = TurboModuleRegistry.getEnforcing('I18nManager') as any;
21
+ const nativeModule = TurboModuleRegistry.getEnforcing<Spec>('ExpoLocalization');
21
22
 
22
- export function addLocaleListener(listener: (event) => void) {
23
- i18nManager.addListener('Locale', listener);
23
+ export function addLocaleListener(listener: () => void): Subscription {
24
+ return DeviceEventEmitter.addListener('onLocaleSettingsChanged', listener);
24
25
  }
25
26
 
26
- export function addCalendarListener(listener: (event) => void) {
27
- i18nManager.addListener('Timezone', listener);
27
+ export function addCalendarListener(listener: () => void): Subscription {
28
+ const localeSubscription = DeviceEventEmitter.addListener('onLocaleSettingsChanged', listener);
29
+ const timezoneSubscription = DeviceEventEmitter.addListener('onCalendarSettingsChanged', listener);
30
+ return {
31
+ remove: () => {
32
+ localeSubscription.remove();
33
+ timezoneSubscription.remove();
34
+ },
35
+ } as Subscription;
28
36
  }
29
37
 
30
38
  export function removeSubscription(subscription: Subscription) {
31
- i18nManager.removeListeners();
39
+ subscription.remove();
32
40
  }
33
41
 
34
42
  const module = {
35
43
  getLocales: nativeModule.getLocales,
36
44
  getCalendars: nativeModule.getCalendars,
37
- locale: i18nManager.getAppLocale(),
45
+ locale: nativeModule.getLocale(),
38
46
  };
39
47
 
40
48
  export default module;
@@ -1 +0,0 @@
1
- {"root":["./src/withExpoLocalization.ts"],"version":"5.9.3"}